From d233b6bf18888dafc85b2bf6a627efd89a8253ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Wed, 22 May 2024 18:24:35 +0200 Subject: [PATCH 1/7] Try more strict phpstan.neon --- phpstan.neon | 1 - 1 file changed, 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index 1293f5a..e134a4f 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -15,4 +15,3 @@ parameters: - assets/lib/locales/locales.php # TODO Tell PHPStan what is inside arrays. checkMissingIterableValueType: false - treatPhpDocTypesAsCertain: false From 79e68f0cf50a06c0dd7b2f9fc32185ac4e3424d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Wed, 22 May 2024 18:26:50 +0200 Subject: [PATCH 2/7] ensured in previous condition --- .../class-site-health-test-wordpress-translations-locale.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-site-health-test-wordpress-translations-locale.php b/includes/class-site-health-test-wordpress-translations-locale.php index c1c1c59..8453346 100644 --- a/includes/class-site-health-test-wordpress-translations-locale.php +++ b/includes/class-site-health-test-wordpress-translations-locale.php @@ -98,7 +98,7 @@ public function run_test() { $formatted_name = Options_General::locale_name_format( $locale ); // Check if Language Packs exist for the Locale and if the Language Pack major version is the same as the WordPress installed major version. - if ( $locale->has_translations() && isset( $locale_translations_version ) && $translation_project_version === $locale_translations_version ) { + if ( $locale->has_translations() && $translation_project_version === $locale_translations_version ) { $this->test_status = self::TRANSLATION_TOOLS_SITE_HEALTH_STATUS_GOOD; $this->test_label = sprintf( From c9f37f4e8ea38e4acef72ab4991bbe6d8aab3326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Wed, 22 May 2024 18:31:07 +0200 Subject: [PATCH 3/7] in the array! --- includes/class-update-translations.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-update-translations.php b/includes/class-update-translations.php index 8d23789..d97b24d 100644 --- a/includes/class-update-translations.php +++ b/includes/class-update-translations.php @@ -305,7 +305,7 @@ public function download_translations( $type, $project, $locale ) { * @param Locale $locale Locale object. * @param array $response HTTP response. * - * @return array|WP_Error Array on success, WP_Error on failure. + * @return array|array{data:WP_Error} Array on success, WP_Error on failure. */ public function generate_po( $destination, $project, $locale, $response ) { From 3ffbc4d216e5c80f2e3fe3699a6cda3ddaf130d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Wed, 22 May 2024 19:02:03 +0200 Subject: [PATCH 4/7] debug --- includes/class-update-translations.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/includes/class-update-translations.php b/includes/class-update-translations.php index d97b24d..da364db 100644 --- a/includes/class-update-translations.php +++ b/includes/class-update-translations.php @@ -106,8 +106,11 @@ public function update_translation( $type, $project, $wp_locale, $generate_po_mo // Generate .po from WordPress.org response. $generate_po = $this->generate_po( $destination, $project, $locale, $download['data'] ); + \PHPStan\dumpType($generate_po); array_push( $result['log'], $generate_po['log'] ); $result['data'] = $generate_po['data']; + \PHPStan\dumpType($generate_po['data']); + \PHPStan\dumpType($result['data']); if ( is_wp_error( $result['data'] ) ) { return $result; } From fefc4b08b66f4312b36de8730c26bd4f8c722b84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Wed, 22 May 2024 19:07:39 +0200 Subject: [PATCH 5/7] full array shape --- includes/class-update-translations.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-update-translations.php b/includes/class-update-translations.php index da364db..9364737 100644 --- a/includes/class-update-translations.php +++ b/includes/class-update-translations.php @@ -308,7 +308,7 @@ public function download_translations( $type, $project, $locale ) { * @param Locale $locale Locale object. * @param array $response HTTP response. * - * @return array|array{data:WP_Error} Array on success, WP_Error on failure. + * @return array{log:string, data:true}|array{data:WP_Error} Array on success, WP_Error on failure. */ public function generate_po( $destination, $project, $locale, $response ) { From bffbdbedbf4a7426b980a41c84ca9b534c0712e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Wed, 22 May 2024 19:16:55 +0200 Subject: [PATCH 6/7] add another array shape --- includes/class-update-translations.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/includes/class-update-translations.php b/includes/class-update-translations.php index 9364737..91fd5fc 100644 --- a/includes/class-update-translations.php +++ b/includes/class-update-translations.php @@ -80,6 +80,7 @@ public function update_translation( $type, $project, $wp_locale, $generate_po_mo $generate_json = apply_filters( 'translation_tools_update_generate_json', $generate_json ) ? true : false; // Define variable. + /** @var array{log: array, data: true|WP_Error} $result */ $result = array(); // Destination of translation files. @@ -106,11 +107,9 @@ public function update_translation( $type, $project, $wp_locale, $generate_po_mo // Generate .po from WordPress.org response. $generate_po = $this->generate_po( $destination, $project, $locale, $download['data'] ); - \PHPStan\dumpType($generate_po); array_push( $result['log'], $generate_po['log'] ); $result['data'] = $generate_po['data']; - \PHPStan\dumpType($generate_po['data']); - \PHPStan\dumpType($result['data']); + \PHPStan\dumpType( $result['data'] ); if ( is_wp_error( $result['data'] ) ) { return $result; } From 4b24989aadd6a9ac4aff7daad09bc2ef5efd6119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Wed, 22 May 2024 19:23:26 +0200 Subject: [PATCH 7/7] violence --- includes/class-update-translations.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-update-translations.php b/includes/class-update-translations.php index 91fd5fc..41935f3 100644 --- a/includes/class-update-translations.php +++ b/includes/class-update-translations.php @@ -80,7 +80,6 @@ public function update_translation( $type, $project, $wp_locale, $generate_po_mo $generate_json = apply_filters( 'translation_tools_update_generate_json', $generate_json ) ? true : false; // Define variable. - /** @var array{log: array, data: true|WP_Error} $result */ $result = array(); // Destination of translation files. @@ -109,6 +108,7 @@ public function update_translation( $type, $project, $wp_locale, $generate_po_mo $generate_po = $this->generate_po( $destination, $project, $locale, $download['data'] ); array_push( $result['log'], $generate_po['log'] ); $result['data'] = $generate_po['data']; + /** @var array{log: array, data: true|WP_Error} $result Results. */ \PHPStan\dumpType( $result['data'] ); if ( is_wp_error( $result['data'] ) ) { return $result;