From 75787ced5e7be135cda43d027ef9eff56a23a003 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 21:10:50 +0000 Subject: [PATCH 1/2] 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](https://github.com/szepeviktor/phpstan-wordpress/compare/v1.1.0...v2.0.1) --- updated-dependencies: - dependency-name: szepeviktor/phpstan-wordpress dependency-type: direct:development ... Signed-off-by: dependabot[bot] --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c4c739e0..d061a75e 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "require-dev": { "alleyinteractive/alley-coding-standards": "^2.0", "mantle-framework/testkit": "^1.0", - "szepeviktor/phpstan-wordpress": "^1.1" + "szepeviktor/phpstan-wordpress": "^2.0" }, "config": { "allow-plugins": { From 64d9741c8eb65dc46af9f3a33c50a022dcbfce05 Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Mon, 30 Dec 2024 13:09:52 -0500 Subject: [PATCH 2/2] PHPStan fixes --- composer.json | 7 +++++++ src/assets.php | 6 ++++-- src/meta.php | 21 ++++++++++++++++----- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index d061a75e..703cdb8b 100644 --- a/composer.json +++ b/composer.json @@ -51,6 +51,13 @@ "phpcs": "phpcs .", "phpunit": "phpunit", "phpstan": "phpstan --memory-limit=512M", + "lint": [ + "@phpcs", + "@phpstan" + ], + "lint:fix": [ + "@phpcbf" + ], "test": [ "@phpcs", "@phpstan", diff --git a/src/assets.php b/src/assets.php index e47af0de..57b7a160 100644 --- a/src/assets.php +++ b/src/assets.php @@ -57,7 +57,9 @@ function get_entry_asset_map( string $dir_entry_name ): array { $asset_file_path = trailingslashit( $base_path ) . 'index.asset.php'; if ( validate_path( $asset_file_path ) ) { - return include $asset_file_path; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.IncludingFile, WordPressVIPMinimum.Files.IncludingFile.UsingVariable + $asset_map = include $asset_file_path; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.IncludingFile, WordPressVIPMinimum.Files.IncludingFile.UsingVariable + + return is_array( $asset_map ) ? $asset_map : []; // @phpstan-ignore-line returns array } } @@ -69,7 +71,7 @@ function get_entry_asset_map( string $dir_entry_name ): array { * * @param string $dir_entry_name The entry point directory name. * - * @return array The asset's dependency array. + * @return array The asset's dependency array. */ function get_asset_dependency_array( string $dir_entry_name ): array { $asset_arr = get_entry_asset_map( $dir_entry_name ); diff --git a/src/meta.php b/src/meta.php index 2abf526e..08d9d426 100644 --- a/src/meta.php +++ b/src/meta.php @@ -95,7 +95,7 @@ function register_meta_helper( 'all' === $object_slugs ) ) { - return register_meta( $object_type, $meta_key, $args ); + return register_meta( $object_type, $meta_key, $args ); // @phpstan-ignore-line array given } // Fix potential errors since we're allowing `$object_slugs` to be a string or array. @@ -107,14 +107,14 @@ function register_meta_helper( switch ( $object_type ) { case 'post': foreach ( $object_slugs as $object_slug ) { - if ( ! register_post_meta( $object_slug, $meta_key, $args ) ) { + if ( ! register_post_meta( $object_slug, $meta_key, $args ) ) { // @phpstan-ignore-line array given return false; } } break; case 'term': foreach ( $object_slugs as $object_slug ) { - if ( ! register_term_meta( $object_slug, $meta_key, $args ) ) { + if ( ! register_term_meta( $object_slug, $meta_key, $args ) ) { // @phpstan-ignore-line array given return false; } } @@ -146,13 +146,24 @@ function register_post_meta_from_defs(): void { // Loop through definitions and register each. foreach ( $definitions as $meta_key => $definition ) { + if ( ! is_array( $definition ) ) { + _doing_it_wrong( __FUNCTION__, 'Post meta definition items must be an array.', '1.0.0' ); + + continue; + } + // Extract post types. $post_types = $definition['post_types'] ?? []; + // Unset since $definition is passed as register_meta args. unset( $definition['post_types'] ); // Relocate schema, if specified at the top level. if ( ! empty( $definition['schema'] ) ) { + if ( ! isset( $definition['show_in_rest'] ) || ! is_array( $definition['show_in_rest'] ) ) { + $definition['show_in_rest'] = []; + } + $definition['show_in_rest']['schema'] = $definition['schema']; // Unset since $definition is passed as register_meta args. unset( $definition['schema'] ); @@ -161,9 +172,9 @@ function register_post_meta_from_defs(): void { // Register the meta. register_meta_helper( 'post', - $post_types, + $post_types, // @phpstan-ignore-line array given $meta_key, - $definition + $definition, // @phpstan-ignore-line array given ); } }