Skip to content

Commit

Permalink
fix: Do not prefix excluded functions used in call_user_func_array() (
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed May 5, 2024
1 parent 4f8d70b commit c1e866e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 2 additions & 0 deletions specs/string-literal/func-arg-call-user-func.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'FQCN string argument' => <<<'PHP'
<?php
call_user_func_array('sprintf', []);
call_user_func_array('sodiumCompatAutoloader', []);
call_user_func_array('Sodium\compatAutoloader', []);
call_user_func_array(['Swift', 'autoload'], []);
Expand All @@ -38,6 +39,7 @@
namespace Humbug;
\call_user_func_array('sprintf', []);
\call_user_func_array('Humbug\sodiumCompatAutoloader', []);
\call_user_func_array('Humbug\Sodium\compatAutoloader', []);
\call_user_func_array(['Humbug\Swift', 'autoload'], []);
Expand Down
19 changes: 10 additions & 9 deletions src/PhpParser/NodeVisitor/StringScalarPrefixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,19 +249,20 @@ private function prefixFunctionStringArg(String_ $string, FuncCall $functionNode

$isConstantNode = self::isConstantNode($string);

if (!$isConstantNode) {
if ('define' === $functionName
&& $this->belongsToTheGlobalNamespace($string)
) {
return $string;
}

return $this->enrichedReflector->isClassExcluded($normalizedValue)
if ($isConstantNode) {
return $this->enrichedReflector->isExposedConstant($normalizedValue)
? $string
: $this->createPrefixedString($string);
}

return $this->enrichedReflector->isExposedConstant($normalizedValue)
if ('define' === $functionName
&& $this->belongsToTheGlobalNamespace($string)
) {
return $string;
}

return $this->enrichedReflector->isClassExcluded($normalizedValue)
|| $this->enrichedReflector->isFunctionExcluded($normalizedValue)
? $string
: $this->createPrefixedString($string);
}
Expand Down

0 comments on commit c1e866e

Please sign in to comment.