Skip to content

Commit

Permalink
Upgrading PHPStan to 2.0 (#412)
Browse files Browse the repository at this point in the history
* 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] <[email protected]>

* PHPStan fixes

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
srtfisher and dependabot[bot] authored Dec 31, 2024
1 parent c261487 commit 9f18251
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
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
);
}
}

0 comments on commit 9f18251

Please sign in to comment.