diff --git a/.changeset/wild-hairs-jog.md b/.changeset/wild-hairs-jog.md new file mode 100644 index 00000000..417a9aea --- /dev/null +++ b/.changeset/wild-hairs-jog.md @@ -0,0 +1,5 @@ +--- +"@wpengine/wp-graphql-content-blocks": patch +--- + +chore: update PHPStan ruleset for stricter linting, and address newly-discovered tech debt. diff --git a/includes/Utilities/DomHelpers.php b/includes/Utilities/DomHelpers.php index 8eda5e55..8a4c8473 100644 --- a/includes/Utilities/DomHelpers.php +++ b/includes/Utilities/DomHelpers.php @@ -25,7 +25,7 @@ final class DOMHelpers { */ public static function parseAttribute( $html, $selector, $attribute, $default_value = null ): ?string { $doc = new Document(); - $doc->loadHTML( $html ); + $doc->loadHtml( $html ); if ( '*' === $selector ) { $selector = '*[' . $attribute . ']'; } @@ -71,11 +71,11 @@ public static function parseFirstNodeAttribute( $html, $attribute ) { * @param string $selector The selector to use. * @param mixed $default_value The default value to return if the selector is not found. * - * @return string|null extracted innerHTML of selector + * @return string extracted innerHTML of selector */ public static function parseHTML( $html, $selector, $default_value = null ) { $doc = new Document(); - $doc->loadHTML( $html ); + $doc->loadHtml( $html ); $node = $doc->find( $selector ); $inner_html = isset( $default_value ) ? $default_value : ''; @@ -91,11 +91,11 @@ public static function parseHTML( $html, $selector, $default_value = null ) { * @param string $html The HTML string to parse. * @param string $selector The element (selector) to extract. * - * @return string|null the HTML string of the extracted elements + * @return string the HTML string of the extracted elements */ public static function getElementsFromHTML( $html, $selector ) { $doc = new Document(); - $doc->loadHTML( $html ); + $doc->loadHtml( $html ); $elements = $doc->find( $selector ); $output = ''; @@ -118,7 +118,7 @@ public static function getElementsFromHTML( $html, $selector ) { */ public static function parseText( $html, $selector ) { $doc = new Document(); - $doc->loadHTML( $html ); + $doc->loadHtml( $html ); $nodes = $doc->find( $selector ); if ( count( $nodes ) === 0 ) { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 18a36ee5..5eacf881 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -3,7 +3,19 @@ includes: parameters: level: 8 inferPrivatePropertyTypeFromConstructor: true - checkMissingIterableValueType: false + checkAlwaysTrueCheckTypeFunctionCall: true + checkAlwaysTrueInstanceof: true + checkAlwaysTrueStrictComparison: true + checkExplicitMixedMissingReturn: true + checkFunctionNameCase: true + checkInternalClassCaseSensitivity: true + checkMissingIterableValueType: false # @todo this should be true + checkTooWideReturnTypesInProtectedAndPublicMethods: true + polluteScopeWithAlwaysIterableForeach: false + polluteScopeWithLoopInitialAssignments: false + reportAlwaysTrueInLastCondition: true + reportStaticMethodSignatures: true + reportWrongPhpDocTypeInVarTag: true treatPhpDocTypesAsCertain: false stubFiles: # Simulate added properties diff --git a/phpstan/constants.php b/phpstan/constants.php index 743bdefe..b42b6a91 100644 --- a/phpstan/constants.php +++ b/phpstan/constants.php @@ -6,6 +6,5 @@ */ define( 'WPGRAPHQL_CONTENT_BLOCKS_VERSION', '0.2.1' ); -define( 'WPGRAPHQL_CONTENT_BLOCKS_AUTOLOAD', true ); define( 'WPGRAPHQL_CONTENT_BLOCKS_PLUGIN_FILE', 'wp-graphql-content-blocks.php' ); define( 'WPGRAPHQL_CONTENT_BLOCKS_MIN_PHP_VERSION', '7.4' );