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

Bump to Rector 0.9.20 #1961

Merged
merged 14 commits into from
Feb 10, 2021
Merged

Bump to Rector 0.9.20 #1961

merged 14 commits into from
Feb 10, 2021

Conversation

TomasVotruba
Copy link
Contributor

There has been many changes in AbstractRector, like removal of ~15 traits. This was a bad design magic crap choice I made years ago and now was time to face it :)

Another big change is that AbstractRectorTestCase custom methods like setParameter() and getPhpVersion() are moved to config-based approach. This will remove extra magical layer in test and make it easier.

I have it still in my head, so I'll upgrade Rector here to put headaches on you.

Good job with tests, it give me very fast feedback in what is wrong 👍


Pre-step to:
rectorphp/rector#5478 (comment)

},
"require-dev": {
"captainhook/captainhook": "^5.4",
"captainhook/plugin-composer": "^5.2",
"phpunit/phpunit": "^8.0|^9.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

PHPUnit 9 is supporting PHP 7.3+, so PHPUnit 8 can be dropped here

Comment on lines -14 to 24
trait ConnectionCallTrait
final class ConnectionCallFactory
{
/**
* @var NodeFactory
*/
protected $nodeFactory;
private $nodeFactory;

/**
* @required
*/
public function autowireNodeFactoryTrait(NodeFactory $nodeFactory): void
public function __construct(NodeFactory $nodeFactory)
{
$this->nodeFactory = $nodeFactory;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Traits depend on magical presence of other properties, e.g. here is "hope" for $nodeFactory.
Instead, it's better to use service, that has clear contract and there is no need for hope :)

I know this was used in Rector a lot, so it's only natural to use it in the code that build on Rector. But we're moving away from this in Rector, so code is cleaner and easier to maintain.

Copy link
Owner

Choose a reason for hiding this comment

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

@TomasVotruba Yes, i am not a big fan of traits either. So cool, Rector is moving away from it.

Comment on lines -33 to 36
if (! $this->isMethodStaticCallOrClassMethodObjectType($node, SysNoteRepository::class)) {
if (! $this->nodeTypeResolver->isMethodStaticCallOrClassMethodObjectType($node, SysNoteRepository::class)) {
return null;
}
if (! $this->isName($node->name, 'findByPidsAndAuthor')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a typical example of where AbstractRector is heading. There will be less and less global methods accessible everywhere, and more focus on specific services that handles the call.

There method will be probably kept even in the future, as they're very practical for every rule:

  • getName()
  • isName()
  • getStaticType()
  • etc

$parentNode = $node->getAttribute('parent');
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Strings attribute can typoed, eg. parnet (been there :)) and are hard to detect.
With constants, there is a future proof that even if the string names changes, the constant will still work.

Copy link
Owner

Choose a reason for hiding this comment

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

@TomasVotruba Most of the time i did it right. But sometimes the evenings were so long. You know ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know, same here :)

That's why I've delegated this task to PHPStan:

services:
    # require constant in argument position
    -
        class: Symplify\PHPStanRules\Rules\RequireMethodCallArgumentConstantRule
        tags: [phpstan.rules.rule]
        arguments:
            constantArgByMethodByType:
                PhpParser\Node:
                    getAttribute: [0]
                    hasAttribute: [0]
                    setAttribute: [0]

He will tell me if something is wrong 👍

Comment on lines 5 to 9
if (TYPO3_MODE === 'BE') {
// must be defined
$_EXTKEY = '___';

/**
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test files are autoloaded, so any missing variable will be reported as fatal error (PHP 8 here :))

This little line will make sure the code is valid.

Another practise we use in Rector core is to wrap code to a class and method run by default.
Code works, is autoloaded but is not run.

@sabbelasichon
Copy link
Owner

@TomasVotruba If you like i can takeover and try to fix the things by myself and ask questions if you like. Saves you some valuable time. What do you think?

@TomasVotruba
Copy link
Contributor Author

Thank you! That would be great :) I've just finished what I guessed.

There is one test case excluded, because of bug in Rector. It's in next 0.9.21 release, but I'd like to finish this first, as there is more changes for `AbstractCommunityTestCase.

@TomasVotruba
Copy link
Contributor Author

It's yours 👍

@TomasVotruba
Copy link
Contributor Author

Let me know if you need to explain anything in more detail.

Break for lunch now 🥘

@TomasVotruba
Copy link
Contributor Author

Looks ready to merge 👍

@sabbelasichon
Copy link
Owner

@TomasVotruba Thanks a lot men. Looks good to me. I think it is ok to have somehow more boilerplate but keep the internals more clean. Thanks for keeping us always up to date.

@sabbelasichon sabbelasichon merged commit c7eb16c into sabbelasichon:master Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants