Skip to content

Commit 9f18251

Browse files
Upgrading PHPStan to 2.0 (#412)
* Update szepeviktor/phpstan-wordpress requirement from ^1.1 to ^2.0 Updates the requirements on [szepeviktor/phpstan-wordpress](https://github.com/szepeviktor/phpstan-wordpress) to permit the latest version. - [Release notes](https://github.com/szepeviktor/phpstan-wordpress/releases) - [Commits](szepeviktor/phpstan-wordpress@v1.1.0...v2.0.1) --- updated-dependencies: - dependency-name: szepeviktor/phpstan-wordpress dependency-type: direct:development ... Signed-off-by: dependabot[bot] <support@github.com> * PHPStan fixes --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent c261487 commit 9f18251

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

composer.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"require-dev": {
2323
"alleyinteractive/alley-coding-standards": "^2.0",
2424
"mantle-framework/testkit": "^1.0",
25-
"szepeviktor/phpstan-wordpress": "^1.1"
25+
"szepeviktor/phpstan-wordpress": "^2.0"
2626
},
2727
"config": {
2828
"allow-plugins": {
@@ -50,6 +50,13 @@
5050
"phpcbf": "phpcbf .",
5151
"phpcs": "phpcs .",
5252
"phpstan": "phpstan --memory-limit=512M",
53+
"lint": [
54+
"@phpcs",
55+
"@phpstan"
56+
],
57+
"lint:fix": [
58+
"@phpcbf"
59+
],
5360
"phpunit": "phpunit",
5461
"release": "npx @alleyinteractive/create-release@latest",
5562
"test": [

src/assets.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ function get_entry_asset_map( string $dir_entry_name ): array {
5757
$asset_file_path = trailingslashit( $base_path ) . 'index.asset.php';
5858

5959
if ( validate_path( $asset_file_path ) ) {
60-
return include $asset_file_path; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.IncludingFile, WordPressVIPMinimum.Files.IncludingFile.UsingVariable
60+
$asset_map = include $asset_file_path; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.IncludingFile, WordPressVIPMinimum.Files.IncludingFile.UsingVariable
61+
62+
return is_array( $asset_map ) ? $asset_map : []; // @phpstan-ignore-line returns array
6163
}
6264
}
6365

@@ -69,7 +71,7 @@ function get_entry_asset_map( string $dir_entry_name ): array {
6971
*
7072
* @param string $dir_entry_name The entry point directory name.
7173
*
72-
* @return array<int, string> The asset's dependency array.
74+
* @return array<string> The asset's dependency array.
7375
*/
7476
function get_asset_dependency_array( string $dir_entry_name ): array {
7577
$asset_arr = get_entry_asset_map( $dir_entry_name );

src/meta.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function register_meta_helper(
9595
'all' === $object_slugs
9696
)
9797
) {
98-
return register_meta( $object_type, $meta_key, $args );
98+
return register_meta( $object_type, $meta_key, $args ); // @phpstan-ignore-line array given
9999
}
100100

101101
// Fix potential errors since we're allowing `$object_slugs` to be a string or array.
@@ -107,14 +107,14 @@ function register_meta_helper(
107107
switch ( $object_type ) {
108108
case 'post':
109109
foreach ( $object_slugs as $object_slug ) {
110-
if ( ! register_post_meta( $object_slug, $meta_key, $args ) ) {
110+
if ( ! register_post_meta( $object_slug, $meta_key, $args ) ) { // @phpstan-ignore-line array given
111111
return false;
112112
}
113113
}
114114
break;
115115
case 'term':
116116
foreach ( $object_slugs as $object_slug ) {
117-
if ( ! register_term_meta( $object_slug, $meta_key, $args ) ) {
117+
if ( ! register_term_meta( $object_slug, $meta_key, $args ) ) { // @phpstan-ignore-line array given
118118
return false;
119119
}
120120
}
@@ -146,13 +146,24 @@ function register_post_meta_from_defs(): void {
146146

147147
// Loop through definitions and register each.
148148
foreach ( $definitions as $meta_key => $definition ) {
149+
if ( ! is_array( $definition ) ) {
150+
_doing_it_wrong( __FUNCTION__, 'Post meta definition items must be an array.', '1.0.0' );
151+
152+
continue;
153+
}
154+
149155
// Extract post types.
150156
$post_types = $definition['post_types'] ?? [];
157+
151158
// Unset since $definition is passed as register_meta args.
152159
unset( $definition['post_types'] );
153160

154161
// Relocate schema, if specified at the top level.
155162
if ( ! empty( $definition['schema'] ) ) {
163+
if ( ! isset( $definition['show_in_rest'] ) || ! is_array( $definition['show_in_rest'] ) ) {
164+
$definition['show_in_rest'] = [];
165+
}
166+
156167
$definition['show_in_rest']['schema'] = $definition['schema'];
157168
// Unset since $definition is passed as register_meta args.
158169
unset( $definition['schema'] );
@@ -161,9 +172,9 @@ function register_post_meta_from_defs(): void {
161172
// Register the meta.
162173
register_meta_helper(
163174
'post',
164-
$post_types,
175+
$post_types, // @phpstan-ignore-line array given
165176
$meta_key,
166-
$definition
177+
$definition, // @phpstan-ignore-line array given
167178
);
168179
}
169180
}

0 commit comments

Comments
 (0)