Skip to content

Commit 7b93cb2

Browse files
committed
Fix unclear types & PHPStan issues
1 parent 09c4ed0 commit 7b93cb2

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
},
4040
"scripts": {
4141
"phpstan": "vendor/bin/phpstan analyse",
42+
"phpstan_full": "vendor/bin/phpstan clear-result-cache && vendor/bin/phpstan analyse",
4243
"phpstan_base": "vendor/bin/phpstan analyse --configuration phpstan_base.neon --error-format baselineNeon > phpstan-baseline.neon",
43-
"phpstan_clear": "vendor/bin/phpstan clear-result-cache",
4444
"psalm": "vendor/bin/psalm --show-info=false",
45-
"psalm_full": "vendor/bin/psalm --show-info=false --clear-cache",
45+
"psalm_full": "vendor/bin/psalm --clear-cache && vendor/bin/psalm --show-info=false",
4646
"psalm_base": "vendor/bin/psalm --set-baseline=psalm-baseline.xml",
4747
"phpunit": "vendor/bin/phpunit --colors=always",
4848
"phpunit_clover": "vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml",

src/Debug.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,18 @@ public static function createException(
4646

4747
// Replace backtrace instance if we find a valid class insance
4848
foreach ($backtraceClasses as $backtraceClass) {
49+
$classImplements = \class_implements($backtrace['class']);
50+
$classParents = \class_parents($backtrace['class']);
51+
52+
if ($classImplements === false || $classParents === false) {
53+
continue;
54+
}
55+
4956
// Check if the class or interface we are looking for is implemented or used
5057
// by the current backtrace class
5158
if (
52-
\in_array($backtraceClass, \class_implements($backtrace['class']), true) ||
53-
\in_array($backtraceClass, \class_parents($backtrace['class']), true) ||
59+
\in_array($backtraceClass, $classImplements, true) ||
60+
\in_array($backtraceClass, $classParents, true) ||
5461
$backtraceClass === $backtrace['class']
5562
) {
5663
$lastInstance = $backtrace;
@@ -70,13 +77,24 @@ public static function createException(
7077
$parts = \explode('\\', $assignedBacktraceClass);
7178
$shownClass = \array_pop($parts);
7279

80+
$classImplements = \class_implements($exceptionClass);
81+
$classParents = \class_parents($exceptionClass);
82+
83+
if ($classImplements === false) {
84+
$classImplements = [];
85+
}
86+
87+
if ($classParents === false) {
88+
$classParents = [];
89+
}
90+
7391
// Make sure the provided exception class inherits from Throwable, otherwise replace it with Exception
74-
if (!\in_array(\Throwable::class, \class_implements($exceptionClass), true)) {
92+
if (!\in_array(\Throwable::class, $classImplements, true)) {
7593
$exceptionClass = \Exception::class;
7694
}
7795

7896
// If we have no OriginException child class, we assume the default Exception class constructor is used
79-
if (!\in_array(OriginException::class, \class_parents($exceptionClass), true) && $exceptionClass !== OriginException::class) {
97+
if (!\in_array(OriginException::class, $classParents, true) && $exceptionClass !== OriginException::class) {
8098
/**
8199
* @var \Throwable $exception At this point we know that $exceptionClass inherits from \Throwable for sure
82100
*/

tests/DebugTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testCreateException()
2626
$this->assertEquals(__FILE__, $e->getFile());
2727
$this->assertEquals(__LINE__ - 8, $e->getLine());
2828
$this->assertEquals($debugClassPath, $e->getExceptionFile());
29-
$this->assertEquals(95, $e->getExceptionLine());
29+
$this->assertEquals(113, $e->getExceptionLine());
3030
$this->assertEquals('SomeClass->someFunction()', $e->getOriginCall());
3131
}
3232
}

0 commit comments

Comments
 (0)