Skip to content

Commit

Permalink
Updated Rector to commit 7729427f459ac348983ee18abff6024db59e9b4f
Browse files Browse the repository at this point in the history
rectorphp/rector-src@7729427 Few static error fixes (#6002)
  • Loading branch information
TomasVotruba committed Jun 22, 2024
1 parent 02a1a1a commit 1864849
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 12 deletions.
16 changes: 8 additions & 8 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -1804,12 +1804,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
"reference": "e23a9b57b934e2ecc1c0ef37dab3a980ec11d4d3"
"reference": "221086cac8c304d374becd9cae9a949852a79d9f"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/e23a9b57b934e2ecc1c0ef37dab3a980ec11d4d3",
"reference": "e23a9b57b934e2ecc1c0ef37dab3a980ec11d4d3",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/221086cac8c304d374becd9cae9a949852a79d9f",
"reference": "221086cac8c304d374becd9cae9a949852a79d9f",
"shasum": ""
},
"require": {
Expand All @@ -1833,7 +1833,7 @@
"tomasvotruba\/class-leak": "^0.2",
"tracy\/tracy": "^2.10"
},
"time": "2024-06-20T14:28:00+00:00",
"time": "2024-06-22T02:46:39+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
Expand Down Expand Up @@ -1869,12 +1869,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
"reference": "bc038d9038168c834a21aadbfd91575c0d4f44d6"
"reference": "dc5ce6e9820e37653bba023d6084ed2ae4da0ac4"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/bc038d9038168c834a21aadbfd91575c0d4f44d6",
"reference": "bc038d9038168c834a21aadbfd91575c0d4f44d6",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/dc5ce6e9820e37653bba023d6084ed2ae4da0ac4",
"reference": "dc5ce6e9820e37653bba023d6084ed2ae4da0ac4",
"shasum": ""
},
"require": {
Expand Down Expand Up @@ -1904,7 +1904,7 @@
"tomasvotruba\/class-leak": "^0.2",
"tracy\/tracy": "^2.10"
},
"time": "2024-06-20T16:02:40+00:00",
"time": "2024-06-22T02:07:50+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
Expand Down
2 changes: 1 addition & 1 deletion vendor/composer/installed.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vendor/rector/extension-installer/src/GeneratedConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
final class GeneratedConfig
{
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main c3c91df'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main a16ded4'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main e23a9b5'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main bc038d9'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main c3c91df'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main a16ded4'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 221086c'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main dc5ce6e'));
private function __construct()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class AssertCompareToSpecificMethodRector extends AbstractRector
public function __construct(TestsNodeAnalyzer $testsNodeAnalyzer)
{
$this->testsNodeAnalyzer = $testsNodeAnalyzer;
$this->functionNamesWithAssertMethods = [new FunctionNameWithAssertMethods('count', self::ASSERT_COUNT, self::ASSERT_NOT_COUNT), new FunctionNameWithAssertMethods('sizeof', self::ASSERT_COUNT, self::ASSERT_NOT_COUNT), new FunctionNameWithAssertMethods('iterator_count', self::ASSERT_COUNT, self::ASSERT_NOT_COUNT), new FunctionNameWithAssertMethods('gettype', 'assertInternalType', 'assertNotInternalType'), new FunctionNameWithAssertMethods('get_class', 'assertInstanceOf', 'assertNotInstanceOf')];
$this->functionNamesWithAssertMethods = [new FunctionNameWithAssertMethods('count', self::ASSERT_COUNT, self::ASSERT_NOT_COUNT), new FunctionNameWithAssertMethods('sizeof', self::ASSERT_COUNT, self::ASSERT_NOT_COUNT), new FunctionNameWithAssertMethods('iterator_count', self::ASSERT_COUNT, self::ASSERT_NOT_COUNT), new FunctionNameWithAssertMethods('get_class', 'assertInstanceOf', 'assertNotInstanceOf')];
}
public function getRuleDefinition() : RuleDefinition
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PhpParser\Node\Identifier;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\Class_;
use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer;
use Rector\Rector\AbstractRector;
use Rector\Symfony\ApplicationMetadata\ListenerServiceDefinitionProvider;
use Rector\Symfony\NodeAnalyzer\ClassAnalyzer;
Expand Down Expand Up @@ -36,10 +37,19 @@ final class EventListenerToEventSubscriberRector extends AbstractRector
* @var \Rector\Symfony\NodeAnalyzer\ClassAnalyzer
*/
private $classAnalyzer;
/**
* @readonly
* @var \Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer
*/
private $phpAttributeAnalyzer;
/**
* @var string
*/
private const EVENT_SUBSCRIBER_INTERFACE = 'Symfony\\Component\\EventDispatcher\\EventSubscriberInterface';
/**
* @var string
*/
private const EVENT_LISTENER_ATTRIBUTE = 'Symfony\\Component\\EventDispatcher\\Attribute\\AsEventListener';
/**
* @var string
*/
Expand All @@ -57,11 +67,12 @@ final class EventListenerToEventSubscriberRector extends AbstractRector
* @var EventNameToClassAndConstant[]
*/
private $eventNamesToClassConstants = [];
public function __construct(ListenerServiceDefinitionProvider $listenerServiceDefinitionProvider, GetSubscribedEventsClassMethodFactory $getSubscribedEventsClassMethodFactory, ClassAnalyzer $classAnalyzer)
public function __construct(ListenerServiceDefinitionProvider $listenerServiceDefinitionProvider, GetSubscribedEventsClassMethodFactory $getSubscribedEventsClassMethodFactory, ClassAnalyzer $classAnalyzer, PhpAttributeAnalyzer $phpAttributeAnalyzer)
{
$this->listenerServiceDefinitionProvider = $listenerServiceDefinitionProvider;
$this->getSubscribedEventsClassMethodFactory = $getSubscribedEventsClassMethodFactory;
$this->classAnalyzer = $classAnalyzer;
$this->phpAttributeAnalyzer = $phpAttributeAnalyzer;
$this->eventNamesToClassConstants = [
// kernel events
new EventNameToClassAndConstant('kernel.request', self::KERNEL_EVENTS_CLASS, 'REQUEST'),
Expand Down Expand Up @@ -134,6 +145,9 @@ public function refactor(Node $node) : ?Node
if ($this->classAnalyzer->hasImplements($node, 'Symfony\\Component\\EventDispatcher\\EventSubscriberInterface')) {
return null;
}
if ($this->hasAsListenerAttribute($node)) {
return null;
}
// there must be event dispatcher in the application
$listenerClassesToEventsToMethods = $this->listenerServiceDefinitionProvider->extract();
if ($listenerClassesToEventsToMethods === []) {
Expand All @@ -159,4 +173,22 @@ private function changeListenerToSubscriberWithMethods(Class_ $class, array $eve
$classMethod = $this->getSubscribedEventsClassMethodFactory->createFromServiceDefinitionsAndEventsToMethods($eventsToMethods, $this->eventNamesToClassConstants);
$class->stmts[] = $classMethod;
}
/**
* @see https://symfony.com/doc/current/event_dispatcher.html#event-dispatcher_event-listener-attributes
*/
private function hasAsListenerAttribute(Class_ $class) : bool
{
if ($this->phpAttributeAnalyzer->hasPhpAttribute($class, self::EVENT_LISTENER_ATTRIBUTE)) {
return \true;
}
foreach ($class->getMethods() as $classMethod) {
if (!$classMethod->isPublic()) {
continue;
}
if ($this->phpAttributeAnalyzer->hasPhpAttribute($classMethod, self::EVENT_LISTENER_ATTRIBUTE)) {
return \true;
}
}
return \false;
}
}

0 comments on commit 1864849

Please sign in to comment.