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

chore: implement stricter PHPStan ruleset and fix new errors. #213

Merged
merged 4 commits into from
Mar 27, 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
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' );
Loading