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

[Transform] Adds ArrayDimFetchToMethodCallRector rule #5723

Merged
merged 2 commits into from
Mar 15, 2024

Conversation

peterfox
Copy link
Contributor

Changes

  • Adds the new rule.
  • Adds a value object to be used as a configuration option for the rule.
  • Adds tests.
  • Updates the docs.

Why

In Laravel there's a few classes that use ArrayAccess to grab from the service container or config keys but it's not an overly popular way to do things anymore. This rule will be helpful to a few people I think who want to replace ArrayAccess implementing classes to use a specific method instead.

-$app['someService'];
+$app->make('someService');

@peterfox peterfox requested a review from staabm March 15, 2024 18:32
@peterfox peterfox changed the title Adds ArrayDimFetchToMethodCallRector rule [Transform] Adds ArrayDimFetchToMethodCallRector rule Mar 15, 2024
@TomasVotruba
Copy link
Member

Looks good 👍 Thanks 🥳

@TomasVotruba TomasVotruba merged commit cdde425 into rectorphp:main Mar 15, 2024
39 checks passed
@peterfox peterfox deleted the feature/array-access-to-method branch March 15, 2024 19:38
}

foreach ($this->arrayDimFetchToMethodCalls as $arrayDimFetchToMethodCall) {
if (! $node->dim instanceof Node) {
Copy link
Member

Choose a reason for hiding this comment

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

This check should be outside the loop, as return null early

}

if (! $this->isObjectType($node->var, new ObjectType($arrayDimFetchToMethodCall->getClass()))) {
return null;
Copy link
Member

Choose a reason for hiding this comment

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

this should continue to next loop of configurable config instead of return null

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.

4 participants