Skip to content

Commit 857d19d

Browse files
authored
Fix PHP-Scoper & PHPStan issues (#14482)
1 parent c54f70b commit 857d19d

27 files changed

+471
-378
lines changed

.github/workflows/tests-unit-php.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ jobs:
5555
continue-on-error: ${{ matrix.experimental }}
5656
strategy:
5757
matrix:
58-
php: ['8.3', '8.2', '8.1', '8.0']
58+
php: ['8.4', '8.3', '8.2', '8.1', '8.0']
5959
wp: ['latest']
6060
coverage: [false]
6161
experimental: [false]
6262
include:
63-
- php: '8.4'
63+
- php: '8.5'
6464
wp: 'latest'
6565
coverage: true
6666
experimental: false
6767

68-
- php: '8.4'
68+
- php: '8.5'
6969
wp: 'latest'
7070
random: true
7171
experimental: true
@@ -74,7 +74,7 @@ jobs:
7474
wp: '6.6'
7575
experimental: false
7676

77-
- php: '8.4'
77+
- php: '8.5'
7878
wp: 'trunk'
7979
experimental: true
8080

@@ -137,11 +137,6 @@ jobs:
137137
with:
138138
composer-options: '--prefer-dist --no-progress --no-interaction --no-scripts'
139139

140-
- name: Update PHPUnit
141-
run: |
142-
echo "Installing latest version of PHPUnit"
143-
composer update --ignore-platform-reqs --no-interaction --no-scripts yoast/phpunit-polyfills --with-dependencies
144-
145140
- name: Composer dump autoload
146141
run: composer dump-autoload --no-interaction
147142

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@
8787
],
8888
"installer-disable": true,
8989
"patches": {
90+
"humbug/php-scoper": {
91+
"Fix using null as array key": "./patches/humbug-php-scoper-php85.diff"
92+
},
9093
"thecodingmachine/safe": {
9194
"Fix explicit nullable errors": "./patches/thecodingmachine-safe-nullable.diff"
9295
}

composer.lock

Lines changed: 261 additions & 189 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/Admin/Customizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,8 @@ public function get_stories_theme_support(): array {
664664
*
665665
* @since 1.5.0
666666
*
667-
* @param array<string,mixed> $view_type View type to check.
668-
* @return array<string,mixed> An array of view type choices.
667+
* @param array<string,string> $view_type View type to check.
668+
* @return array<string,string> An array of view type choices.
669669
*/
670670
private function get_view_type_choices( array $view_type ): array {
671671
$view_type_choices = $this->stories_script_data->get_layouts();

includes/Admin/Site_Health.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ public function modify_test_result( $test_result ) {
239239
// Set the `https_status` test status to critical if its current status is recommended, along with adding to the
240240
// description for why its required for Web Stories.
241241
if ( isset( $test_result['test'], $test_result['status'], $test_result['description'] ) && 'https_status' === $test_result['test'] && 'recommended' === $test_result['status'] ) {
242-
$test_result['status'] = 'critical';
242+
$test_result['status'] = 'critical';
243+
// @phpstan-ignore assignOp.invalid (False positive.)
243244
$test_result['description'] .= '<p>' . __( 'Additionally, Web Stories requires HTTPS for most components to work properly, including iframes and videos.', 'web-stories' ) . '</p>';
244245
}
245246

includes/Infrastructure/Injector/SimpleInjector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ private function resolve_argument(
364364
$type = $parameter->getType();
365365

366366
// In PHP 8.0, the isBuiltin method was removed from the parent {@see ReflectionType} class.
367+
368+
// @phpstan-ignore identical.alwaysFalse
367369
if ( null === $type || ( $type instanceof ReflectionNamedType && $type->isBuiltin() ) ) {
368370
return $this->resolve_argument_by_name(
369371
$class_name,

includes/Integrations/AMP.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ public static function get_requirements(): array {
137137
*
138138
* @since 1.2.0
139139
*
140-
* @param array|mixed $options Options.
140+
* @param array|false $options Options.
141141
* @return array|mixed Filtered options.
142142
*
143-
* @phpstan-param AMPOptions|mixed $options
143+
* @phpstan-param AMPOptions|false $options
144144
*
145145
* @template T
146146
*
@@ -166,12 +166,10 @@ public function filter_amp_options( $options ) {
166166
*
167167
* @since 1.2.0
168168
*
169-
* @param string[]|mixed $post_types Supportable post types.
170-
* @return array|mixed Supportable post types.
169+
* @param string[]|false $post_types Supportable post types.
170+
* @return string[]|false Supportable post types.
171171
*
172-
* @template T
173-
*
174-
* @phpstan-return ($post_types is array<T> ? array<T> : mixed)
172+
* @phpstan-return ($post_types is string[] ? string[] : false)
175173
*/
176174
public function filter_supportable_post_types( $post_types ) {
177175
if ( ! \is_array( $post_types ) ) {

includes/Integrations/Site_Kit.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ public function filter_site_kit_gtag_opt( $gtag_opt ) {
145145
$default_config['triggers'] = $default_config['triggers'] ?? [];
146146

147147
$gtag_opt['triggers'] ??= [];
148-
$gtag_opt['triggers'] = array_merge( $default_config['triggers'], $gtag_opt['triggers'] );
148+
// @phpstan-ignore argument.type
149+
$gtag_opt['triggers'] = array_merge( $default_config['triggers'], $gtag_opt['triggers'] );
149150

150151
return $gtag_opt;
151152
}

includes/KSES.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public function filter_insert_post_data( $data, $postarr, $unsanitized_postarr )
137137

138138
if (
139139
! \is_string( $data['post_type'] ) ||
140+
// @phpstan-ignore argument.type
140141
! $this->is_allowed_post_type( $data['post_type'], $data['post_parent'] )
141142
) {
142143
return $data;
@@ -150,6 +151,7 @@ public function filter_insert_post_data( $data, $postarr, $unsanitized_postarr )
150151
}
151152

152153
if ( isset( $unsanitized_postarr['post_content'] ) ) {
154+
// @phpstan-ignore argument.type
153155
$data['post_content'] = wp_slash( $this->sanitize_content( wp_unslash( $unsanitized_postarr['post_content'] ) ) );
154156
}
155157

includes/Media/Media_Source_Taxonomy.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ public function filter_rest_generated_media_attachments( $args ) {
304304
* @since 1.29.0
305305
*/
306306
private function add_missing_terms(): void {
307-
// @phpstan-ignore function.internal (false positive)
308307
$existing_terms = get_terms(
309308
[
310309
'taxonomy' => $this->get_taxonomy_slug(),

0 commit comments

Comments
 (0)