File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed
tests/PHPStan/Rules/Exceptions Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -667,6 +667,21 @@ public function testBug9146(): void
667667 ]);
668668 }
669669
670+ #[RequiresPhp('>= 8.3 ' )]
671+ public function testPr5105 (): void
672+ {
673+ $ this ->analyse ([__DIR__ . '/data/pr-5105.php ' ], [
674+ [
675+ 'Dead catch - RuntimeException is never thrown in the try block. ' ,
676+ 15 ,
677+ ],
678+ [
679+ 'Dead catch - Error is never thrown in the try block. ' ,
680+ 28 ,
681+ ],
682+ ]);
683+ }
684+
670685 public function testBug9146NonStrict (): void
671686 {
672687 $ this ->analyse ([__DIR__ . '/data/bug-9146-non-strict.php ' ], [
Original file line number Diff line number Diff line change 1+ <?php // lint >= 8.3
2+
3+ declare (strict_types = 1 );
4+
5+ namespace Pr5105 ;
6+
7+ enum ReactionType: string
8+ {
9+ case EMOJI_HEART = '❤️ ' ;
10+
11+ public static function tryFromName1 (string $ name ): ?self
12+ {
13+ try {
14+ return ReactionType::{$ name };
15+ } catch (\RuntimeException ) {
16+ return null ;
17+ }
18+ }
19+
20+ public static function tryFromName2 (string $ name ): ?self
21+ {
22+ if ($ name !== 'EMOJI_HEART ' ) {
23+ return null ;
24+ }
25+
26+ try {
27+ return ReactionType::{$ name };
28+ } catch (\Error ) {
29+ return null ;
30+ }
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments