PluginProbe
TablePress – Tables in WordPress made easy / 3.0
TablePress – Tables in WordPress made easy v3.0
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 | classes/class-import.php +15 -14 2.4.23.0 View file →
@@ -25,14 +25,14 @@
25 25 */
26 26 class TablePress_Import {
27 27
28 28 /**
29 - * Instance of the TablePress Legacy Importer.
29 + * Instance of the TablePress Legacy or PHPSpreadsheet Importer.
30 30 *
31 31 * @since 1.0.0
32 - * @var TablePress_Import_Legacy
32 + * @var TablePress_Import_Legacy|TablePress_Import_PHPSpreadsheet
33 33 */
34 - protected $importer;
34 + protected object $importer;
35 35
36 36 /**
37 37 * Import configuration (mainly the data from the Import form).
38 38 *
@@ -38,9 +38,9 @@
38 38 *
39 39 * @since 2.0.0
40 40 * @var array<string, mixed>
41 41 */
42 - protected $import_config = array();
42 + protected array $import_config = array();
43 43
44 44 /**
45 45 * Whether ZIP archive support is available (which it always is, as PclZip is used as a fallback).
46 46 *
@@ -45,11 +45,10 @@
45 45 * Whether ZIP archive support is available (which it always is, as PclZip is used as a fallback).
46 46 *
47 47 * @since 1.0.0
48 48 * @deprecated 2.3.0 ZIP support is now always available, either through `ZipArchive` or through `PclZip`.
49 - * @var bool
50 49 */
51 - public $zip_support_available = true;
50 + public bool $zip_support_available = true;
52 51
53 52 /**
54 53 * List of table names/IDs for use when replacing/appending existing tables (except for the JSON format).
55 54 *
@@ -55,9 +54,9 @@
55 54 *
56 55 * @since 2.0.0
57 56 * @var array<string, string[]>
58 57 */
59 - protected $table_names_ids = array();
58 + protected array $table_names_ids = array();
60 59
61 60 /**
62 61 * Runs the import process for a given import configuration.
63 62 *
@@ -134,9 +133,9 @@
134 133
135 134 /**
136 135 * Load WP file functions to be sure that `download_url()` exists, in particular during Cron requests.
137 136 */
138 - require_once ABSPATH . 'wp-admin/includes/file.php';
137 + require_once ABSPATH . 'wp-admin/includes/file.php'; // @phpstan-ignore requireOnce.fileNotFound (This is a WordPress core file that always exists.)
139 138
140 139 // Download URL to local file.
141 140 $location = download_url( $this->import_config['url'] );
142 141 if ( is_wp_error( $location ) ) {
@@ -286,16 +285,16 @@
286 285 * @return File[]|WP_Error List of files to import that were extracted from the ZIP file or WP_Error on failure.
287 286 */
288 287 protected function extract_zip_file_ziparchive( File $zip_file ) /* : array|WP_Error */ {
289 288 $archive = new ZipArchive();
290 - $archive_opened = $archive->open( $zip_file->location, ZIPARCHIVE::CHECKCONS );
289 + $archive_opened = $archive->open( $zip_file->location, ZipArchive::CHECKCONS );
291 290
292 - // If the ZIP file can't be opened with ZIPARCHIVE::CHECKCONS, try again without.
291 + // If the ZIP file can't be opened with ZipArchive::CHECKCONS, try again without.
293 292 if ( true !== $archive_opened ) {
294 293 $archive_opened = $archive->open( $zip_file->location );
295 294 }
296 295
297 - // If the ZIP file can't even be opened without ZIPARCHIVE::CHECKCONS, bail.
296 + // If the ZIP file can't even be opened without ZipArchive::CHECKCONS, bail.
298 297 if ( true !== $archive_opened ) {
299 298 return new WP_Error( 'table_import_error_zip_open', '', array( 'ziparchive_error' => $archive_opened ) );
300 299 }
301 300
@@ -370,12 +369,12 @@
370 369 */
371 370 protected function extract_zip_file_pclzip( File $zip_file ) /* : array|WP_Error */ {
372 371 mbstring_binary_safe_encoding();
373 372
374 - require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
373 + require_once ABSPATH . 'wp-admin/includes/class-pclzip.php'; // @phpstan-ignore requireOnce.fileNotFound (This is a WordPress core file that always exists.)
375 374
376 375 $archive = new PclZip( $zip_file->location );
377 - $archive_files = $archive->extract( PCLZIP_OPT_EXTRACT_AS_STRING ); // @phpstan-ignore-line PclZip::extract() uses `func_get_args()` to handle optional arguments.
376 + $archive_files = $archive->extract( PCLZIP_OPT_EXTRACT_AS_STRING ); // @phpstan-ignore arguments.count (PclZip::extract() uses `func_get_args()` to handle optional arguments.)
378 377
379 378 reset_mbstring_encoding();
380 379
381 380 // If the ZIP file can't be opened, bail.
@@ -510,10 +509,12 @@
510 509 TablePress::load_file( 'class-import-base.php', 'classes' );
511 510
512 511 // Choose the Table Import library based on the PHP version and the filter hook value.
513 512 if ( $use_legacy_import_class ) {
513 + // @phpstan-ignore assign.propertyType (The `load_class()` method returns `object` and not a specific type.)
514 514 $this->importer = TablePress::load_class( 'TablePress_Import_Legacy', 'class-import-legacy.php', 'classes' );
515 515 } else {
516 + // @phpstan-ignore assign.propertyType (The `load_class()` method returns `object` and not a specific type.)
516 517 $this->importer = TablePress::load_class( 'TablePress_Import_PHPSpreadsheet', 'class-import-phpspreadsheet.php', 'classes' );
517 518 }
518 519
519 520 // If there is more than one valid import file, ignore the chosen existing table for replacing/appending.
@@ -656,9 +657,9 @@
656 657 * @return array<string, mixed>|WP_Error Loaded table on success (either with all properties or just 'data'), WP_Error on failure.
657 658 */
658 659 protected function load_table_from_file_phpspreadsheet( File $file ) /* : array|WP_Error */ {
659 660 // Convert File object to array, as those are not yet used outside of this class.
660 - return $this->importer->import_table( $file ); // @phpstan-ignore-line
661 + return $this->importer->import_table( $file ); // @phpstan-ignore return.type (This is an instance of TablePress_Import_PHPSpreadsheet which does not return false.)
661 662 }
662 663
663 664 /**
664 665 * Imports a loaded table into TablePress.