PluginProbe
TablePress – Tables in WordPress made easy / 3.0.4
TablePress – Tables in WordPress made easy v3.0.4
3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 2.4.4 All 44 releases
← All changes | libraries/evalmath.class.php +25 -29 2.2.23.0.4 View file →
@@ -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 ) {
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,17 +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 ];
354 + // @phpstan-ignore greater.alwaysFalse, booleanAnd.alwaysFalse
357 355 if ( in_array( -1, $counts, true ) && $arg_count > 0 ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
358 356 // Everything is fine, we expected an indefinite number arguments and got some.
359 - } elseif ( ! in_array( $arg_count, $counts, true ) ) {
357 + } elseif ( ! in_array( $arg_count, $counts, true ) ) { // @phpstan-ignore function.impossibleType
360 358 $error_data = array( 'expected' => implode( '/', $this->calc_functions[ $function_name ] ), 'given' => $arg_count );
361 359 return $this->raise_error( 'wrong_number_of_arguments', $error_data );
362 360 }
363 361 } elseif ( array_key_exists( $function_name, $this->functions ) ) {
364 362 // User-defined functions.
365 - if ( count( $this->functions[ $function_name ]['args'] ) !== $arg_count ) {
363 + if ( count( $this->functions[ $function_name ]['args'] ) !== $arg_count ) { // @phpstan-ignore notIdentical.alwaysTrue
366 364 $error_data = array( 'expected' => count( $this->functions[ $function_name ]['args'] ), 'given' => $arg_count );
367 365 return $this->raise_error( 'wrong_number_of_arguments', $error_data );
368 366 }
369 367 } else {
@@ -389,9 +387,9 @@
389 387 if ( 0 === preg_match( '/^(' . self::$name_pattern . ')\($/', (string) $stack->last( 2 ), $matches ) ) {
390 388 return $this->raise_error( 'unexpected_comma' );
391 389 }
392 390 // Increment the argument count.
393 - $stack->push( $stack->pop() + 1 );
391 + $stack->push( $stack->pop() + 1 ); // @phpstan-ignore binaryOp.invalid
394 392 // Put the ( back on, we'll need to pop back to it again.
395 393 $stack->push( '(' );
396 394 ++$index;
397 395 $expecting_operator = false;
@@ -479,9 +477,9 @@
479 477 } // while ( true )
480 478
481 479 // Pop everything off the stack and push onto output.
482 480 // phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
483 - while ( ! is_null( $op = $stack->pop() ) ) { // @phpstan-ignore-line
481 + while ( ! is_null( $op = $stack->pop() ) ) {
484 482 if ( '(' === $op ) {
485 483 // If there are (s on the stack, ()s were unbalanced.
486 484 return $this->raise_error( 'expecting_a_closing_bracket' );
487 485 }
@@ -573,10 +571,10 @@
573 571 } else {
574 572 $args[ $this->functions[ $function_name ]['args'][ $i ] ] = $arg;
575 573 }
576 574 }
577 - // yay... recursion!
578 - $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 ) );
579 577 }
580 578 } elseif ( in_array( $token, array( '+', '-', '*', '/', '^', '>', '<', '=', '%' ), true ) ) {
581 579 // If the token is a binary operator, pop two values off the stack, do the operation, and push the result back on.
582 580 $op2 = $stack->pop();
@@ -739,17 +737,16 @@
739 737 *
740 738 * @since 1.0.0
741 739 * @var mixed[]
742 740 */
743 - protected $stack = array();
741 + protected array $stack = array();
744 742
745 743 /**
746 744 * Number of items on the stack.
747 745 *
748 746 * @since 1.0.0
749 - * @var int
750 747 */
751 - public $count = 0;
748 + public int $count = 0;
752 749
753 750 /**
754 751 * Push an item onto the stack.
755 752 *
@@ -806,11 +803,10 @@
806 803 /**
807 804 * Seed for the generation of random numbers.
808 805 *
809 806 * @since 1.0.0
810 - * @var string|null
811 807 */
812 - protected static $random_seed = null;
808 + protected static ?string $random_seed = null;
813 809
814 810 /**
815 811 * Choose from two values based on an if-condition.
816 812 *
@@ -954,9 +950,9 @@
954 950 */
955 951 public static function median( array ...$args ) /* : float|int */ {
956 952 sort( $args );
957 953 $middle = intdiv( count( $args ), 2 ); // Upper median for even counts.
958 - return $args[ $middle ]; // @phpstan-ignore-line
954 + return $args[ $middle ]; // @phpstan-ignore return.type
959 955 }
960 956
961 957 /**
962 958 * Calculate the mode of the arguments.
@@ -966,11 +962,11 @@
966 962 * @param array<int, double|int> ...$args Values for which the mode shall be calculated.
967 963 * @return double|int Mode of the passed arguments.
968 964 */
969 965 public static function mode( ...$args ) /* : float|int */ {
970 - $values = array_count_values( $args );
966 + $values = array_count_values( $args ); // @phpstan-ignore argument.type
971 967 asort( $values );
972 - return array_key_last( $values ); // @phpstan-ignore-line
968 + return array_key_last( $values ); // @phpstan-ignore return.type
973 969 }
974 970
975 971 /**
976 972 * Calculate the range of the arguments.
@@ -993,9 +989,9 @@
993 989 * @param double|int ...$args Values for which the maximum value shall be found.
994 990 * @return double|int Maximum value of the passed arguments.
995 991 */
996 992 public static function max( ...$args ) /* : float|int */ {
997 - return max( $args );
993 + return max( $args ); // @phpstan-ignore argument.type
998 994 }
999 995
1000 996 /**
1001 997 * Find the minimum value of the arguments.
@@ -1005,9 +1001,9 @@
1005 1001 * @param double|int ...$args Values for which the minimum value shall be found.
1006 1002 * @return double|int Minimum value of the passed arguments.
1007 1003 */
1008 1004 public static function min( ...$args ) /* : float|int */ {
1009 - return min( $args );
1005 + return min( $args ); // @phpstan-ignore argument.type
1010 1006 }
1011 1007
1012 1008 /**
1013 1009 * Calculate the remainder of a division of two numbers.
@@ -1169,8 +1165,8 @@
1169 1165 * @return double Random number from the range [0, 1].
1170 1166 */
1171 1167 public static function rand_float(): float {
1172 1168 $random_values = unpack( 'v', md5( self::_get_random_seed(), true ) );
1173 - return array_shift( $random_values ) / 65536; // @phpstan-ignore-line
1169 + return array_shift( $random_values ) / 65536; // @phpstan-ignore argument.type
1174 1170 }
1175 1171
1176 1172 } // class EvalMath_Functions