Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"ondram/ci-detector": "^3.4",
"phpstan/phpdoc-parser": "^0.4.7",
"phpstan/phpstan": "^0.12.25",
"phpstan/phpstan-phpunit": "0.12.8",
"phpstan/phpstan-phpunit": "^0.12.9",
"psr/simple-cache": "^1.0",
"sebastian/diff": "^3.0|^4.0",
"symfony/cache": "^4.4.8|^5.0.6",
Expand Down
12 changes: 5 additions & 7 deletions docs/rector_rules_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -4607,22 +4607,20 @@ Change $this->templates->{magic} to $this->template->render(..., $values)

## NetteKdyby

### `KdybyEventSubscriberToContributteEventSubscriberRector`
### `ChangeNetteEventNamesInGetSubscribedEventsRector`

- class: [`Rector\NetteKdyby\Rector\ClassMethod\KdybyEventSubscriberToContributteEventSubscriberRector`](/../master/rules/nette-kdyby/src/Rector/Class_/KdybyEventSubscriberToContributteEventSubscriberRector.php)
- [test fixtures](/../master/rules/nette-kdyby/tests/Rector/Class_/KdybyEventSubscriberToContributteEventSubscriberRector/Fixture)
- class: [`Rector\NetteKdyby\Rector\ClassMethod\ChangeNetteEventNamesInGetSubscribedEventsRector`](/../master/rules/nette-kdyby/src/Rector/ClassMethod/ChangeNetteEventNamesInGetSubscribedEventsRector.php)
- [test fixtures](/../master/rules/nette-kdyby/tests/Rector/ClassMethod/ChangeNetteEventNamesInGetSubscribedEventsRector/Fixture)

Change EventSubscriber from Kdyby to Contributte

```diff
-use Kdyby\Events\Subscriber;
+use Contributte\Events\Extra\Event\Application\ShutdownEvent;
use Kdyby\Events\Subscriber;
use Nette\Application\Application;
-use Nette\Application\UI\Presenter;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;

-class GetApplesSubscriber implements Subscriber
+class GetApplesSubscriber implements EventSubscriberInterface
class GetApplesSubscriber implements Subscriber
{
- public function getSubscribedEvents()
+ public static function getSubscribedEvents()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Identifier;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractPHPUnitRector;
use Rector\Core\RectorDefinition\CodeSample;
use Rector\Core\RectorDefinition\RectorDefinition;
Expand Down Expand Up @@ -84,7 +85,10 @@ public function refactor(Node $node): ?Node
}

$callerNode = $node instanceof StaticCall ? $node->class : $node->var;
if (! $this->isObjectType($callerNode, 'PHPUnit\Framework\MockObject\Builder\InvocationMocker')) {

$callerNodeStaticType = $this->getStaticType($callerNode);

if (! $callerNodeStaticType->isSuperTypeOf(new ObjectType('PHPUnit\Framework\MockObject\MockObject'))->yes()) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

namespace Rector\PHPUnit\Rector\MethodCall;

use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\String_;
use PHPStan\Type\ArrayType;
use PHPUnit\Framework\MockObject\Builder\InvocationMocker;
use PHPStan\Type\Generic\GenericObjectType;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\PhpParser\Node\Manipulator\MethodCallManipulator;
use Rector\Core\Rector\AbstractRector;
Expand Down Expand Up @@ -109,7 +110,7 @@ public function refactor(Node $node): ?Node
}

// is a mock?
if (! $this->isObjectType($node, InvocationMocker::class)) {
if (! $this->isMockType($node)) {
return null;
}

Expand Down Expand Up @@ -217,4 +218,14 @@ private function findRootVariableOfChainCall(MethodCall $methodCall): ?Variable

return $currentMethodCallee;
}

private function isMockType(MethodCall $methodCall): bool
{
$nodeStaticType = $this->getObjectType($methodCall);
if (! $nodeStaticType instanceof GenericObjectType) {
return false;
}

return (bool) Strings::match($nodeStaticType->getClassName(), '#InvocationMocker$#');
}
}