| @@ -7,8 +7,10 @@ | ||
| 7 | 7 | * @author Tobias Bäthge |
| 8 | 8 | * @since 1.5.0 |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | +declare(strict_types=1); | |
| 12 | + | |
| 11 | 13 | // Prohibit direct script loading. |
| 12 | 14 | defined( 'ABSPATH' ) || die( 'No direct script access allowed!' ); |
| 13 | 15 | |
| 14 | 16 | /** |
| @@ -29,15 +31,15 @@ | ||
| 29 | 31 | * @since 2.0.0 |
| 30 | 32 | * |
| 31 | 33 | * @return bool Whether the legacy evaluate class should be used. |
| 32 | 34 | */ |
| 33 | - protected function _should_use_legacy_evaluate_class() { | |
| 35 | + protected function _should_use_legacy_evaluate_class(): bool { | |
| 34 | 36 | /** |
| 35 | 37 | * Filters whether the Legacy Table Evaluate class shall be used. |
| 36 | 38 | * |
| 37 | 39 | * @since 2.0.0 |
| 38 | 40 | * |
| 39 | - * @param bool Whether to use the legacy table evaluate class. Default false. | |
| 41 | + * @param bool $use_legacy_class Whether to use the legacy table evaluate class. Default false. | |
| 40 | 42 | */ |
| 41 | 43 | if ( apply_filters( 'tablepress_use_legacy_table_evaluate_class', false ) ) { |
| 42 | 44 | return true; |
| 43 | 45 | } |
| @@ -42,19 +44,13 @@ | ||
| 42 | 44 | return true; |
| 43 | 45 | } |
| 44 | 46 | |
| 45 | 47 | // Use the legacy evaluate class, if the requirements for PHPSpreadsheet Calculations are not fulfilled. |
| 46 | - $phpspreadsheet_requirements_fulfilled = PHP_VERSION_ID >= 70200 | |
| 47 | - && extension_loaded( 'mbstring' ); | |
| 48 | + $phpspreadsheet_requirements_fulfilled = extension_loaded( 'mbstring' ); | |
| 48 | 49 | if ( ! $phpspreadsheet_requirements_fulfilled ) { |
| 49 | 50 | return true; |
| 50 | 51 | } |
| 51 | 52 | |
| 52 | - // Use the legacy evaluate class, if the PHPSpreadsheet files do not exist (e.g. because `composer install` was not run). | |
| 53 | - if ( ! file_exists( TABLEPRESS_ABSPATH . 'libraries/autoload.php' ) ) { | |
| 54 | - return true; | |
| 55 | - } | |
| 56 | - | |
| 57 | 53 | return false; |
| 58 | 54 | } |
| 59 | 55 | |
| 60 | 56 | /** |
| @@ -61,17 +57,15 @@ | ||
| 61 | 57 | * Evaluate formulas in the passed table. |
| 62 | 58 | * |
| 63 | 59 | * @since 1.0.0 |
| 64 | 60 | * |
| 65 | - * @param array $table_data Table data in which formulas shall be evaluated. | |
| 66 | - * @param string $table_id ID of the passed table. | |
| 67 | - * @return array Table data with evaluated formulas. | |
| 61 | + * @param array<int, array<int, string>> $table_data Table data in which formulas shall be evaluated. | |
| 62 | + * @param string $table_id ID of the passed table. | |
| 63 | + * @return array<int, array<int, string>> Table data with evaluated formulas. | |
| 68 | 64 | */ |
| 69 | - public function evaluate_table_data( array $table_data, $table_id ) { | |
| 70 | - $use_legacy_evaluate_class = $this->_should_use_legacy_evaluate_class(); | |
| 71 | - | |
| 65 | + public function evaluate_table_data( array $table_data, string $table_id ): array { | |
| 72 | 66 | // Choose the Table Evaluate library based on the PHP version and the filter hook value. |
| 73 | - if ( $use_legacy_evaluate_class ) { | |
| 67 | + if ( $this->_should_use_legacy_evaluate_class() ) { | |
| 74 | 68 | $evaluate_class = TablePress::load_class( 'TablePress_Evaluate_Legacy', 'class-evaluate-legacy.php', 'classes' ); |
| 75 | 69 | } else { |
| 76 | 70 | $evaluate_class = TablePress::load_class( 'TablePress_Evaluate_PHPSpreadsheet', 'class-evaluate-phpspreadsheet.php', 'classes' ); |
| 77 | 71 | } |