From eb92a5265d5f8f899040feff1125b798219f126d Mon Sep 17 00:00:00 2001 From: Dovid Levine Date: Sat, 6 Apr 2024 16:24:50 +0300 Subject: [PATCH] chore: implement strict phpstan rules and fix (#66) * chore: implement strict phpstan rules and fix * fix: param conflict --- CHANGELOG.md | 3 ++- access-functions.php | 2 +- phpstan.neon.dist | 15 ++++++++++++++- src/Registry/FacetRegistry.php | 28 ++++++++++++++-------------- src/Type/Enum/SortOptionsEnum.php | 2 +- src/Type/WPInterface/FacetConfig.php | 2 +- vendor/composer/installed.php | 4 ++-- wp-graphql-facetwp.php | 2 +- 8 files changed, 36 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8352a80..7e6dfbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,10 @@ ## Unreleased +- chore: Implement strict phpstan rules and lint. - chore: Update Composer dependencies and lint. - ci: Test against WP 6.5. -- ci: update GitHub Workflows. +- ci: Update GitHub Workflows. ## v0.4.4 diff --git a/access-functions.php b/access-functions.php index c636cd0..2103b9e 100644 --- a/access-functions.php +++ b/access-functions.php @@ -38,7 +38,7 @@ static function () use ( $type_name ) { /** * Get the facets that are allowed to be queried via GraphQL. * - * @return array + * @return array * * @since 0.4.1 */ diff --git a/phpstan.neon.dist b/phpstan.neon.dist index f0bc4ab..2afd2d8 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,7 +1,20 @@ parameters: level: 8 + checkAlwaysTrueCheckTypeFunctionCall: true + checkAlwaysTrueInstanceof: true + checkAlwaysTrueStrictComparison: true + checkExplicitMixedMissingReturn: true + checkFunctionNameCase: true + checkInternalClassCaseSensitivity: true + checkMissingIterableValueType: true + checkTooWideReturnTypesInProtectedAndPublicMethods: true inferPrivatePropertyTypeFromConstructor: true - checkMissingIterableValueType: false + polluteScopeWithAlwaysIterableForeach: false + polluteScopeWithLoopInitialAssignments: false + reportAlwaysTrueInLastCondition: true + reportStaticMethodSignatures: true + reportWrongPhpDocTypeInVarTag: true + treatPhpDocTypesAsCertain: false featureToggles: disableRuntimeReflectionProvider: true stubFiles: diff --git a/src/Registry/FacetRegistry.php b/src/Registry/FacetRegistry.php index c460524..17f41c4 100644 --- a/src/Registry/FacetRegistry.php +++ b/src/Registry/FacetRegistry.php @@ -20,14 +20,14 @@ class FacetRegistry { /** * The facet configs to register to WPGraphQL * - * @var ?array + * @var ?array[] */ protected static $facets; /** * Gets the facet configs to be registered to WPGraphQL. * - * @return array + * @return array[] * * @since 0.4.1 */ @@ -59,9 +59,9 @@ static function ( $config ) { /** * Gets the GraphQL input type for a facet. * - * @param array $config The facet config. + * @param array $config The facet config. * - * @return string|array The GraphQL input type. + * @return string|array The GraphQL input type. * * @since 0.4.1 */ @@ -162,7 +162,7 @@ public static function register( string $type ): void { /** * Register facet-type root field. * - * @param array $facet_config The config array. + * @param array $facet_config The config array. */ private static function register_root_field( array $facet_config ): void { $type = $facet_config['type']; @@ -289,7 +289,7 @@ static function ( $post_ids ) use ( &$filtered_ids ) { /** * Register input argument types. * - * @param array $facet_config The config array. + * @param array $facet_config The config array. */ private static function register_input_arg_types( array $facet_config ): void { $field = $facet_config['field']; @@ -411,7 +411,7 @@ static function ( $prev, $cur ) { /** * Register custom output types. * - * @param array $facet_config The config array. + * @param array $facet_config The config array. */ private static function register_custom_output_types( array $facet_config ): void { $singular = $facet_config['singular']; @@ -449,7 +449,7 @@ private static function register_custom_output_types( array $facet_config ): voi /** * Register facet-type connection types. * - * @param array $facet_config The config array. + * @param array $facet_config The config array. */ private static function register_facet_connection( array $facet_config ): void { $type = $facet_config['type']; @@ -504,9 +504,9 @@ private static function register_facet_connection( array $facet_config ): void { /** * Parse WPGraphQL query into FacetWP query * - * @param array $query The WPGraphQL query. + * @param array $query The WPGraphQL query. * - * @return array The FacetWP query. + * @return array The FacetWP query. */ private static function parse_query( array $query ): array { // Bail early if no query set. @@ -607,8 +607,8 @@ static function ( $prev, $cur ) use ( $query ) { * * @todo move to helper class. * - * @param string|array $input The string or list of strings to convert. - * @return string|array The converted string or list of strings. + * @param string|array $input The string or list of strings to convert. + * @return string|array The converted string or list of strings. */ private static function to_camel_case( $input ) { if ( is_array( $input ) ) { @@ -693,9 +693,9 @@ public static function use_graphql_pagination(): bool { * * @see \FacetWP_Facet_Sort::parse_sort_facet() * - * @param array $facet The facet configuration. + * @param array $facet The facet configuration. * - * @return array> The parsed sort options. + * @return array> The parsed sort options. */ private static function parse_sort_facet_options( array $facet ): array { $sort_options = []; diff --git a/src/Type/Enum/SortOptionsEnum.php b/src/Type/Enum/SortOptionsEnum.php index 333e351..e492085 100644 --- a/src/Type/Enum/SortOptionsEnum.php +++ b/src/Type/Enum/SortOptionsEnum.php @@ -45,7 +45,7 @@ static function ( $facet ) { /** * Registers the enum type for the provided facet. * - * @param array $facet The facet to register the enum type for. + * @param array $facet The facet to register the enum type for. */ public static function register_enum( array $facet ): string { $name = self::get_type_name( $facet['name'] ); diff --git a/src/Type/WPInterface/FacetConfig.php b/src/Type/WPInterface/FacetConfig.php index 240c0a9..16e3667 100644 --- a/src/Type/WPInterface/FacetConfig.php +++ b/src/Type/WPInterface/FacetConfig.php @@ -66,7 +66,7 @@ public static function get_fields(): array { /** * {@inheritDoc} * - * @param array $value The value. + * @param array $value The value. */ public static function get_resolved_type_name( $value ): ?string { return graphql_format_type_name( $value['type'] ) . 'Facet'; diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 379141f..beaefa5 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => 'hsimah-services/wp-graphql-facetwp', 'pretty_version' => 'dev-develop', 'version' => 'dev-develop', - 'reference' => '6b912ce060b68ed4c8b1c31c882cf70f099e912f', + 'reference' => 'c35bbe72d12734aac2a052bd0623d8e3fd12d444', 'type' => 'wordpress-plugin', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -22,7 +22,7 @@ 'hsimah-services/wp-graphql-facetwp' => array( 'pretty_version' => 'dev-develop', 'version' => 'dev-develop', - 'reference' => '6b912ce060b68ed4c8b1c31c882cf70f099e912f', + 'reference' => 'c35bbe72d12734aac2a052bd0623d8e3fd12d444', 'type' => 'wordpress-plugin', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), diff --git a/wp-graphql-facetwp.php b/wp-graphql-facetwp.php index b99e760..a9c1cc6 100644 --- a/wp-graphql-facetwp.php +++ b/wp-graphql-facetwp.php @@ -68,7 +68,7 @@ function graphql_facetwp_constants(): void { /** * Checks if all the the required plugins are installed and activated. * - * @return array The list of missing dependencies. + * @return array The list of missing dependencies. */ function graphql_facetwp_deps_not_ready(): array { $wpgraphql_version = '1.6.0';