| @@ -29,27 +29,24 @@ | ||
| 29 | 29 | * |
| 30 | 30 | * Note, variable and function names are case insensitive. |
| 31 | 31 | * |
| 32 | 32 | * @since 1.0.0 |
| 33 | - * @var string | |
| 34 | 33 | */ |
| 35 | - protected static $name_pattern = '[a-z][a-z0-9_]*'; | |
| 34 | + protected static string $name_pattern = '[a-z][a-z0-9_]*'; | |
| 36 | 35 | |
| 37 | 36 | /** |
| 38 | 37 | * Whether to suppress errors and warnings. |
| 39 | 38 | * |
| 40 | 39 | * @since 1.0.0 |
| 41 | - * @var bool | |
| 42 | 40 | */ |
| 43 | - public $suppress_errors = false; | |
| 41 | + public bool $suppress_errors = false; | |
| 44 | 42 | |
| 45 | 43 | /** |
| 46 | 44 | * The last error message that was raised. |
| 47 | 45 | * |
| 48 | 46 | * @since 1.0.0 |
| 49 | - * @var string | |
| 50 | 47 | */ |
| 51 | - public $last_error = ''; | |
| 48 | + public string $last_error = ''; | |
| 52 | 49 | |
| 53 | 50 | /** |
| 54 | 51 | * Variables (including constants). |
| 55 | 52 | * |
| @@ -55,9 +52,9 @@ | ||
| 55 | 52 | * |
| 56 | 53 | * @since 1.0.0 |
| 57 | 54 | * @var array<string, mixed> |
| 58 | 55 | */ |
| 59 | - public $variables = array(); | |
| 56 | + public array $variables = array(); | |
| 60 | 57 | |
| 61 | 58 | /** |
| 62 | 59 | * User-defined functions. |
| 63 | 60 | * |
| @@ -63,9 +60,9 @@ | ||
| 63 | 60 | * |
| 64 | 61 | * @since 1.0.0 |
| 65 | 62 | * @var array<string, mixed> |
| 66 | 63 | */ |
| 67 | - protected $functions = array(); | |
| 64 | + protected array $functions = array(); | |
| 68 | 65 | |
| 69 | 66 | /** |
| 70 | 67 | * Constants. |
| 71 | 68 | * |
| @@ -71,9 +68,9 @@ | ||
| 71 | 68 | * |
| 72 | 69 | * @since 1.0.0 |
| 73 | 70 | * @var array<string, mixed> |
| 74 | 71 | */ |
| 75 | - protected $constants = array(); | |
| 72 | + protected array $constants = array(); | |
| 76 | 73 | |
| 77 | 74 | /** |
| 78 | 75 | * Built-in functions. |
| 79 | 76 | * |
| @@ -79,9 +76,9 @@ | ||
| 79 | 76 | * |
| 80 | 77 | * @since 1.0.0 |
| 81 | 78 | * @var string[] |
| 82 | 79 | */ |
| 83 | - protected $builtin_functions = array( | |
| 80 | + protected array $builtin_functions = array( | |
| 84 | 81 | 'sin', |
| 85 | 82 | 'sinh', |
| 86 | 83 | 'arcsin', |
| 87 | 84 | 'asin', |
| @@ -113,9 +110,9 @@ | ||
| 113 | 110 | * |
| 114 | 111 | * @since 1.0.0 |
| 115 | 112 | * @var array<string, int[]> |
| 116 | 113 | */ |
| 117 | - protected $calc_functions = array( | |
| 114 | + protected array $calc_functions = array( | |
| 118 | 115 | 'average' => array( -1 ), |
| 119 | 116 | 'mean' => array( -1 ), |
| 120 | 117 | 'median' => array( -1 ), |
| 121 | 118 | 'mode' => array( -1 ), |
| @@ -346,9 +343,9 @@ | ||
| 346 | 343 | $output[] = array( 'function_name' => $function_name, 'arg_count' => $arg_count ); |
| 347 | 344 | // Check the argument count, depending on what type of function we have. |
| 348 | 345 | if ( in_array( $function_name, $this->builtin_functions, true ) ) { |
| 349 | 346 | // Built-in functions. |
| 350 | - if ( $arg_count > 1 ) { // @phpstan-ignore-line | |
| 347 | + if ( $arg_count > 1 ) { // @phpstan-ignore greater.alwaysFalse | |
| 351 | 348 | $error_data = array( 'expected' => 1, 'given' => $arg_count ); |
| 352 | 349 | return $this->raise_error( 'wrong_number_of_arguments', $error_data ); |
| 353 | 350 | } |
| 354 | 351 | } elseif ( array_key_exists( $function_name, $this->calc_functions ) ) { |
| @@ -353,18 +350,18 @@ | ||
| 353 | 350 | } |
| 354 | 351 | } elseif ( array_key_exists( $function_name, $this->calc_functions ) ) { |
| 355 | 352 | // Calc-emulation functions. |
| 356 | 353 | $counts = $this->calc_functions[ $function_name ]; |
| 357 | - // @phpstan-ignore-next-line | |
| 354 | + // @phpstan-ignore greater.alwaysFalse, booleanAnd.alwaysFalse | |
| 358 | 355 | if ( in_array( -1, $counts, true ) && $arg_count > 0 ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf |
| 359 | 356 | // Everything is fine, we expected an indefinite number arguments and got some. |
| 360 | - } elseif ( ! in_array( $arg_count, $counts, true ) ) { // @phpstan-ignore-line | |
| 357 | + } elseif ( ! in_array( $arg_count, $counts, true ) ) { // @phpstan-ignore function.impossibleType | |
| 361 | 358 | $error_data = array( 'expected' => implode( '/', $this->calc_functions[ $function_name ] ), 'given' => $arg_count ); |
| 362 | 359 | return $this->raise_error( 'wrong_number_of_arguments', $error_data ); |
| 363 | 360 | } |
| 364 | 361 | } elseif ( array_key_exists( $function_name, $this->functions ) ) { |
| 365 | 362 | // User-defined functions. |
| 366 | - if ( count( $this->functions[ $function_name ]['args'] ) !== $arg_count ) { | |
| 363 | + if ( count( $this->functions[ $function_name ]['args'] ) !== $arg_count ) { // @phpstan-ignore notIdentical.alwaysTrue | |
| 367 | 364 | $error_data = array( 'expected' => count( $this->functions[ $function_name ]['args'] ), 'given' => $arg_count ); |
| 368 | 365 | return $this->raise_error( 'wrong_number_of_arguments', $error_data ); |
| 369 | 366 | } |
| 370 | 367 | } else { |
| @@ -390,9 +387,9 @@ | ||
| 390 | 387 | if ( 0 === preg_match( '/^(' . self::$name_pattern . ')\($/', (string) $stack->last( 2 ), $matches ) ) { |
| 391 | 388 | return $this->raise_error( 'unexpected_comma' ); |
| 392 | 389 | } |
| 393 | 390 | // Increment the argument count. |
| 394 | - $stack->push( $stack->pop() + 1 ); // @phpstan-ignore-line | |
| 391 | + $stack->push( $stack->pop() + 1 ); // @phpstan-ignore binaryOp.invalid | |
| 395 | 392 | // Put the ( back on, we'll need to pop back to it again. |
| 396 | 393 | $stack->push( '(' ); |
| 397 | 394 | ++$index; |
| 398 | 395 | $expecting_operator = false; |
| @@ -480,9 +477,9 @@ | ||
| 480 | 477 | } // while ( true ) |
| 481 | 478 | |
| 482 | 479 | // Pop everything off the stack and push onto output. |
| 483 | 480 | // phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition |
| 484 | - while ( ! is_null( $op = $stack->pop() ) ) { // @phpstan-ignore-line | |
| 481 | + while ( ! is_null( $op = $stack->pop() ) ) { | |
| 485 | 482 | if ( '(' === $op ) { |
| 486 | 483 | // If there are (s on the stack, ()s were unbalanced. |
| 487 | 484 | return $this->raise_error( 'expecting_a_closing_bracket' ); |
| 488 | 485 | } |
| @@ -574,10 +571,10 @@ | ||
| 574 | 571 | } else { |
| 575 | 572 | $args[ $this->functions[ $function_name ]['args'][ $i ] ] = $arg; |
| 576 | 573 | } |
| 577 | 574 | } |
| 578 | - // yay... recursion! | |
| 579 | - $stack->push( $this->pfx( $this->functions[ $function_name ]['func'], $args ) ); // @phpstan-ignore-line | |
| 575 | + // Recursion. | |
| 576 | + $stack->push( $this->pfx( $this->functions[ $function_name ]['func'], $args ) ); // @phpstan-ignore argument.type | |
| 580 | 577 | } |
| 581 | 578 | } elseif ( in_array( $token, array( '+', '-', '*', '/', '^', '>', '<', '=', '%' ), true ) ) { |
| 582 | 579 | // If the token is a binary operator, pop two values off the stack, do the operation, and push the result back on. |
| 583 | 580 | $op2 = $stack->pop(); |
| @@ -740,17 +737,16 @@ | ||
| 740 | 737 | * |
| 741 | 738 | * @since 1.0.0 |
| 742 | 739 | * @var mixed[] |
| 743 | 740 | */ |
| 744 | - protected $stack = array(); | |
| 741 | + protected array $stack = array(); | |
| 745 | 742 | |
| 746 | 743 | /** |
| 747 | 744 | * Number of items on the stack. |
| 748 | 745 | * |
| 749 | 746 | * @since 1.0.0 |
| 750 | - * @var int | |
| 751 | 747 | */ |
| 752 | - public $count = 0; | |
| 748 | + public int $count = 0; | |
| 753 | 749 | |
| 754 | 750 | /** |
| 755 | 751 | * Push an item onto the stack. |
| 756 | 752 | * |
| @@ -807,11 +803,10 @@ | ||
| 807 | 803 | /** |
| 808 | 804 | * Seed for the generation of random numbers. |
| 809 | 805 | * |
| 810 | 806 | * @since 1.0.0 |
| 811 | - * @var string|null | |
| 812 | 807 | */ |
| 813 | - protected static $random_seed = null; | |
| 808 | + protected static ?string $random_seed = null; | |
| 814 | 809 | |
| 815 | 810 | /** |
| 816 | 811 | * Choose from two values based on an if-condition. |
| 817 | 812 | * |
| @@ -955,9 +950,9 @@ | ||
| 955 | 950 | */ |
| 956 | 951 | public static function median( array ...$args ) /* : float|int */ { |
| 957 | 952 | sort( $args ); |
| 958 | 953 | $middle = intdiv( count( $args ), 2 ); // Upper median for even counts. |
| 959 | - return $args[ $middle ]; // @phpstan-ignore-line | |
| 954 | + return $args[ $middle ]; // @phpstan-ignore return.type | |
| 960 | 955 | } |
| 961 | 956 | |
| 962 | 957 | /** |
| 963 | 958 | * Calculate the mode of the arguments. |
| @@ -967,11 +962,11 @@ | ||
| 967 | 962 | * @param array<int, double|int> ...$args Values for which the mode shall be calculated. |
| 968 | 963 | * @return double|int Mode of the passed arguments. |
| 969 | 964 | */ |
| 970 | 965 | public static function mode( ...$args ) /* : float|int */ { |
| 971 | - $values = array_count_values( $args ); | |
| 966 | + $values = array_count_values( $args ); // @phpstan-ignore argument.type | |
| 972 | 967 | asort( $values ); |
| 973 | - return array_key_last( $values ); // @phpstan-ignore-line | |
| 968 | + return array_key_last( $values ); // @phpstan-ignore return.type | |
| 974 | 969 | } |
| 975 | 970 | |
| 976 | 971 | /** |
| 977 | 972 | * Calculate the range of the arguments. |
| @@ -994,9 +989,9 @@ | ||
| 994 | 989 | * @param double|int ...$args Values for which the maximum value shall be found. |
| 995 | 990 | * @return double|int Maximum value of the passed arguments. |
| 996 | 991 | */ |
| 997 | 992 | public static function max( ...$args ) /* : float|int */ { |
| 998 | - return max( $args ); | |
| 993 | + return max( $args ); // @phpstan-ignore argument.type | |
| 999 | 994 | } |
| 1000 | 995 | |
| 1001 | 996 | /** |
| 1002 | 997 | * Find the minimum value of the arguments. |
| @@ -1006,9 +1001,9 @@ | ||
| 1006 | 1001 | * @param double|int ...$args Values for which the minimum value shall be found. |
| 1007 | 1002 | * @return double|int Minimum value of the passed arguments. |
| 1008 | 1003 | */ |
| 1009 | 1004 | public static function min( ...$args ) /* : float|int */ { |
| 1010 | - return min( $args ); | |
| 1005 | + return min( $args ); // @phpstan-ignore argument.type | |
| 1011 | 1006 | } |
| 1012 | 1007 | |
| 1013 | 1008 | /** |
| 1014 | 1009 | * Calculate the remainder of a division of two numbers. |
| @@ -1170,8 +1165,8 @@ | ||
| 1170 | 1165 | * @return double Random number from the range [0, 1]. |
| 1171 | 1166 | */ |
| 1172 | 1167 | public static function rand_float(): float { |
| 1173 | 1168 | $random_values = unpack( 'v', md5( self::_get_random_seed(), true ) ); |
| 1174 | - return array_shift( $random_values ) / 65536; // @phpstan-ignore-line | |
| 1169 | + return array_shift( $random_values ) / 65536; // @phpstan-ignore argument.type | |
| 1175 | 1170 | } |
| 1176 | 1171 | |
| 1177 | 1172 | } // class EvalMath_Functions |