Remove isOnClassMethodCall() (#6116)

This commit is contained in:
Tomas Votruba 2021-04-12 22:04:30 +02:00 committed by GitHub
parent 620309c0d7
commit 5dcedbd825
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 17 deletions

View File

@ -7,6 +7,5 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigura
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(RemoveSetTempDirOnExcelWriterRector::class);
};

View File

@ -70,7 +70,11 @@ CODE_SAMPLE
*/
public function refactor(Node $node): ?Node
{
if (! $this->isOnClassMethodCall($node, new ObjectType('Carbon\Carbon'), 'diffForHumans')) {
if (! $this->isObjectType($node->var, new ObjectType('Carbon\Carbon'))) {
return null;
}
if (! $this->isName($node->name, 'diffForHumans')) {
return null;
}

View File

@ -65,7 +65,11 @@ CODE_SAMPLE
*/
public function refactor(Node $node): ?Node
{
if (! $this->isOnClassMethodCall($node, new ObjectType('PHPExcel_Style_Conditional'), 'setCondition')) {
if (! $this->isObjectType($node->var, new ObjectType('PHPExcel_Style_Conditional'))) {
return null;
}
if (! $this->isName($node->name, 'setCondition')) {
return null;
}

View File

@ -63,7 +63,11 @@ CODE_SAMPLE
*/
public function refactor(Node $node): ?Node
{
if (! $this->isOnClassMethodCall($node, new ObjectType('PHPExcel_Worksheet'), 'duplicateStyleArray')) {
if (! $this->isObjectType($node->var, new ObjectType('PHPExcel_Worksheet'))) {
return null;
}
if (! $this->nodeNameResolver->isName($node->name, 'duplicateStyleArray')) {
return null;
}

View File

@ -61,7 +61,11 @@ CODE_SAMPLE
*/
public function refactor(Node $node): ?Node
{
if (! $this->isOnClassMethodCall($node, new ObjectType('PHPExcel_Writer_Excel5'), 'setTempDir')) {
if (! $this->isObjectType($node->var, new ObjectType('PHPExcel_Writer_Excel5'))) {
return null;
}
if (! $this->isName($node->name, 'setTempDir')) {
return null;
}

View File

@ -78,8 +78,7 @@ CODE_SAMPLE
*/
public function refactor(Node $node): ?Node
{
$callerType = $this->getObjectType($node->class);
if (! $callerType->isSuperTypeOf(new ObjectType('PHPExcel_IOFactory'))->yes()) {
if (! $this->isObjectType($node->class, new ObjectType('PHPExcel_IOFactory'))) {
return null;
}

View File

@ -7,7 +7,6 @@ namespace Rector\Core\Rector;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Class_;
@ -412,15 +411,6 @@ abstract class AbstractRector extends NodeVisitorAbstract implements PhpRectorIn
}
}
protected function isOnClassMethodCall(MethodCall $methodCall, ObjectType $objectType, string $methodName): bool
{
if (! $this->isObjectType($methodCall->var, $objectType)) {
return false;
}
return $this->isName($methodCall->name, $methodName);
}
protected function isOpenSourceProjectType(): bool
{
$projectType = $this->parameterProvider->provideStringParameter(Option::PROJECT_TYPE);