-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix CatchWithUnthrownExceptionRule for new $expr()
- Loading branch information
1 parent
566b44b
commit 8463afd
Showing
3 changed files
with
150 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,124 @@ | ||
<?php | ||
|
||
namespace Bug4806; | ||
|
||
class NeverThrows | ||
{ | ||
/** | ||
* @throws void | ||
*/ | ||
final public function __construct() | ||
{ | ||
} | ||
} | ||
|
||
class HasNoConstructor | ||
{ | ||
|
||
} | ||
|
||
class MayThrowArgumentCountError | ||
{ | ||
/** | ||
* @throws \ArgumentCountError | ||
*/ | ||
public function __construct() | ||
{ | ||
throw new \ArgumentCountError(); | ||
} | ||
} | ||
|
||
class ImplicitThrow | ||
{ | ||
|
||
public function __construct() | ||
{ | ||
|
||
} | ||
|
||
} | ||
|
||
class Foo | ||
{ | ||
|
||
/** | ||
* @param class-string $class | ||
*/ | ||
function createNotSpecified(string $class): object | ||
{ | ||
try { | ||
$object = new $class(); | ||
} catch (\ArgumentCountError $error) { | ||
|
||
} | ||
|
||
return $object; | ||
} | ||
|
||
/** | ||
* @param class-string<NeverThrows> $class | ||
*/ | ||
function createNeverThrows(string $class): object | ||
{ | ||
try { | ||
$object = new $class(); | ||
} catch (\ArgumentCountError $throwable) { | ||
|
||
} | ||
|
||
return $object; | ||
} | ||
|
||
/** | ||
* @param class-string<MayThrowArgumentCountError> $class | ||
*/ | ||
function createMayThrowArgumentCountError(string $class): object | ||
{ | ||
try { | ||
$object = new $class(); | ||
} catch (\ArgumentCountError $error) { | ||
|
||
} | ||
|
||
return $object; | ||
} | ||
|
||
/** | ||
* @param class-string<MayThrowArgumentCountError> $class | ||
*/ | ||
function createMayThrowArgumentCountErrorB(string $class): object | ||
{ | ||
try { | ||
$object = new $class(); | ||
} catch (\Throwable $throwable) { | ||
|
||
} | ||
|
||
return $object; | ||
} | ||
|
||
/** | ||
* @param class-string<ImplicitThrow> $class | ||
*/ | ||
function implicitThrow(string $class): void | ||
{ | ||
try { | ||
$object = new $class(); | ||
} catch (\Throwable $throwable) { | ||
|
||
} | ||
} | ||
|
||
/** | ||
* @param class-string<HasNoConstructor> $class | ||
*/ | ||
function hasNoConstructor(string $class): void | ||
{ | ||
try { | ||
$object = new $class(); | ||
} catch (\Throwable $throwable) { | ||
|
||
} | ||
} | ||
|
||
} |