aboutsummaryrefslogtreecommitdiff
path: root/src/NXP/Classes/CustomFunction.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/NXP/Classes/CustomFunction.php')
-rw-r--r--src/NXP/Classes/CustomFunction.php24
1 files changed, 9 insertions, 15 deletions
diff --git a/src/NXP/Classes/CustomFunction.php b/src/NXP/Classes/CustomFunction.php
index 225495f..bc0f4e7 100644
--- a/src/NXP/Classes/CustomFunction.php
+++ b/src/NXP/Classes/CustomFunction.php
@@ -8,25 +8,17 @@ use ReflectionFunction;
class CustomFunction
{
- /**
- * @var string
- */
- public $name;
+ public string $name = '';
/**
* @var callable $function
*/
public $function;
- /**
- * @var int
- */
- public $places;
+ public int $places = 0;
/**
* CustomFunction constructor.
- * @param string $name
- * @param callable $function
* @param int $places
* @throws ReflectionException
* @throws IncorrectNumberOfFunctionParametersException
@@ -35,7 +27,8 @@ class CustomFunction
{
$this->name = $name;
$this->function = $function;
- if ($places === null) {
+
+ if (null === $places) {
$reflection = new ReflectionFunction($function);
$this->places = $reflection->getNumberOfParameters();
} else {
@@ -48,17 +41,18 @@ class CustomFunction
*
* @throws IncorrectNumberOfFunctionParametersException
*/
- public function execute(array &$stack): Token
+ public function execute(array &$stack) : Token
{
- if (count($stack) < $this->places) {
+ if (\count($stack) < $this->places) {
throw new IncorrectNumberOfFunctionParametersException($this->name);
}
$args = [];
+
for ($i = 0; $i < $this->places; $i++) {
- array_unshift($args, array_pop($stack)->value);
+ \array_unshift($args, \array_pop($stack)->value);
}
- $result = call_user_func_array($this->function, $args);
+ $result = \call_user_func_array($this->function, $args);
return new Token(Token::Literal, $result);
}