diff --git a/composer.json b/composer.json index df823125..3fe11081 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": { @@ -50,6 +50,13 @@ "phpcbf": "phpcbf .", "phpcs": "phpcs .", "phpstan": "phpstan --memory-limit=512M", + "lint": [ + "@phpcs", + "@phpstan" + ], + "lint:fix": [ + "@phpcbf" + ], "phpunit": "phpunit", "release": "npx @alleyinteractive/create-release@latest", "test": [ 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 ); } }