@@ -54,8 +54,7 @@ |
||
54 | 54 | * @class Operator |
55 | 55 | * @package Platine\Expression |
56 | 56 | */ |
57 | -class Operator |
|
58 | -{ |
|
57 | +class Operator { |
|
59 | 58 | /** |
60 | 59 | * The operator like =, >=, ... |
61 | 60 | * @var string |
@@ -51,8 +51,7 @@ discard block |
||
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 | */ |
@@ -96,8 +95,7 @@ discard block |
||
96 | 95 | * @param mixed $value |
97 | 96 | * @param string|null $name |
98 | 97 | */ |
99 | - public function __construct(string $type, $value, ?string $name = null) |
|
100 | - { |
|
98 | + public function __construct(string $type, $value, ?string $name = null) { |
|
101 | 99 | $this->name = $name; |
102 | 100 | $this->value = $value; |
103 | 101 | $this->type = $type; |
@@ -116,8 +114,7 @@ discard block |
||
116 | 114 | * Return the token value |
117 | 115 | * @return mixed |
118 | 116 | */ |
119 | - public function getValue() |
|
120 | - { |
|
117 | + public function getValue() { |
|
121 | 118 | return $this->value; |
122 | 119 | } |
123 | 120 |
@@ -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'; |
@@ -54,8 +54,7 @@ discard block |
||
54 | 54 | * @class CustomFunction |
55 | 55 | * @package Platine\Expression |
56 | 56 | */ |
57 | -class CustomFunction |
|
58 | -{ |
|
57 | +class CustomFunction { |
|
59 | 58 | /** |
60 | 59 | * The function name |
61 | 60 | * @var string |
@@ -79,8 +78,7 @@ discard block |
||
79 | 78 | * @param string $name |
80 | 79 | * @param callable $function |
81 | 80 | */ |
82 | - public function __construct(string $name, callable $function) |
|
83 | - { |
|
81 | + public function __construct(string $name, callable $function) { |
|
84 | 82 | $this->name = $name; |
85 | 83 | $this->function = $function; |
86 | 84 |
@@ -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 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | */ |
175 | 175 | public function getVariable(string $name) |
176 | 176 | { |
177 | - if (! array_key_exists($name, $this->variables)) { |
|
177 | + if (!array_key_exists($name, $this->variables)) { |
|
178 | 178 | if ($this->variableNotFoundHandler !== null) { |
179 | 179 | return call_user_func($this->variableNotFoundHandler, $name); |
180 | 180 | } |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | 'uNeg' => [static fn($a) => 0 - $a, 200, false], |
374 | 374 | '*' => [static fn($a, $b) => $a * $b, 180, false], |
375 | 375 | '/' => [ |
376 | - static function ($a, $b) { |
|
376 | + static function($a, $b) { |
|
377 | 377 | if ($b == 0) { |
378 | 378 | throw new DivisionByZeroException(); |
379 | 379 | } |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | return [ |
406 | 406 | 'abs' => static fn($arg) => abs($arg), |
407 | 407 | 'array' => static fn(...$args) => $args, |
408 | - 'avg' => static function ($arg1, ...$args) { |
|
408 | + 'avg' => static function($arg1, ...$args) { |
|
409 | 409 | if (is_array($arg1)) { |
410 | 410 | if (count($arg1) === 0) { |
411 | 411 | throw new InvalidArgumentException('Array must contains at least one element'); |
@@ -429,14 +429,14 @@ discard block |
||
429 | 429 | 'sqrt' => static fn($arg) => sqrt(floatval($arg)), |
430 | 430 | 'hypot' => static fn($arg1, $arg2) => hypot(floatval($arg1), floatval($arg2)), |
431 | 431 | 'intdiv' => static fn($arg1, $arg2) => intdiv(intval($arg1), intval($arg2)), |
432 | - 'max' => static function ($arg1, ...$args) { |
|
432 | + 'max' => static function($arg1, ...$args) { |
|
433 | 433 | if (is_array($arg1) && count($arg1) === 0) { |
434 | 434 | throw new InvalidArgumentException('Array must contains at least one element'); |
435 | 435 | } |
436 | 436 | |
437 | 437 | return max(is_array($arg1) ? $arg1 : [$arg1, ...$args]); |
438 | 438 | }, |
439 | - 'min' => static function ($arg1, ...$args) { |
|
439 | + 'min' => static function($arg1, ...$args) { |
|
440 | 440 | if (is_array($arg1) && count($arg1) === 0) { |
441 | 441 | throw new InvalidArgumentException('Array must contains at least one element'); |
442 | 442 | } |
@@ -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, int|float> |
@@ -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 | |
@@ -115,8 +112,7 @@ discard block |
||
115 | 112 | * @param bool $cache |
116 | 113 | * @return int|float|string|null |
117 | 114 | */ |
118 | - public function execute(string $expression, bool $cache = true) |
|
119 | - { |
|
115 | + public function execute(string $expression, bool $cache = true) { |
|
120 | 116 | $cacheKey = $expression; |
121 | 117 | if (!array_key_exists($cacheKey, $this->caches)) { |
122 | 118 | $tokens = (new Tokenizer($expression, $this->operators)) |
@@ -172,8 +168,7 @@ discard block |
||
172 | 168 | * @param string $name |
173 | 169 | * @return int|float |
174 | 170 | */ |
175 | - public function getVariable(string $name) |
|
176 | - { |
|
171 | + public function getVariable(string $name) { |
|
177 | 172 | if (! array_key_exists($name, $this->variables)) { |
178 | 173 | if ($this->variableNotFoundHandler !== null) { |
179 | 174 | return call_user_func($this->variableNotFoundHandler, $name); |