Skip to content

Commit

Permalink
Updated Rector to commit fe99f211133b43850881ce0a7522c6242892b6b1
Browse files Browse the repository at this point in the history
rectorphp/rector-src@fe99f21 Use autowired method if exists in adding new dependency (#6652)
  • Loading branch information
TomasVotruba committed Jan 6, 2025
1 parent 4405ec5 commit 45b8ec2
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Rector\TypeDeclaration\NodeAnalyzer;

use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Property;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
Expand All @@ -23,6 +24,22 @@ public function __construct(PhpDocInfoFactory $phpDocInfoFactory, PhpAttributeAn
$this->phpDocInfoFactory = $phpDocInfoFactory;
$this->phpAttributeAnalyzer = $phpAttributeAnalyzer;
}
public function matchAutowiredMethodInClass(Class_ $class) : ?ClassMethod
{
foreach ($class->getMethods() as $classMethod) {
if (!$classMethod->isPublic()) {
continue;
}
if ($classMethod->isMagic()) {
continue;
}
if (!$this->detect($classMethod)) {
continue;
}
return $classMethod;
}
return null;
}
/**
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Param|\PhpParser\Node\Stmt\Property $node
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '8bc80b4641429cfcea9a413ff9eb1bd9afaae9ee';
public const PACKAGE_VERSION = 'fe99f211133b43850881ce0a7522c6242892b6b1';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2025-01-05 18:37:06';
public const RELEASE_DATE = '2025-01-06 10:15:49';
/**
* @var int
*/
Expand Down
18 changes: 14 additions & 4 deletions src/NodeManipulator/ClassDependencyManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,28 @@ public function __construct(\Rector\NodeManipulator\ClassInsertManipulator $clas
}
public function addConstructorDependency(Class_ $class, PropertyMetadata $propertyMetadata) : void
{
// already has property as dependency? skip it
if ($this->hasClassPropertyAndDependency($class, $propertyMetadata)) {
return;
}
if (!$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::PROPERTY_PROMOTION)) {
// special case for Symfony @required
$autowireClassMethod = $this->autowiredClassMethodOrPropertyAnalyzer->matchAutowiredMethodInClass($class);
if (!$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::PROPERTY_PROMOTION) || $autowireClassMethod instanceof ClassMethod) {
$this->classInsertManipulator->addPropertyToClass($class, $propertyMetadata->getName(), $propertyMetadata->getType());
}
// in case of existing autowire method, re-use it
if ($autowireClassMethod instanceof ClassMethod) {
$assign = $this->nodeFactory->createPropertyAssignment($propertyMetadata->getName());
$this->classMethodAssignManipulator->addParameterAndAssignToMethod($autowireClassMethod, $propertyMetadata->getName(), $propertyMetadata->getType(), $assign);
return;
}
// add PHP 8.0 promoted property
if ($this->shouldAddPromotedProperty($class, $propertyMetadata)) {
$this->addPromotedProperty($class, $propertyMetadata);
} else {
$assign = $this->nodeFactory->createPropertyAssignment($propertyMetadata->getName());
$this->addConstructorDependencyWithCustomAssign($class, $propertyMetadata->getName(), $propertyMetadata->getType(), $assign);
return;
}
$assign = $this->nodeFactory->createPropertyAssignment($propertyMetadata->getName());
$this->addConstructorDependencyWithCustomAssign($class, $propertyMetadata->getName(), $propertyMetadata->getType(), $assign);
}
/**
* @api doctrine
Expand Down
10 changes: 5 additions & 5 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -1866,12 +1866,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
"reference": "f7e0a140e1f6d30252f950b05da1fc89776468eb"
"reference": "f14ec1ab84460a4ecc961bb69dc3c8c6c4122e60"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/f7e0a140e1f6d30252f950b05da1fc89776468eb",
"reference": "f7e0a140e1f6d30252f950b05da1fc89776468eb",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/f14ec1ab84460a4ecc961bb69dc3c8c6c4122e60",
"reference": "f14ec1ab84460a4ecc961bb69dc3c8c6c4122e60",
"shasum": ""
},
"require": {
Expand All @@ -1883,7 +1883,7 @@
"phpstan\/phpstan": "^2.0",
"phpstan\/phpstan-webmozart-assert": "^2.0",
"phpunit\/phpunit": "^11.4",
"rector\/rector-src": "dev-main",
"rector\/rector-src": "dev-tv-readonly-add-ctor",
"symfony\/config": "^6.4",
"symfony\/dependency-injection": "^6.4",
"symfony\/http-kernel": "~6.3",
Expand All @@ -1896,7 +1896,7 @@
"tomasvotruba\/class-leak": "^1.0",
"tracy\/tracy": "^2.10"
},
"time": "2025-01-05T17:17:55+00:00",
"time": "2025-01-06T10:15:02+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 f740789'), '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 f9cc5a0'), '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 6b0e4f0'), '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 f7e0a14'));
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 f740789'), '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 f9cc5a0'), '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 6b0e4f0'), '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 f14ec1a'));
private function __construct()
{
}
Expand Down
2 changes: 1 addition & 1 deletion vendor/rector/rector-symfony/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"phpstan\/phpstan": "^2.0",
"phpstan\/phpstan-webmozart-assert": "^2.0",
"phpunit\/phpunit": "^11.4",
"rector\/rector-src": "dev-main",
"rector\/rector-src": "dev-tv-readonly-add-ctor",
"symfony\/config": "^6.4",
"symfony\/dependency-injection": "^6.4",
"symfony\/http-kernel": "~6.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class GetBySymfonyStringToConstructorInjectionRector extends AbstractRecto
/**
* @var array<string, string>
*/
private const SYMFONY_NAME_TO_TYPE_MAP = ['validator' => SymfonyClass::VALIDATOR_INTERFACE, 'event_dispatcher' => SymfonyClass::EVENT_DISPATCHER_INTERFACE, 'logger' => SymfonyClass::LOGGER_INTERFACE, 'jms_serializer' => SymfonyClass::SERIALIZER_INTERFACE];
private const SYMFONY_NAME_TO_TYPE_MAP = ['validator' => SymfonyClass::VALIDATOR_INTERFACE, 'event_dispatcher' => SymfonyClass::EVENT_DISPATCHER_INTERFACE, 'logger' => SymfonyClass::LOGGER_INTERFACE, 'jms_serializer' => SymfonyClass::SERIALIZER_INTERFACE, 'translator' => SymfonyClass::TRANSLATOR_INTERFACE, 'session' => SymfonyClass::SESSION, 'security.token_storage' => SymfonyClass::TOKEN_STORAGE_INTERFACE];
public function __construct(ClassDependencyManipulator $classDependencyManipulator, ThisGetTypeMatcher $thisGetTypeMatcher, PropertyNaming $propertyNaming)
{
$this->classDependencyManipulator = $classDependencyManipulator;
Expand Down
12 changes: 12 additions & 0 deletions vendor/rector/rector-symfony/src/Enum/SymfonyClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,16 @@ final class SymfonyClass
* @var string
*/
public const EVENT_SUBSCRIBER_INTERFACE = 'Symfony\\Component\\EventDispatcher\\EventSubscriberInterface';
/**
* @var string
*/
public const TRANSLATOR_INTERFACE = 'Symfony\\Contracts\\Translation\\TranslatorInterface';
/**
* @var string
*/
public const SESSION = 'Symfony\\Component\\HttpFoundation\\Session\\Session';
/**
* @var string
*/
public const TOKEN_STORAGE_INTERFACE = 'Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorageInterface';
}

0 comments on commit 45b8ec2

Please sign in to comment.