Skip to content

Commit 07aa8ce

Browse files
authored
Fix and improve handling of wp_die's 3rd parameter (#123)
1 parent f60ff2f commit 07aa8ce

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

visitor.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111
use phpDocumentor\Reflection\Types\Never_;
1212
use phpDocumentor\Reflection\Types\Void_;
1313
use PhpParser\Comment\Doc;
14+
use PhpParser\ConstExprEvaluationException;
15+
use PhpParser\ConstExprEvaluator;
1416
use PhpParser\Node;
1517
use PhpParser\NodeFinder;
1618
use PhpParser\Node\Identifier;
1719
use PhpParser\Node\Name;
18-
use PhpParser\Node\Expr\Array_;
19-
use PhpParser\Node\Expr\ArrayItem;
2020
use PhpParser\Node\Expr\Exit_;
2121
use PhpParser\Node\Expr\FuncCall;
22-
use PhpParser\Node\Scalar\String_;
2322
use PhpParser\Node\Stmt\Class_;
2423
use PhpParser\Node\Stmt\ClassMethod;
2524
use PhpParser\Node\Stmt\Expression;
@@ -1117,23 +1116,23 @@ static function (Node $node): bool {
11171116
return 'never';
11181117
}
11191118
// If wp_die is called with 3rd parameter, we need additional checks.
1120-
$argValue = $args[2]->value;
1121-
if (!($argValue instanceof Array_)) {
1119+
try {
1120+
$arg = (new ConstExprEvaluator())->evaluateSilently($args[2]->value);
1121+
} catch (ConstExprEvaluationException $e) {
1122+
// If we don't know the value of the 3rd parameter, we can't be sure.
11221123
continue;
11231124
}
1124-
foreach ($argValue->items as $item) {
1125-
if (!($item instanceof ArrayItem && $item->key instanceof String_ && $item->key->value === 'exit')) {
1126-
continue;
1127-
}
1128-
if (
1129-
($item->value instanceof Node\Expr\ConstFetch && strtolower($item->value->name->toString()) === 'true')
1130-
|| ($item->value instanceof Node\Scalar\LNumber && $item->value->value === 1)
1131-
|| ($item->value instanceof Node\Scalar\String_ && $item->value->value !== '' && $item->value->value !== '0')
1132-
) {
1125+
1126+
if (is_int($arg)) {
1127+
return 'never';
1128+
}
1129+
if (is_array($arg)) {
1130+
if (!isset($arg['exit']) || (bool)$arg['exit'] === true) {
11331131
return 'never';
11341132
}
1135-
return '';
11361133
}
1134+
1135+
continue;
11371136
}
11381137
return '';
11391138
}

wordpress-stubs.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120894,6 +120894,7 @@ function ms_load_current_site_and_network($domain, $path, $subdomain = \false)
120894120894
*
120895120895
* @param string $domain The requested domain for the error to reference.
120896120896
* @param string $path The requested path for the error to reference.
120897+
* @phpstan-return never
120897120898
*/
120898120899
function ms_not_installed($domain, $path)
120899120900
{

0 commit comments

Comments
 (0)