| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
…ndNotBoolean for tests
|
The one last PHPStan error remaining is empty.notAllowed. There are 60 instances of this. |
Sorry, something went wrong.
| identifier: cast.string | ||
| path: */tests/* | ||
| - | ||
| identifier: staticMethod.dynamicCall |
There was a problem hiding this comment.
I'm not sure why this issue is being reported for assertion method calls in tests.
Sorry, something went wrong.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. Co-authored-by: westonruter <westonruter@git.wordpress.org> Co-authored-by: joemcgill <joemcgill@git.wordpress.org> Co-authored-by: swissspidy <swissspidy@git.wordpress.org> Co-authored-by: mukeshpanchal27 <mukesh27@git.wordpress.org> To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Sorry, something went wrong.
There was a problem hiding this comment.
This looks good to me. I've added some suggestions, but none blocking so I'm pre-approving. Feel free to apply or ignore.
Sorry, something went wrong.
| add_action( 'wp_footer', 'embed_optimizer_lazy_load_scripts' ); | ||
| if ( $html_processor->seek( 'script' ) ) { | ||
| if ( $html_processor->get_attribute( 'type' ) ) { | ||
| if ( is_string( $html_processor->get_attribute( 'type' ) ) ) { |
There was a problem hiding this comment.
Same as above.
| if ( is_string( $html_processor->get_attribute( 'type' ) ) ) { | |
| if ( null !== $html_processor->get_attribute( 'type' ) ) ) { |
Sorry, something went wrong.
There was a problem hiding this comment.
In this case, I think the code should stay as-is. Since get_attribute can return true in the case of a boolean attribute, we wouldn't want to try passing a true to set_attrbute(). I believe PHPStan would complain about that anyway.
Sorry, something went wrong.
| } | ||
| $href = $p->get_attribute( 'href' ); | ||
| if ( $href && is_string( $href ) ) { | ||
| if ( is_string( $href ) && '' !== $href ) { |
There was a problem hiding this comment.
I could go either way here, but for consistency...
| if ( is_string( $href ) && '' !== $href ) { | |
| if ( null !== $href && '' !== $href ) { |
Sorry, something went wrong.
There was a problem hiding this comment.
This should stay as is because if <a href> is encountered, then $href here would be true which would be a type error since the function returns a string or null.
Sorry, something went wrong.
| } | ||
|
|
||
| if ( did_action( 'perflab_server_timing_send_header' ) && ! doing_action( 'perflab_server_timing_send_header' ) ) { | ||
| if ( 0 !== did_action( 'perflab_server_timing_send_header' ) && ! doing_action( 'perflab_server_timing_send_header' ) ) { |
There was a problem hiding this comment.
This is such a common pattern in WP that I wouldn't even think of needing to specify, but makes sense.
Sorry, something went wrong.
| if ( '' === $resource_url ) { | ||
| return ''; |
There was a problem hiding this comment.
Could just return the value early in this case.
| if ( '' === $resource_url ) { | |
| return ''; | |
| if ( '' === $resource_url ) { | |
| return $resource_url; |
Sorry, something went wrong.
Co-authored-by: Joe McGill <801097+joemcgill@users.noreply.github.com>
There was a problem hiding this comment.
LGTM, pending the merge conflict resolution
Sorry, something went wrong.
… add/phpstan-strict-rules * 'trunk' of https://github.com/WordPress/performance: (206 commits) fix(webp-uploads): prevent picture element when JPEG output disabled Prepare 0.4.1 release of Optimization Detective Update attribute order in Image Prioritizer test after eliminating excessive seek() calls Account for visitors calling next_token() not just seek() Update attribute order in embed-optimizer test due to not seeking Add test to ensure tag visitation does not exceed seek limit Fix attribute order in tests now that seeking is not happening Add missing bookmark name to warning message Only seek back to the current tag if a tag visitor seeked Migrate commander for v12 Upgrade commander to 12.1.0 Bump yoast/phpunit-polyfills from 1.1.1 to 2.0.1 Bump @wordpress/scripts from 26.19.0 to 28.3.0 Bump @wordpress/env from 9.6.0 to 10.3.0 Migrate husky Update Octokit to use dynamic import Bump husky from 8.0.3 to 9.1.0 Add labels for Dependabot PRs Bump web-vitals from 3.5.0 to 4.2.1 Bump phpstan/extension-installer from 1.3.1 to 1.4.1 ...
… add/phpstan-strict-rules * 'trunk' of https://github.com/WordPress/performance: Fix OD test case for WP 6.7-alpha
| if ( | ||
| ! is_string( $class_name ) | ||
| || | ||
| 1 !== preg_match( '/(?:^|\s)wp-image-([1-9]\d*)(?:\s|$)/i', $class_name, $matches ) |
There was a problem hiding this comment.
| 1 !== preg_match( '/(?:^|\s)wp-image-([1-9]\d*)(?:\s|$)/i', $class_name, $matches ) | |
| 1 !== (int) preg_match( '/(?:^|\s)wp-image-([1-9]\d*)(?:\s|$)/i', $class_name, $matches ) |
Do we needs to cast int here?
Sorry, something went wrong.
There was a problem hiding this comment.
No, because it can either be an int or false, and we're checking to see if it is not identical to the value.
Sorry, something went wrong.
| // This content does not have any tag on it, move forward. | ||
| // TODO: Eventually this should use the HTML API to parse out the image tags and then update them. | ||
| if ( ! preg_match_all( '/<(img)\s[^>]+>/', $content, $img_tags, PREG_SET_ORDER ) ) { | ||
| if ( 0 === (int) preg_match_all( '/<(img)\s[^>]+>/', $content, $img_tags, PREG_SET_ORDER ) ) { |
There was a problem hiding this comment.
The use of (int) isn't needed here either...
Sorry, something went wrong.
There was a problem hiding this comment.
Well, actually it is. Because it's preg_match_all() so we don't know the number of image tags being matched. Otherwise, it could be 1 === .... So by casting the return value to (int), it will convert both 0 and false to 0. Alternatively, this could be:
| if ( 0 === (int) preg_match_all( '/<(img)\s[^>]+>/', $content, $img_tags, PREG_SET_ORDER ) ) { | |
| if ( false === (bool) preg_match_all( '/<(img)\s[^>]+>/', $content, $img_tags, PREG_SET_ORDER ) ) { |
But false indicates the error state. The integer return value is the normal case, the number of matches.
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks @westonruter, LGTM!
Sorry, something went wrong.
|
@westonruter Could you please merge as it not allow me. Shows that Merging can be performed automatically with 1 approving review. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Part of #1219
See #775
Note: This does not fix the empty.notAllowed issues since they are more complicated and deserve a separate PR.
Just adding phpstan-strict-rules results in the following 863 errors in the codebase:
712 staticMethod.dynamicCall 60 empty.notAllowed 36 booleanNot.exprNotBoolean 21 if.condNotBoolean 11 booleanAnd.leftNotBoolean 5 cast.useless 4 booleanOr.rightNotBoolean 4 arrayFilter.strict 3 method.childReturnType 2 ternary.condNotBoolean 2 booleanAnd.rightNotBoolean 1 variable.implicitArray 1 plus.leftNonNumeric 1 elseif.condNotBooleanThis report was generated via:
When ignoring staticMethod.dynamicCall, booleanNot.exprNotBoolean, and if.condNotBoolean in tests, this goes down to just 144 errors:
60 empty.notAllowed 34 booleanNot.exprNotBoolean 16 if.condNotBoolean 11 booleanAnd.leftNotBoolean 5 cast.useless 4 booleanOr.rightNotBoolean 4 arrayFilter.strict 3 method.childReturnType 2 ternary.condNotBoolean 2 booleanAnd.rightNotBoolean 1 variable.implicitArray 1 plus.leftNonNumeric 1 elseif.condNotBooleanThe following remain to be addressed: