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

ReturnNeverTypeRector: use @return never for php7.x support #296

Merged
merged 22 commits into from
Jun 29, 2021

Conversation

clxmstaab
Copy link
Contributor

@clxmstaab clxmstaab commented Jun 25, 2021

this PR changes the ReturnNeverTypeRector to use @return never which can safely be used on php7.x

as discussed in rectorphp/rector#6283 (comment)

@clxmstaab
Copy link
Contributor Author

@TomasVotruba this should be good to go

@clxmstaab clxmstaab marked this pull request as ready for review June 25, 2021 14:56
Comment on lines +52 to 62
/**
* @return never
*/
public function run()
{
throw new InvalidException();
}
Copy link
Member

Choose a reason for hiding this comment

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

This one has lover priority, code samples should promote the highest PHP availble, if they're using native PHP feature. E.g. TypedPropertyRector uses native types, even though @var is possible too. But that was not the reason for making the rule. The original "why" should be respected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

E.g. TypedPropertyRector uses native types, even though @var is possible too. But that was not the reason for making the rule. The original "why" should be respected

so you mean when running this rector on php8 it should add :never but when running on php7.x it should add @return never, right?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, the PHP version is configurable in config for the test case

@staabm
Copy link
Contributor

staabm commented Jun 26, 2021

rebased and green, which meens #306 fixed the underlying problem we saw initially. 👍

going back to the open issue:

This one has lover priority, code samples should promote the highest PHP availble, if they're using native PHP feature. E.g. TypedPropertyRector uses native types, even though @var is possible too. But that was not the reason for making the rule. The original "why" should be respected

is there another rector which I can take inspiration from, on how to separate the test-fixtures by php version?

@TomasVotruba
Copy link
Member

is there another rector which I can take inspiration from, on how to separate the test-fixtures by php version?

Yes, look for files PHP<version>Test.php

@clxmstaab clxmstaab marked this pull request as draft June 28, 2021 09:58
@TomasVotruba TomasVotruba marked this pull request as ready for review June 28, 2021 10:08
@staabm
Copy link
Contributor

staabm commented Jun 28, 2021

just separated the PHP7.2 tests from the PHP8.1+ tests.

two remaining problems:

  • we get some unrelated NodeRepository errors, which are unrelated to this PR (I guess this is related to latest changes on the main branch)
  • I can see a single error locally, which doesn't reproduce in CI (and I don't know how to fix it):
$ vendor/bin/phpunit rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnNeverTypeRector/ReturnNeverTypeRectorTest.php
PHPUnit 9.5.6 by Sebastian Bergmann and contributors.

.......F.                                                           9 / 9 (100%)

Time: 00:02.602, Memory: 68.00 MB

There was 1 failure:

1) Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector\ReturnNeverTypeRectorTest::test with data set #5 (Symplify\SmartFileSystem\SmartFileInfo Object (...))
rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnNeverTypeRector/Fixture/skip_parent_protected.php.inc
Failed asserting that string matches format description.
--- Expected
+++ Actual
@@ @@

 final class SkipParentProtected implements SomeInterfaceWithReturnType
 {
-    public function run()
+    public function run(): never
     {
         throw new ShouldNotHappenException();
     }

C:\dvl\GitHub\rector-src-staabm\packages\Testing\PHPUnit\AbstractRectorTestCase.php:130
C:\dvl\GitHub\rector-src-staabm\packages\Testing\PHPUnit\AbstractRectorTestCase.php:92
C:\dvl\GitHub\rector-src-staabm\rules-tests\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector\ReturnNeverTypeRectorTest.php:18

FAILURES!
Tests: 9, Assertions: 19, Failures: 1.

feedback welcome

/**
* @param ClassMethod|Function_ $node
*/
private function shouldSkip($node):bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

extracted a shouldSkip() to reduce refactor() complexity

@clxmstaab
Copy link
Contributor Author

@TomasVotruba all green now after rebase ƪ(˘⌣˘)ʃ

@TomasVotruba
Copy link
Member

Thank you, looks good 🙂 👍

@TomasVotruba TomasVotruba merged commit 75c7757 into rectorphp:main Jun 29, 2021
@clxmstaab clxmstaab deleted the return-never branch June 29, 2021 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants