for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
/**
* @license http://opensource.org/licenses/mit-license.php MIT
* @link https://github.com/nicoSWD
* @author Nicolas Oelgart <[email protected]>
*/
namespace nicoSWD\Rules\AST\Nodes;
use nicoSWD\Rules\Core\CallableFunction;
use nicoSWD\Rules\Exceptions\ParserException;
use nicoSWD\Rules\Tokens\BaseToken;
final class NodeFunction extends BaseNode
{
public function getNode(): BaseToken
$current = $this->ast->getStack()->current();
$function = $this->resolveFunctionName($current);
$class = $this->resolveClassName($function);
if (!class_exists($class)) {
return $this->ast->parser->getFunction($function)->call($this, ...$this->getArguments());
}
/** @var CallableFunction $instance */
$instance = new $class($current);
if ($instance->getName() !== $function) {
throw new ParserException(sprintf(
'%s is not defined',
$function
));
return $instance->call(...$this->getArguments());
$this->getArguments()
object<nicoSWD\Rules\AST\TokenCollection>
object<nicoSWD\Rules\Tokens\BaseToken>|null
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example:
function acceptsInteger($int) { } $x = '123'; // string "123" // Instead of acceptsInteger($x); // we recommend to use acceptsInteger((integer) $x);
private function resolveClassName(string $class): string
return '\nicoSWD\Rules\Core\Functions\\' . ucfirst($class);
private function resolveFunctionName(BaseToken $token): string
return rtrim($token->getValue(), " \r\n(");
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: