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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
*/
final class RenameEventNamesInEventSubscriberRector extends AbstractRector
{
/**
* @var string
*/
private const EVENT_SUBSCRIBER_INTERFACE = 'Symfony\Component\EventDispatcher\EventSubscriberInterface';

/**
* @var EventInfo[]
*/
Expand Down Expand Up @@ -87,13 +92,12 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
$classNode = $node->getAttribute(AttributeKey::CLASS_NODE);

if ($classNode === null) {
$class = $node->getAttribute(AttributeKey::CLASS_NODE);
if ($class === null) {
return null;
}

if (! $this->isType($classNode, 'Symfony\Component\EventDispatcher\EventSubscriberInterface')) {
if (! $this->isType($class, self::EVENT_SUBSCRIBER_INTERFACE)) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function refactor(Node $node): ?Node
return null;
}

for ($i = $reflectionFunctionLike->getNumberOfParameters(); $i <= count($node->args); $i++) {
for ($i = $reflectionFunctionLike->getNumberOfParameters(), $iMax = count($node->args); $i <= $iMax; $i++) {
unset($node->args[$i]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Rector\Php\Tests\Rector\FuncCall\RemoveExtraParametersRector\Fixture;

use Rector\Php\Tests\Rector\FuncCall\RemoveExtraParametersRector\Source\MagicEventDispatcher;

final class SkipCommentedParamFuncGetArgs
{
public function run()
{
$magicEventDispatcher = new MagicEventDispatcher();
$magicEventDispatcher->dispatch(1, 2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function test(): void
__DIR__ . '/Fixture/static_calls.php.inc',
__DIR__ . '/Fixture/external_scope.php.inc',
__DIR__ . '/Fixture/static_call_parent.php.inc',
__DIR__ . '/Fixture/skip_commented_param_func_get_args.php.inc',
]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php declare(strict_types=1);

namespace Rector\Php\Tests\Rector\FuncCall\RemoveExtraParametersRector\Source;

use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

final class MagicEventDispatcher
{
/**
* {@inheritdoc}
*
* @param string|null $eventName
*/
public function dispatch($event/*, string $eventName = null*/)
{
$eventName = 1 < \func_num_args() ? \func_get_arg(1) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ namespace Rector\Symfony\Tests\Rector\MethodCall\MakeDispatchFirstArgumentEventR

use Rector\Symfony\Tests\Rector\MethodCall\MakeDispatchFirstArgumentEventRector\Source\CustomEvent;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Contracts\EventDispatcher\Event;

class KeepStringEventConstant
{
public function run(EventDispatcher $eventDispatcher)
{
/** @var Event|CustomEvent $customEvent */
$customEvent = new CustomEvent();
$eventDispatcher->dispatch(CustomEvent::NAME, $customEvent);
$eventDispatcher->dispatch($customEvent, CustomEvent::NAME);
}
}

Expand All @@ -22,13 +25,16 @@ namespace Rector\Symfony\Tests\Rector\MethodCall\MakeDispatchFirstArgumentEventR

use Rector\Symfony\Tests\Rector\MethodCall\MakeDispatchFirstArgumentEventRector\Source\CustomEvent;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Contracts\EventDispatcher\Event;

class KeepStringEventConstant
{
public function run(EventDispatcher $eventDispatcher)
{
/** @var Event|CustomEvent $customEvent */
$customEvent = new CustomEvent();
$eventDispatcher->dispatch($customEvent, CustomEvent::NAME);
$eventDispatcher->dispatch($customEvent, CustomEvent::NAME);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace Rector\Symfony\Tests\Rector\MethodCall\MakeDispatchFirstArgumentEventRector\Source;

use Symfony\Contracts\EventDispatcher\Event;

final class CustomEvent extends Event
final class CustomEvent
{
public const NAME = 'custom_event';
}
2 changes: 1 addition & 1 deletion rector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ parameters:
php_version_features: '7.1'

services:
Rector\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector: ~
# Rector\CodingStyle\Rector\Namespace_\ImportFullyQualifiedNamesRector: ~