rename class is not needed

This commit is contained in:
TomasVotruba 2020-05-28 10:24:35 +02:00
parent 7fb892b9d1
commit de4477b0f9
2 changed files with 20 additions and 4 deletions

View File

@ -1,10 +1,6 @@
# from: https://github.com/Kdyby/Events/
# to: https://github.com/contributte/event-dispatcher/
services:
Rector\Renaming\Rector\Class_\RenameClassRector:
$oldToNewClasses:
Kdyby\Events\Subscriber: 'Symfony\Component\EventDispatcher\EventSubscriberInterface'
Rector\NetteKdyby\Rector\Class_\KdybyEventSubscriberToContributteEventSubscriberRector: null
Rector\NetteKdyby\Rector\MethodCall\ReplaceMagicPropertyEventWithEventClassRector: null
Rector\NetteKdyby\Rector\ClassMethod\ReplaceMagicEventPropertySubscriberWithEventClassSubscriberRector: null

View File

@ -13,6 +13,7 @@ use PhpParser\Node\Arg;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\Cast\String_ as StringCast;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Expr\Variable;
@ -148,6 +149,10 @@ final class CustomEventFactory
return $this->resolveParamNameFromPropertyFetch($value);
}
if ($value instanceof MethodCall) {
return $this->resolveParamNameFromMethodCall($value);
}
if ($value === null) {
throw new NotImplementedException();
}
@ -178,4 +183,19 @@ final class CustomEventFactory
return $varName . ucfirst($propertyName);
}
private function resolveParamNameFromMethodCall(MethodCall $methodCall): string
{
$varName = $this->nodeNameResolver->getName($methodCall->var);
if (! is_string($varName)) {
throw new NotImplementedException();
}
$methodName = $this->nodeNameResolver->getName($methodCall->name);
if (! is_string($methodName)) {
throw new NotImplementedException();
}
return $varName . ucfirst($methodName);
}
}