| @@ -113,7 +113,7 @@ | ||
| 113 | 113 | )); | 
| 114 | 114 | } | 
| 115 | 115 | $stack[] = new Token(Token::LITERAL, $value, $variable); | 
| 116 | -            } elseif (Token::FUNCTION === $token->getType()) { | |
| 116 | +            } elseif (Token::function === $token->getType()) { | |
| 117 | 117 |                  if (! array_key_exists($token->getValue(), $this->functions)) { | 
| 118 | 118 | throw new UnknownFunctionException(sprintf( | 
| 119 | 119 | 'Unknown function [%s]', | 
| @@ -100,7 +100,7 @@ discard block | ||
| 100 | 100 | } | 
| 101 | 101 | $stack[] = new Token(Token::LITERAL, $value, $variable); | 
| 102 | 102 |              } elseif (Token::FUNCTION === $token->getType()) { | 
| 103 | -                if (! array_key_exists($token->getValue(), $this->functions)) { | |
| 103 | +                if (!array_key_exists($token->getValue(), $this->functions)) { | |
| 104 | 104 | throw new UnknownFunctionException(sprintf( | 
| 105 | 105 | 'Unknown function [%s]', | 
| 106 | 106 | $token->getValue() | 
| @@ -111,7 +111,7 @@ discard block | ||
| 111 | 111 | $token->getParamCount() | 
| 112 | 112 | ); | 
| 113 | 113 |              } elseif (Token::OPERATOR === $token->getType()) { | 
| 114 | -                if (! array_key_exists($token->getValue(), $this->operators)) { | |
| 114 | +                if (!array_key_exists($token->getValue(), $this->operators)) { | |
| 115 | 115 | throw new UnknownOperatorException(sprintf( | 
| 116 | 116 | 'Unknown operator [%s]', | 
| 117 | 117 | $token->getValue() | 
| @@ -57,15 +57,13 @@ | ||
| 57 | 57 | * @class Calculator | 
| 58 | 58 | * @package Platine\Expression | 
| 59 | 59 | */ | 
| 60 | -class Calculator | |
| 61 | -{ | |
| 60 | +class Calculator { | |
| 62 | 61 | /** | 
| 63 | 62 | * Create new instance | 
| 64 | 63 | * @param array<string, CustomFunction> $functions | 
| 65 | 64 | * @param array<string, Operator> $operators | 
| 66 | 65 | */ | 
| 67 | - public function __construct(protected array $functions, protected array $operators) | |
| 68 | -    { | |
| 66 | +    public function __construct(protected array $functions, protected array $operators) { | |
| 69 | 67 | } | 
| 70 | 68 | |
| 71 | 69 | /** | 
| @@ -61,7 +61,7 @@ | ||
| 61 | 61 | public const OPERATOR = 'operator'; | 
| 62 | 62 | public const LEFT_PARENTHESIS = 'LP'; | 
| 63 | 63 | public const RIGHT_PARENTHESIS = 'RP'; | 
| 64 | - public const FUNCTION = 'function'; | |
| 64 | + public const function = 'function'; | |
| 65 | 65 | public const PARAM_SEPARATOR = 'PS'; | 
| 66 | 66 | public const STRING = 'string'; | 
| 67 | 67 | public const SPACE = 'space'; | 
| @@ -51,8 +51,7 @@ | ||
| 51 | 51 | * @class Token | 
| 52 | 52 | * @package Platine\Expression | 
| 53 | 53 | */ | 
| 54 | -class Token | |
| 55 | -{ | |
| 54 | +class Token { | |
| 56 | 55 | /** | 
| 57 | 56 | * Constants | 
| 58 | 57 | */ | 
| @@ -324,7 +324,7 @@ | ||
| 324 | 324 | */ | 
| 325 | 325 | public function buildReversePolishNotation(): array | 
| 326 | 326 |      { | 
| 327 | - $tokens = []; | |
| 327 | + $tokens = []; | |
| 328 | 328 | /** @var SplStack<Token> $stack */ | 
| 329 | 329 | $stack = new SplStack(); | 
| 330 | 330 | |
| @@ -56,8 +56,7 @@ discard block | ||
| 56 | 56 | * @class Tokenizer | 
| 57 | 57 | * @package Platine\Expression | 
| 58 | 58 | */ | 
| 59 | -class Tokenizer | |
| 60 | -{ | |
| 59 | +class Tokenizer { | |
| 61 | 60 | /** | 
| 62 | 61 | * List of token | 
| 63 | 62 | * @var array<Token> | 
| @@ -111,8 +110,7 @@ discard block | ||
| 111 | 110 | * @param string $input | 
| 112 | 111 | * @param array<string, Operator> $operators | 
| 113 | 112 | */ | 
| 114 | - public function __construct(string $input, array $operators) | |
| 115 | -    { | |
| 113 | +    public function __construct(string $input, array $operators) { | |
| 116 | 114 | $this->input = $input; | 
| 117 | 115 | $this->operators = $operators; | 
| 118 | 116 | } | 
| @@ -191,7 +191,7 @@ discard block | ||
| 191 | 191 | continue 2; | 
| 192 | 192 | |
| 193 | 193 | case $ch === '[': | 
| 194 | - $this->tokens[] = new Token(Token::FUNCTION, 'array'); | |
| 194 | + $this->tokens[] = new Token(Token::function, 'array'); | |
| 195 | 195 | $this->allowNegative = true; | 
| 196 | 196 | $this->tokens[] = new Token(Token::LEFT_PARENTHESIS, ''); | 
| 197 | 197 | |
| @@ -250,7 +250,7 @@ discard block | ||
| 250 | 250 | |
| 251 | 251 | case $this->isLeftParenthesis($ch): | 
| 252 | 252 |                      if ($this->stringBuffer != '') { | 
| 253 | - $this->tokens[] = new Token(Token::FUNCTION, $this->stringBuffer); | |
| 253 | + $this->tokens[] = new Token(Token::function, $this->stringBuffer); | |
| 254 | 254 | $this->stringBuffer = ''; | 
| 255 | 255 |                      } elseif (strlen($this->numberBuffer) > 0) { | 
| 256 | 256 | $this->emptyNumberBufferAsLiteral(); | 
| @@ -344,7 +344,7 @@ discard block | ||
| 344 | 344 | |
| 345 | 345 | break; | 
| 346 | 346 | |
| 347 | - case Token::FUNCTION: | |
| 347 | + case Token::function: | |
| 348 | 348 |                      if ($paramCounter->count() > 0 && $paramCounter->top() === 0) { | 
| 349 | 349 | $paramCounter->push($paramCounter->pop() + 1); | 
| 350 | 350 | } | 
| @@ -407,7 +407,7 @@ discard block | ||
| 407 | 407 |                              throw new IncorrectBracketsException('Incorrect brackets'); | 
| 408 | 408 | } | 
| 409 | 409 | } | 
| 410 | -                    if ($stack->count() > 0 && Token::FUNCTION === $stack->top()->getType()) { | |
| 410 | +                    if ($stack->count() > 0 && Token::function === $stack->top()->getType()) { | |
| 411 | 411 | /** @var Token $funcToken */ | 
| 412 | 412 | $funcToken = $stack->pop(); | 
| 413 | 413 | $funcToken->setParamCount($paramCounter->pop()); | 
| @@ -120,8 +120,8 @@ discard block | ||
| 120 | 120 | $cacheKey = $expression; | 
| 121 | 121 |          if (!array_key_exists($cacheKey, $this->caches)) { | 
| 122 | 122 | $tokens = (new Tokenizer($expression, $this->operators)) | 
| 123 | - ->tokenize() | |
| 124 | - ->buildReversePolishNotation(); | |
| 123 | + ->tokenize() | |
| 124 | + ->buildReversePolishNotation(); | |
| 125 | 125 | |
| 126 | 126 |              if ($cache) { | 
| 127 | 127 | $this->caches[$cacheKey] = $tokens; | 
| @@ -456,8 +456,8 @@ discard block | ||
| 456 | 456 | protected function defaultVariables(): array | 
| 457 | 457 |      { | 
| 458 | 458 | return [ | 
| 459 | - 'pi' => 3.14159265359, | |
| 460 | - 'e' => 2.71828182846 | |
| 459 | + 'pi' => 3.14159265359, | |
| 460 | + 'e' => 2.71828182846 | |
| 461 | 461 | ]; | 
| 462 | 462 | } | 
| 463 | 463 | } | 
| @@ -55,8 +55,7 @@ discard block | ||
| 55 | 55 | * @class Executor | 
| 56 | 56 | * @package Platine\Expression | 
| 57 | 57 | */ | 
| 58 | -class Executor | |
| 59 | -{ | |
| 58 | +class Executor { | |
| 60 | 59 | /** | 
| 61 | 60 | * The variable list | 
| 62 | 61 | * @var array<string, mixed> | 
| @@ -96,16 +95,14 @@ discard block | ||
| 96 | 95 | /** | 
| 97 | 96 | * Create new instance | 
| 98 | 97 | */ | 
| 99 | - public function __construct() | |
| 100 | -    { | |
| 98 | +    public function __construct() { | |
| 101 | 99 | $this->addDefaults(); | 
| 102 | 100 | } | 
| 103 | 101 | |
| 104 | 102 | /** | 
| 105 | 103 | * When do clone of this object | 
| 106 | 104 | */ | 
| 107 | - public function __clone() | |
| 108 | -    { | |
| 105 | +    public function __clone() { | |
| 109 | 106 | $this->addDefaults(); | 
| 110 | 107 | } | 
| 111 | 108 | |
| @@ -178,7 +178,7 @@ discard block | ||
| 178 | 178 | */ | 
| 179 | 179 | public function getVariable(string $name): mixed | 
| 180 | 180 |      { | 
| 181 | -        if (! array_key_exists($name, $this->variables)) { | |
| 181 | +        if (!array_key_exists($name, $this->variables)) { | |
| 182 | 182 |              if ($this->variableNotFoundHandler !== null) { | 
| 183 | 183 | return call_user_func($this->variableNotFoundHandler, $name); | 
| 184 | 184 | } | 
| @@ -377,7 +377,7 @@ discard block | ||
| 377 | 377 | 'uNeg' => [static fn($a) => 0 - $a, 200, false], | 
| 378 | 378 | '*' => [static fn($a, $b) => $a * $b, 180, false], | 
| 379 | 379 | '/' => [ | 
| 380 | -                static function ($a, $b) { | |
| 380 | +                static function($a, $b) { | |
| 381 | 381 |                      if ($b == 0) { | 
| 382 | 382 | throw new DivisionByZeroException(); | 
| 383 | 383 | } | 
| @@ -397,7 +397,7 @@ discard block | ||
| 397 | 397 | '>' => [static fn($a, $b) => $a > $b, 150, false], | 
| 398 | 398 | '<=' => [static fn($a, $b) => $a <= $b, 150, false], | 
| 399 | 399 | '<' => [static fn($a, $b) => $a < $b, 150, false], | 
| 400 | - '!' => [static fn($a) => ! $a, 190, false], | |
| 400 | + '!' => [static fn($a) => !$a, 190, false], | |
| 401 | 401 | ]; | 
| 402 | 402 | } | 
| 403 | 403 | |
| @@ -408,14 +408,14 @@ discard block | ||
| 408 | 408 | protected function defaultFunctions(): array | 
| 409 | 409 |      { | 
| 410 | 410 | return [ | 
| 411 | -            'abs' => static function ($arg) { | |
| 411 | +            'abs' => static function($arg) { | |
| 412 | 412 |                  if ((int) $arg == $arg) { | 
| 413 | 413 | return abs(intval($arg)); | 
| 414 | 414 | } | 
| 415 | 415 | return abs(floatval($arg)); | 
| 416 | 416 | }, | 
| 417 | 417 | 'array' => static fn(...$args) => $args, | 
| 418 | -            'avg' => static function ($arg1, ...$args) { | |
| 418 | +            'avg' => static function($arg1, ...$args) { | |
| 419 | 419 |                  if (is_array($arg1)) { | 
| 420 | 420 |                      if (count($arg1) === 0) { | 
| 421 | 421 |                          throw new InvalidArgumentException('Array must contains at least one element'); | 
| @@ -427,13 +427,13 @@ discard block | ||
| 427 | 427 | $args = [$arg1, ...array_values($args)]; | 
| 428 | 428 | return array_sum($args) / count($args); | 
| 429 | 429 | }, | 
| 430 | -            'ceil' => static function ($arg) { | |
| 430 | +            'ceil' => static function($arg) { | |
| 431 | 431 |                  if ((int) $arg == $arg) { | 
| 432 | 432 | return ceil(intval($arg)); | 
| 433 | 433 | } | 
| 434 | 434 | return ceil(floatval($arg)); | 
| 435 | 435 | }, | 
| 436 | -            'floor' => static function ($arg) { | |
| 436 | +            'floor' => static function($arg) { | |
| 437 | 437 |                  if ((int) $arg == $arg) { | 
| 438 | 438 | return floor(intval($arg)); | 
| 439 | 439 | } | 
| @@ -449,22 +449,22 @@ discard block | ||
| 449 | 449 | 'sqrt' => static fn($arg) => sqrt(floatval($arg)), | 
| 450 | 450 | 'hypot' => static fn($arg1, $arg2) => hypot(floatval($arg1), floatval($arg2)), | 
| 451 | 451 | 'intdiv' => static fn($arg1, $arg2) => intdiv(intval($arg1), intval($arg2)), | 
| 452 | -            'max' => static function ($arg1, ...$args) { | |
| 452 | +            'max' => static function($arg1, ...$args) { | |
| 453 | 453 |                  if (is_array($arg1) && count($arg1) === 0) { | 
| 454 | 454 |                      throw new InvalidArgumentException('Array must contains at least one element'); | 
| 455 | 455 | } | 
| 456 | 456 | |
| 457 | 457 | return max(is_array($arg1) && count($arg1) > 0 ? $arg1 : [$arg1, ...array_values($args)]); | 
| 458 | 458 | }, | 
| 459 | -            'min' => static function ($arg1, ...$args) { | |
| 459 | +            'min' => static function($arg1, ...$args) { | |
| 460 | 460 |                  if (is_array($arg1) && count($arg1) === 0) { | 
| 461 | 461 |                      throw new InvalidArgumentException('Array must contains at least one element'); | 
| 462 | 462 | } | 
| 463 | 463 | |
| 464 | - return min(is_array($arg1) && count($arg1) > 0 ? $arg1 : [$arg1, ...array_values($args)]); | |
| 464 | + return min(is_array($arg1) && count($arg1) > 0 ? $arg1 : [$arg1, ...array_values($args)]); | |
| 465 | 465 | }, | 
| 466 | 466 | 'pow' => static fn($arg1, $arg2) => $arg1 ** $arg2, | 
| 467 | -            'round' => static function ($arg, int $precision = 0) { | |
| 467 | +            'round' => static function($arg, int $precision = 0) { | |
| 468 | 468 |                  if ((int) $arg == $arg) { | 
| 469 | 469 | return round(intval($arg), intval($precision)); | 
| 470 | 470 | } | 
| @@ -40,6 +40,5 @@ | ||
| 40 | 40 | * @class ExpressionException | 
| 41 | 41 | * @package Platine\Expression\Exception | 
| 42 | 42 | */ | 
| 43 | -class ExpressionException extends Exception | |
| 44 | -{ | |
| 43 | +class ExpressionException extends Exception { | |
| 45 | 44 | } | 
| @@ -38,6 +38,5 @@ | ||
| 38 | 38 | * @class IncorrectFunctionParameterException | 
| 39 | 39 | * @package Platine\Expression\Exception | 
| 40 | 40 | */ | 
| 41 | -class IncorrectFunctionParameterException extends ExpressionException | |
| 42 | -{ | |
| 41 | +class IncorrectFunctionParameterException extends ExpressionException { | |
| 43 | 42 | } | 
| @@ -38,6 +38,5 @@ | ||
| 38 | 38 | * @class DivisionByZeroException | 
| 39 | 39 | * @package Platine\Expression\Exception | 
| 40 | 40 | */ | 
| 41 | -class DivisionByZeroException extends ExpressionException | |
| 42 | -{ | |
| 41 | +class DivisionByZeroException extends ExpressionException { | |
| 43 | 42 | } | 
| @@ -38,6 +38,5 @@ | ||
| 38 | 38 | * @class IncorrectBracketsException | 
| 39 | 39 | * @package Platine\Expression\Exception | 
| 40 | 40 | */ | 
| 41 | -class IncorrectBracketsException extends ExpressionException | |
| 42 | -{ | |
| 41 | +class IncorrectBracketsException extends ExpressionException { | |
| 43 | 42 | } | 
| @@ -38,6 +38,5 @@ | ||
| 38 | 38 | * @class UnknownFunctionException | 
| 39 | 39 | * @package Platine\Expression\Exception | 
| 40 | 40 | */ | 
| 41 | -class UnknownFunctionException extends ExpressionException | |
| 42 | -{ | |
| 41 | +class UnknownFunctionException extends ExpressionException { | |
| 43 | 42 | } |