Skip to content

Commit

Permalink
chore: implement stricter PHPStan ruleset and fix new errors. (#213)
Browse files Browse the repository at this point in the history
* chore: stricter PHPStan ruleset

* fix: DiDom\Document::loadHtml() casing

* fix: remove `null` from return type when value is impossible

* chore: update changeset
  • Loading branch information
justlevine authored Mar 27, 2024
1 parent 05b21b5 commit 43791db
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/wild-hairs-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wpengine/wp-graphql-content-blocks": patch
---

chore: update PHPStan ruleset for stricter linting, and address newly-discovered tech debt.
12 changes: 6 additions & 6 deletions includes/Utilities/DomHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 . ']';
}
Expand Down Expand Up @@ -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 : '';

Expand All @@ -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 = '';
Expand All @@ -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 ) {
Expand Down
14 changes: 13 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion phpstan/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );

0 comments on commit 43791db

Please sign in to comment.