Skip to content

Raise phpstan level from level 3 to level 4 and fixed errors#7096

Merged
westonruter merged 10 commits into
developfrom
tech-debt/4733-raise-phpstan-level
May 18, 2022
Merged

Raise phpstan level from level 3 to level 4 and fixed errors#7096
westonruter merged 10 commits into
developfrom
tech-debt/4733-raise-phpstan-level

Conversation

@dhaval-parekh

@dhaval-parekh dhaval-parekh commented May 11, 2022

Copy link
Copy Markdown
Collaborator

Summary

Fixes #4733

Checklist

  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

Comment thread phpstan.neon.dist Outdated
@dhaval-parekh dhaval-parekh self-assigned this May 11, 2022
@dhaval-parekh dhaval-parekh marked this pull request as ready for review May 11, 2022 14:05
@github-actions

github-actions Bot commented May 11, 2022

Copy link
Copy Markdown
Contributor

Plugin builds for 9301d45 are ready 🛎️!

@westonruter westonruter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to drop a PR comment with each change to show what PHPStan had complained about for each instance? That would help with reviewing. Basically inlining this comment: #4733 (comment).

Comment thread src/Support/SupportData.php Outdated
Comment thread src/PluginSuppression.php Outdated

// Account for case where registered script is a placeholder for a set of scripts (e.g. jquery).
if ( isset( $wp_scripts->registered[ $added_handle ] ) && false === $wp_scripts->registered[ $added_handle ]->src ) {
if ( isset( $wp_scripts->registered[ $added_handle ] ) && empty( $wp_scripts->registered[ $added_handle ]->src ) ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value that core is looking for is specifically false. While empty() will have the same effect, it will also match other falsy values. Is this needed because _WP_Dependency::$src is defined as only being a string?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below message, I'm getting while running the phpstan.

------ ------------------------------------------------------------------------------------- 
  Line   includes/validation/class-amp-validation-callback-wrapper.php                        
 ------ ------------------------------------------------------------------------------------- 
  326    Result of && is always false.                                                        
  326    Strict comparison using === between false and string will always evaluate to false.  
 ------ ------------------------------------------------------------------------------------- 

Yes, As per documentation in core _WP_Dependency::$src have only a string value.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like that's something that WordPress core should fix in its phpdoc as well, but I don't see any downside to using empty() instead of checking for false.

Comment thread includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php
Comment thread includes/amp-helper-functions.php Outdated
Comment thread src/ValidationExemption.php Outdated
Comment thread phpstan.neon.dist Outdated
Comment thread phpstan.neon.dist Outdated
Comment thread phpstan.neon.dist Outdated
Comment thread phpstan.neon.dist Outdated
@dhaval-parekh dhaval-parekh force-pushed the tech-debt/4733-raise-phpstan-level branch from 1e9be9e to d2b95e7 Compare May 13, 2022 08:25
@dhaval-parekh dhaval-parekh requested a review from westonruter May 17, 2022 08:32
Comment thread includes/amp-helper-functions.php Outdated
Comment thread src/PluginSuppression.php Outdated
@dhaval-parekh dhaval-parekh force-pushed the tech-debt/4733-raise-phpstan-level branch from fd098c1 to 9ad7d75 Compare May 18, 2022 08:20
@westonruter westonruter added this to the v2.3 milestone May 18, 2022

@westonruter westonruter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work.

@westonruter westonruter merged commit e311a10 into develop May 18, 2022
@westonruter westonruter deleted the tech-debt/4733-raise-phpstan-level branch May 18, 2022 23:07
@westonruter westonruter added the Changelogged Whether the issue/PR has been added to release notes. label Jun 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelogged Whether the issue/PR has been added to release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Raise PHPStan level for the AmpProject\AmpWP package to 4

2 participants