File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
tests/PHPStan/Rules/Exceptions Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -667,6 +667,20 @@ public function testBug9146(): void
667667 ]);
668668 }
669669
670+ public function testPr5105 (): void
671+ {
672+ $ this ->analyse ([__DIR__ . '/data/pr-5105.php ' ], [
673+ [
674+ 'Dead catch - RuntimeException is never thrown in the try block. ' ,
675+ 15 ,
676+ ],
677+ [
678+ 'Dead catch - Error is never thrown in the try block. ' ,
679+ 28 ,
680+ ],
681+ ]);
682+ }
683+
670684 public function testBug9146NonStrict (): void
671685 {
672686 $ this ->analyse ([__DIR__ . '/data/bug-9146-non-strict.php ' ], [
Original file line number Diff line number Diff line change 1+ <?php // lint >= 8.1
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