Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading PHPStan to 2.0 #412

Merged
merged 4 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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": [
Expand Down
6 changes: 4 additions & 2 deletions src/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -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<int, string> The asset's dependency array.
* @return array<string> The asset's dependency array.
*/
function get_asset_dependency_array( string $dir_entry_name ): array {
$asset_arr = get_entry_asset_map( $dir_entry_name );
Expand Down
21 changes: 16 additions & 5 deletions src/meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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'] );
Expand All @@ -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
);
}
}
Loading