-
-
Notifications
You must be signed in to change notification settings - Fork 699
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from TomasVotruba/symplify-geter-to-property-r…
…ector Symplify GetterToPropertyRector
- Loading branch information
Showing
16 changed files
with
279 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Rector\NodeAnalyzer; | ||
|
||
use PhpParser\Node\Expr\MethodCall; | ||
use PhpParser\Node\Scalar\String_; | ||
|
||
final class SymfonyContainerCallsAnalyzer | ||
{ | ||
/** | ||
* Finds $this->get(...); | ||
*/ | ||
public function isThisCall(MethodCall $methodCall): bool | ||
{ | ||
if ($methodCall->var->name !== 'this' || (string) $methodCall->name !== 'get') { | ||
return false; | ||
} | ||
|
||
return $this->hasOneStringArgument($methodCall); | ||
} | ||
|
||
/** | ||
* Finds $this->getContainer()->get(...); | ||
*/ | ||
public function isGetContainerCall(MethodCall $methodCall): bool | ||
{ | ||
if (! $methodCall->var instanceof MethodCall) { | ||
return false; | ||
} | ||
|
||
if ((string) $methodCall->var->var->name !== 'this' || (string) $methodCall->name !== 'get') { | ||
return false; | ||
} | ||
|
||
return $this->hasOneStringArgument($methodCall); | ||
} | ||
|
||
/** | ||
* Finds ('some_service') | ||
*/ | ||
private function hasOneStringArgument(MethodCall $methodCall): bool | ||
{ | ||
return count($methodCall->args) === 1 && $methodCall->args[0]->value instanceof String_; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.