fix few Evaluators code

This commit is contained in:
odain
2025-09-04 22:41:14 +02:00
parent 86fe9d6a2b
commit af790269f0
10 changed files with 102 additions and 122 deletions

View File

@@ -5,9 +5,17 @@ namespace Combodo\iTop\PhpParser\Evaluation;
use ModuleFileReaderException;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use ReflectionFunction;
class FuncCallEvaluator extends AbstractExprEvaluator {
public const WHITELIST=[
"function_exists",
"class_exists",
"method_exists"
];
public function GetHandledExpressionType(): ?string {
return FuncCall::class;
}
@@ -15,9 +23,12 @@ class FuncCallEvaluator extends AbstractExprEvaluator {
public function Evaluate(Expr $oExpr): mixed {
/** @var FuncCall $oExpr */
$sFunction = $oExpr->name->name;
$aWhiteList = ["function_exists", "class_exists", "method_exists"];
if (! in_array($sFunction, $aWhiteList)){
if ($oExpr->name instanceof Name){
$sFunction = $oExpr->name->name;
} else {
$sFunction = PhpExpressionEvaluator::GetInstance()->EvaluateExpression($oExpr->name);
}
if (! in_array($sFunction, self::WHITELIST)){
throw new ModuleFileReaderException("FuncCall $sFunction not supported");
}