Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fix CatchWithUnthrownExceptionRule for $expr::foo()
- Loading branch information
1 parent
8463afd
commit 8c7cf85
Showing
3 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
|
||
namespace Bug4805; | ||
|
||
final class Foo | ||
{ | ||
/** | ||
* @throws \OutOfBoundsException | ||
*/ | ||
public static function canThrow(bool $throw): self | ||
{ | ||
if($throw){ | ||
throw new \OutOfBoundsException('Ooops'); | ||
} | ||
return new self(); | ||
} | ||
|
||
/** | ||
* @throws void | ||
*/ | ||
public static function cannotThrow(bool $throw): void | ||
{ | ||
|
||
} | ||
} | ||
|
||
final class Bar | ||
{ | ||
public static function doFoo(Foo $foo, bool $flag): bool | ||
{ | ||
try{ | ||
$foo::canThrow($flag); | ||
return true; | ||
}catch(\OutOfBoundsException $e){ | ||
return false; | ||
} | ||
} | ||
|
||
public static function doFoo2(Foo $foo, bool $flag): bool | ||
{ | ||
try{ | ||
$foo::cannotThrow($flag); | ||
return true; | ||
}catch(\OutOfBoundsException $e){ | ||
return false; | ||
} | ||
} | ||
|
||
/** @param class-string<Foo> $foo */ | ||
public static function doBar(string $foo, bool $flag): bool | ||
{ | ||
try{ | ||
$foo::canThrow($flag); | ||
return true; | ||
} catch(\OutOfBoundsException $e){ | ||
return false; | ||
} | ||
} | ||
|
||
/** @param class-string<Foo> $foo */ | ||
public static function doBar2(string $foo, bool $flag): bool | ||
{ | ||
try{ | ||
$foo::cannotThrow($flag); | ||
return true; | ||
} catch(\OutOfBoundsException $e){ | ||
return false; | ||
} | ||
} | ||
|
||
/** @param class-string $foo */ | ||
public static function doBaz(string $foo, bool $flag): bool | ||
{ | ||
try{ | ||
$foo::canThrow($flag); | ||
return true; | ||
} catch(\OutOfBoundsException $e){ | ||
return false; | ||
} | ||
} | ||
|
||
/** @param class-string $foo */ | ||
public static function doBaz2(string $foo, bool $flag): bool | ||
{ | ||
try{ | ||
$foo::cannotThrow($flag); | ||
return true; | ||
} catch(\OutOfBoundsException $e){ | ||
return false; | ||
} | ||
} | ||
|
||
public static function doLorem(string $foo, bool $flag): bool | ||
{ | ||
try{ | ||
$foo::canThrow($flag); | ||
return true; | ||
} catch(\OutOfBoundsException $e){ | ||
return false; | ||
} | ||
} | ||
|
||
public static function doLorem2(string $foo, bool $flag): bool | ||
{ | ||
try{ | ||
$foo::cannotThrow($flag); | ||
return true; | ||
} catch(\OutOfBoundsException $e){ | ||
return false; | ||
} | ||
} | ||
} |