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

Backport recognition of return type hints #323

Merged
merged 8 commits into from Feb 16, 2017

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Dec 30, 2016

When reviewing test skip conditions I came across the NewNullableTypes and NewScalarReturnTypeDeclarations which both skipped for PHPCS < 2.4.0 for tests involving return type hints. Turned out this was not that difficult to backport.

  • Adds a new getReturnTypeHintToken() utility function which will be used by both sniffs.
    • Fixes: self and callable not being recognized as T_RETURN_TYPE in PHPCS < 2.6.0
    • Fixes: return types not recognized at all in PHPCS < 2.4.0
  • Implement use of the getReturnTypeHintToken() utility function in both the NewNullableTypes and NewReturnTypeDeclarations sniffs.
  • Removes test skipping on older PHPCS versions for both sniffs.

Additionally, this PR:

  • Renames the NewScalarReturnTypeDeclarations sniff to NewReturnTypeDeclarations.
    Return types didn't exist at all before PHP 7.0, so it wasn't just scalar return types which were introduced in PHP 7.0.
  • Adds the missing return types to the version array & add logic to deal with (namespaced) class name based return type hints in the NewReturnTypeDeclarations sniff.
  • Fixes: the ? of a nullable type hint not being added correctly to the typehint content for array, callable and self in the NewNullableTypes sniff. Fixed in Sync the getMethodParameters() method with the version now merged in PHPCS #326
  • Fixes: namespaced class names as return type hints were not recognized properly in the NewNullableTypes sniff.

Includes additional unit test cases for namespaced class name return hints (both) and for array, callable and self return type hints for the NewReturnTypeDeclarations sniff.


[Edit] I've added one more commit to this PR to allow for an upstream change in the upcoming PHPCS 2.7.2 which introduces a new T_NULLABLE token which was breaking the NewNullableTypes sniff.
Ref: squizlabs/PHP_CodeSniffer#1263
Ref: squizlabs/PHP_CodeSniffer@b2b4b28


[Edit] And another commit... now allowing for type hints in anonymous functions. Including unit tests for the same.

@coveralls
Copy link

coveralls commented Dec 30, 2016

Coverage Status

Coverage increased (+0.1%) to 96.847% when pulling a516bb3 on jrfnl:feature/return-types-back-compat into e1af2c3 on wimg:master.

@coveralls
Copy link

coveralls commented Jan 9, 2017

Coverage Status

Coverage increased (+0.3%) to 96.978% when pulling 3c99656 on jrfnl:feature/return-types-back-compat into e1af2c3 on wimg:master.

@jrfnl jrfnl force-pushed the feature/return-types-back-compat branch from 3c99656 to d7fabf8 Compare January 16, 2017 02:18
@jrfnl
Copy link
Member Author

jrfnl commented Jan 16, 2017

Rebased for merge conflicts

@coveralls
Copy link

coveralls commented Jan 16, 2017

Coverage Status

Coverage increased (+0.1%) to 97.043% when pulling d7fabf8 on jrfnl:feature/return-types-back-compat into 4fa57b3 on wimg:master.

@jrfnl
Copy link
Member Author

jrfnl commented Jan 18, 2017

Eh... what's going on with Travis ? Not being triggered anymore ?

Never mind, apparently it was just slow to trigger.

@coveralls
Copy link

coveralls commented Jan 18, 2017

Coverage Status

Coverage decreased (-2.8%) to 94.099% when pulling 806cd41 on jrfnl:feature/return-types-back-compat into 4fa57b3 on wimg:master.

@jrfnl jrfnl force-pushed the feature/return-types-back-compat branch from 806cd41 to fcbda25 Compare January 18, 2017 10:52
@coveralls
Copy link

coveralls commented Jan 18, 2017

Coverage Status

Coverage increased (+0.1%) to 97.049% when pulling fcbda25 on jrfnl:feature/return-types-back-compat into 4fa57b3 on wimg:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 97.049% when pulling fcbda25 on jrfnl:feature/return-types-back-compat into 4fa57b3 on wimg:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 97.049% when pulling fcbda25 on jrfnl:feature/return-types-back-compat into 4fa57b3 on wimg:master.

@jrfnl jrfnl force-pushed the feature/return-types-back-compat branch from fcbda25 to a7ecf91 Compare January 18, 2017 11:51
@coveralls
Copy link

coveralls commented Jan 18, 2017

Coverage Status

Coverage increased (+0.1%) to 97.049% when pulling a7ecf91 on jrfnl:feature/return-types-back-compat into 4fa57b3 on wimg:master.

@coveralls
Copy link

coveralls commented Jan 20, 2017

Coverage Status

Coverage increased (+0.09%) to 97.018% when pulling 8d01472 on jrfnl:feature/return-types-back-compat into 4fa57b3 on wimg:master.

5 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+0.09%) to 97.018% when pulling 8d01472 on jrfnl:feature/return-types-back-compat into 4fa57b3 on wimg:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.09%) to 97.018% when pulling 8d01472 on jrfnl:feature/return-types-back-compat into 4fa57b3 on wimg:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.09%) to 97.018% when pulling 8d01472 on jrfnl:feature/return-types-back-compat into 4fa57b3 on wimg:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.09%) to 97.018% when pulling 8d01472 on jrfnl:feature/return-types-back-compat into 4fa57b3 on wimg:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.09%) to 97.018% when pulling 8d01472 on jrfnl:feature/return-types-back-compat into 4fa57b3 on wimg:master.

@jrfnl jrfnl force-pushed the feature/return-types-back-compat branch 3 times, most recently from 642716b to 13963f6 Compare January 20, 2017 04:11
@coveralls
Copy link

coveralls commented Jan 20, 2017

Coverage Status

Coverage increased (+0.08%) to 97.005% when pulling 642716b on jrfnl:feature/return-types-back-compat into 4fa57b3 on wimg:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 97.005% when pulling 642716b on jrfnl:feature/return-types-back-compat into 4fa57b3 on wimg:master.

@coveralls
Copy link

coveralls commented Jan 20, 2017

Coverage Status

Coverage increased (+0.08%) to 97.005% when pulling 13963f6 on jrfnl:feature/return-types-back-compat into 4fa57b3 on wimg:master.

This function itself is not unit tested as the sniffs in which it will be used effectively unit test it already.
…rationsSniff

It wasn't just scalar return types which were introduced in PHP 7, return types didn't exist at all before that.
…eTypesSniff`.

Includes extra unit test cases for namespaced classes.
As return type hints didn't exist at all for PHP < 7.0, this sniff should also alert on return type hints for `array`, `callable`, `self` or arbitrary (namespaced) class names.

Includes additional unit tests.
@jrfnl jrfnl force-pushed the feature/return-types-back-compat branch from 13963f6 to c21e981 Compare February 6, 2017 21:51
@jrfnl
Copy link
Member Author

jrfnl commented Feb 6, 2017

Rebased

@coveralls
Copy link

coveralls commented Feb 6, 2017

Coverage Status

Coverage increased (+1.8%) to 97.035% when pulling c21e981 on jrfnl:feature/return-types-back-compat into b169766 on wimg:master.

@wimg wimg merged commit 4015618 into PHPCompatibility:master Feb 16, 2017
@jrfnl jrfnl deleted the feature/return-types-back-compat branch February 17, 2017 22:09
@jrfnl jrfnl added this to the 7.1.2 milestone May 2, 2017
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

3 participants