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

NewHeredocInitialize: extend the NewScalarExpressions sniff to cover more cases #641

Merged
merged 2 commits into from Jul 13, 2018

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented May 2, 2018

NewHeredocInitialize: add unit tests for global constants, multi-declarations and function param defaults

The PHP 5.3 change regarding initializing something with a heredoc turns out to apply to more than the current sniff was sniffing for (undocumented/based on tests ran).

Add tests for:

  • Global constants declared using the const keyword
    A bit of a mood case as the const keyword was only introduced in PHP 5.3. All the same, the sniff should be accurate and the unit tests should reflect this.
  • Multi-declarations for static variables, constants and class properties
  • Default values for function parameters

NewHeredocInitialize: extend the NewScalarExpressions sniff

The logic within the original NewHeredocInitialize sniff did not allow for multi-declarations nor for examining the default values of function parameters.

While not (well) documented, these features are supported and do allow initialization with heredocs since PHP 5.3.

As the logic to determine whether a token needs to be examined is the same for this sniff and for the new NewScalarExpressions sniff, letting the sniff extend the NewScalarExpressions sniff prevents code duplication.

@jrfnl jrfnl added this to the 8.2.0 milestone May 2, 2018
@jrfnl jrfnl requested a review from wimg May 2, 2018 09:03
@jrfnl jrfnl force-pushed the feature/heredocinit-extend-scalar-expr-sniff branch 2 times, most recently from d59408b to dabd0ca Compare June 11, 2018 00:55
…arations and function param defaults

The PHP 5.3 change regarding initializing something with a heredoc turns out to apply to more than the current sniff was sniffing for.

Add tests for:
* Global constants declared using the `const` keyword
    A bit of a mood case as the `const` keyword was only introduced in PHP 5.3. All the same, the sniff should be accurate and the unit tests should reflect this.
* Multi-declarations for static variables, constants and class properties
* Default values for function parameters
The logic within the original `NewHeredocInitialize` sniff did not allow for multi-declarations nor for examining the default values of function parameters.

While not (well) documented, these features are supported and do allow initialization with heredocs since PHP 5.3.

As the logic to determine whether a token needs to be examined is the same for this sniff and for the new `NewScalarExpressions` sniff, letting the sniff extend the `NewScalarExpressions` sniff prevents code duplication.
@wimg wimg merged commit 76c5deb into master Jul 13, 2018
@wimg wimg deleted the feature/heredocinit-extend-scalar-expr-sniff branch July 13, 2018 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants