mirror of https://github.com/rectorphp/rector.git
Compare commits
3 Commits
1c323223b2
...
c041415e42
Author | SHA1 | Date |
---|---|---|
Tomas Votruba | c041415e42 | |
Tomas Votruba | 3e1d355024 | |
Tomas Votruba | 6cbc8ec497 |
|
@ -4,6 +4,7 @@ declare (strict_types=1);
|
|||
namespace Rector\DeadCode\NodeAnalyzer;
|
||||
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\NullsafeMethodCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name;
|
||||
|
@ -29,7 +30,7 @@ final class CallCollectionAnalyzer
|
|||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
}
|
||||
/**
|
||||
* @param StaticCall[]|MethodCall[] $calls
|
||||
* @param StaticCall[]|MethodCall[]|NullsafeMethodCall[] $calls
|
||||
*/
|
||||
public function isExists(array $calls, string $classMethodName, string $className) : bool
|
||||
{
|
||||
|
@ -52,14 +53,14 @@ final class CallCollectionAnalyzer
|
|||
return \false;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $call
|
||||
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\NullsafeMethodCall $call
|
||||
*/
|
||||
private function isSelfStatic($call) : bool
|
||||
{
|
||||
return $call instanceof StaticCall && $call->class instanceof Name && \in_array($call->class->toString(), [ObjectReference::SELF, ObjectReference::STATIC], \true);
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\MethodCall $call
|
||||
* @param \PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\NullsafeMethodCall $call
|
||||
*/
|
||||
private function shouldSkip($call, string $classMethodName) : bool
|
||||
{
|
||||
|
|
|
@ -88,11 +88,15 @@ final class IsClassMethodUsedAnalyzer
|
|||
if ($this->isClassMethodCalledInLocalMethodCall($class, $classMethodName)) {
|
||||
return \true;
|
||||
}
|
||||
// 2. direct static calls
|
||||
// 2. direct null-safe calls
|
||||
if ($this->isClassMethodCalledInLocalNullsafeMethodCall($class, $classMethodName)) {
|
||||
return \true;
|
||||
}
|
||||
// 3. direct static calls
|
||||
if ($this->isClassMethodUsedInLocalStaticCall($class, $classMethodName)) {
|
||||
return \true;
|
||||
}
|
||||
// 3. magic array calls!
|
||||
// 4. magic array calls!
|
||||
if ($this->isClassMethodCalledInLocalArrayCall($class, $classMethod, $scope)) {
|
||||
return \true;
|
||||
}
|
||||
|
@ -113,6 +117,13 @@ final class IsClassMethodUsedAnalyzer
|
|||
$methodCalls = $this->betterNodeFinder->findInstanceOf($class, MethodCall::class);
|
||||
return $this->callCollectionAnalyzer->isExists($methodCalls, $classMethodName, $className);
|
||||
}
|
||||
private function isClassMethodCalledInLocalNullsafeMethodCall(Class_ $class, string $classMethodName) : bool
|
||||
{
|
||||
$className = (string) $this->nodeNameResolver->getName($class);
|
||||
/** @var Node\Expr\NullsafeMethodCall[] $methodCalls */
|
||||
$methodCalls = $this->betterNodeFinder->findInstanceOf($class, Node\Expr\NullsafeMethodCall::class);
|
||||
return $this->callCollectionAnalyzer->isExists($methodCalls, $classMethodName, $className);
|
||||
}
|
||||
private function isInArrayMap(Class_ $class, Array_ $array) : bool
|
||||
{
|
||||
if (!$array->getAttribute(ArrayMapArgVisitor::ATTRIBUTE_NAME) instanceof Arg) {
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Rector\DeadCode\NodeAnalyzer;
|
|||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\NullsafePropertyFetch;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\StaticPropertyFetch;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
|
@ -24,7 +25,7 @@ final class PropertyWriteonlyAnalyzer
|
|||
public function hasClassDynamicPropertyNames(Class_ $class) : bool
|
||||
{
|
||||
return (bool) $this->betterNodeFinder->findFirst($class, static function (Node $node) : bool {
|
||||
if (!$node instanceof PropertyFetch) {
|
||||
if (!$node instanceof PropertyFetch && !$node instanceof NullsafePropertyFetch) {
|
||||
return \false;
|
||||
}
|
||||
// has dynamic name - could be anything
|
||||
|
@ -34,7 +35,7 @@ final class PropertyWriteonlyAnalyzer
|
|||
/**
|
||||
* The property fetches are always only assigned to, nothing else
|
||||
*
|
||||
* @param array<PropertyFetch|StaticPropertyFetch> $propertyFetches
|
||||
* @param array<PropertyFetch|StaticPropertyFetch|NullsafePropertyFetch> $propertyFetches
|
||||
*/
|
||||
public function arePropertyFetchesExclusivelyBeingAssignedTo(array $propertyFetches) : bool
|
||||
{
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '068799f59b289bef06b9c1f384df4301b19e726e';
|
||||
public const PACKAGE_VERSION = '71c6dd929f07d6491847ee9004224441265d0197';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2024-04-21 02:27:01';
|
||||
public const RELEASE_DATE = '2024-04-22 02:22:37';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace Rector\NodeAnalyzer;
|
|||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\NullsafePropertyFetch;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Expr\StaticPropertyFetch;
|
||||
|
@ -67,10 +68,10 @@ final class PropertyFetchAnalyzer
|
|||
}
|
||||
public function isLocalPropertyFetch(Node $node) : bool
|
||||
{
|
||||
if (!$node instanceof PropertyFetch && !$node instanceof StaticPropertyFetch) {
|
||||
if (!$node instanceof PropertyFetch && !$node instanceof StaticPropertyFetch && !$node instanceof NullsafePropertyFetch) {
|
||||
return \false;
|
||||
}
|
||||
$variableType = $node instanceof PropertyFetch ? $this->nodeTypeResolver->getType($node->var) : $this->nodeTypeResolver->getType($node->class);
|
||||
$variableType = $node instanceof StaticPropertyFetch ? $this->nodeTypeResolver->getType($node->class) : $this->nodeTypeResolver->getType($node->var);
|
||||
if ($variableType instanceof ObjectType) {
|
||||
$classReflection = $this->reflectionResolver->resolveClassReflection($node);
|
||||
if ($classReflection instanceof ClassReflection) {
|
||||
|
@ -85,7 +86,7 @@ final class PropertyFetchAnalyzer
|
|||
}
|
||||
public function isLocalPropertyFetchName(Node $node, string $desiredPropertyName) : bool
|
||||
{
|
||||
if (!$node instanceof PropertyFetch && !$node instanceof StaticPropertyFetch) {
|
||||
if (!$node instanceof PropertyFetch && !$node instanceof StaticPropertyFetch && !$node instanceof NullsafePropertyFetch) {
|
||||
return \false;
|
||||
}
|
||||
if (!$this->nodeNameResolver->isName($node->name, $desiredPropertyName)) {
|
||||
|
|
|
@ -9,6 +9,7 @@ use PhpParser\Node\Expr\ArrayDimFetch;
|
|||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\NullsafePropertyFetch;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Expr\StaticPropertyFetch;
|
||||
|
@ -96,15 +97,18 @@ final class PropertyFetchFinder
|
|||
return $this->findPropertyFetchesInClassLike($class, $nodes, $propertyName, $hasTrait, $scope);
|
||||
}
|
||||
/**
|
||||
* @return PropertyFetch[]|StaticPropertyFetch[]
|
||||
* @return PropertyFetch[]|StaticPropertyFetch[]|NullsafePropertyFetch[]
|
||||
*/
|
||||
public function findLocalPropertyFetchesByName(Class_ $class, string $paramName) : array
|
||||
{
|
||||
/** @var PropertyFetch[]|StaticPropertyFetch[] $foundPropertyFetches */
|
||||
/** @var PropertyFetch[]|StaticPropertyFetch[]|NullsafePropertyFetch[] $foundPropertyFetches */
|
||||
$foundPropertyFetches = $this->betterNodeFinder->find($class->getMethods(), function (Node $subNode) use($paramName) : bool {
|
||||
if ($subNode instanceof PropertyFetch) {
|
||||
return $this->propertyFetchAnalyzer->isLocalPropertyFetchName($subNode, $paramName);
|
||||
}
|
||||
if ($subNode instanceof NullsafePropertyFetch) {
|
||||
return $this->propertyFetchAnalyzer->isLocalPropertyFetchName($subNode, $paramName);
|
||||
}
|
||||
if ($subNode instanceof StaticPropertyFetch) {
|
||||
return $this->propertyFetchAnalyzer->isLocalPropertyFetchName($subNode, $paramName);
|
||||
}
|
||||
|
|
|
@ -1319,7 +1319,10 @@ return array(
|
|||
'Rector\\Doctrine\\CodeQuality\\AttributeTransformer\\PropertyAttributeTransformer\\IdAttributeTransformer' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/IdAttributeTransformer.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\AttributeTransformer\\PropertyAttributeTransformer\\IdColumnAttributeTransformer' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/IdColumnAttributeTransformer.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\AttributeTransformer\\PropertyAttributeTransformer\\IdGeneratorAttributeTransformer' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/IdGeneratorAttributeTransformer.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\AttributeTransformer\\PropertyAttributeTransformer\\InverseJoinColumnAttributeTransformer' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/InverseJoinColumnAttributeTransformer.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\AttributeTransformer\\PropertyAttributeTransformer\\JoinColumnAttributeTransformer' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/JoinColumnAttributeTransformer.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\AttributeTransformer\\PropertyAttributeTransformer\\JoinTableAttributeTransformer' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/JoinTableAttributeTransformer.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\AttributeTransformer\\PropertyAttributeTransformer\\ManyToManyAttributeTransformer' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/ManyToManyAttributeTransformer.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\AttributeTransformer\\PropertyAttributeTransformer\\ManyToOneAttributeTransformer' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/ManyToOneAttributeTransformer.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\AttributeTransformer\\PropertyAttributeTransformer\\OneToManyAttributeTransformer' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/OneToManyAttributeTransformer.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\AttributeTransformer\\PropertyAttributeTransformer\\OrderByAttributeTransformer' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/OrderByAttributeTransformer.php',
|
||||
|
|
|
@ -1538,7 +1538,10 @@ class ComposerStaticInit005507a96a37a412a8adf9cfaae1e621
|
|||
'Rector\\Doctrine\\CodeQuality\\AttributeTransformer\\PropertyAttributeTransformer\\IdAttributeTransformer' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/IdAttributeTransformer.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\AttributeTransformer\\PropertyAttributeTransformer\\IdColumnAttributeTransformer' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/IdColumnAttributeTransformer.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\AttributeTransformer\\PropertyAttributeTransformer\\IdGeneratorAttributeTransformer' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/IdGeneratorAttributeTransformer.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\AttributeTransformer\\PropertyAttributeTransformer\\InverseJoinColumnAttributeTransformer' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/InverseJoinColumnAttributeTransformer.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\AttributeTransformer\\PropertyAttributeTransformer\\JoinColumnAttributeTransformer' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/JoinColumnAttributeTransformer.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\AttributeTransformer\\PropertyAttributeTransformer\\JoinTableAttributeTransformer' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/JoinTableAttributeTransformer.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\AttributeTransformer\\PropertyAttributeTransformer\\ManyToManyAttributeTransformer' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/ManyToManyAttributeTransformer.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\AttributeTransformer\\PropertyAttributeTransformer\\ManyToOneAttributeTransformer' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/ManyToOneAttributeTransformer.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\AttributeTransformer\\PropertyAttributeTransformer\\OneToManyAttributeTransformer' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/OneToManyAttributeTransformer.php',
|
||||
'Rector\\Doctrine\\CodeQuality\\AttributeTransformer\\PropertyAttributeTransformer\\OrderByAttributeTransformer' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/AttributeTransformer/PropertyAttributeTransformer/OrderByAttributeTransformer.php',
|
||||
|
|
|
@ -1679,12 +1679,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/rectorphp\/rector-doctrine.git",
|
||||
"reference": "9e0a97b087071637e35eda5c7596704ee137a082"
|
||||
"reference": "ea7e84438061f3c39c59cb029e6c55b39002d8f8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/9e0a97b087071637e35eda5c7596704ee137a082",
|
||||
"reference": "9e0a97b087071637e35eda5c7596704ee137a082",
|
||||
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/ea7e84438061f3c39c59cb029e6c55b39002d8f8",
|
||||
"reference": "ea7e84438061f3c39c59cb029e6c55b39002d8f8",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1709,7 +1709,7 @@
|
|||
"tomasvotruba\/unused-public": "^0.3",
|
||||
"tracy\/tracy": "^2.10"
|
||||
},
|
||||
"time": "2024-04-21T12:41:39+00:00",
|
||||
"time": "2024-04-21T13:25:07+00:00",
|
||||
"default-branch": true,
|
||||
"type": "rector-extension",
|
||||
"extra": {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
|
|||
*/
|
||||
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 9e0a97b'), '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 05e44cf'), '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 e8af39b'), '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 b8126e8'));
|
||||
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 ea7e844'), '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 05e44cf'), '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 e8af39b'), '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 b8126e8'));
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -15,7 +15,10 @@ use Rector\Doctrine\CodeQuality\AttributeTransformer\PropertyAttributeTransforme
|
|||
use Rector\Doctrine\CodeQuality\AttributeTransformer\PropertyAttributeTransformer\IdAttributeTransformer;
|
||||
use Rector\Doctrine\CodeQuality\AttributeTransformer\PropertyAttributeTransformer\IdColumnAttributeTransformer;
|
||||
use Rector\Doctrine\CodeQuality\AttributeTransformer\PropertyAttributeTransformer\IdGeneratorAttributeTransformer;
|
||||
use Rector\Doctrine\CodeQuality\AttributeTransformer\PropertyAttributeTransformer\InverseJoinColumnAttributeTransformer;
|
||||
use Rector\Doctrine\CodeQuality\AttributeTransformer\PropertyAttributeTransformer\JoinColumnAttributeTransformer;
|
||||
use Rector\Doctrine\CodeQuality\AttributeTransformer\PropertyAttributeTransformer\JoinTableAttributeTransformer;
|
||||
use Rector\Doctrine\CodeQuality\AttributeTransformer\PropertyAttributeTransformer\ManyToManyAttributeTransformer;
|
||||
use Rector\Doctrine\CodeQuality\AttributeTransformer\PropertyAttributeTransformer\ManyToOneAttributeTransformer;
|
||||
use Rector\Doctrine\CodeQuality\AttributeTransformer\PropertyAttributeTransformer\OneToManyAttributeTransformer;
|
||||
use Rector\Doctrine\CodeQuality\AttributeTransformer\PropertyAttributeTransformer\OrderByAttributeTransformer;
|
||||
|
@ -38,9 +41,12 @@ return static function (RectorConfig $rectorConfig) : void {
|
|||
$rectorConfig->singleton(IdAttributeTransformer::class);
|
||||
$rectorConfig->singleton(IdColumnAttributeTransformer::class);
|
||||
$rectorConfig->singleton(IdGeneratorAttributeTransformer::class);
|
||||
$rectorConfig->singleton(ManyToManyAttributeTransformer::class);
|
||||
$rectorConfig->singleton(ManyToOneAttributeTransformer::class);
|
||||
$rectorConfig->singleton(OneToManyAttributeTransformer::class);
|
||||
$rectorConfig->singleton(JoinTableAttributeTransformer::class);
|
||||
$rectorConfig->singleton(JoinColumnAttributeTransformer::class);
|
||||
$rectorConfig->singleton(InverseJoinColumnAttributeTransformer::class);
|
||||
$rectorConfig->singleton(OrderByAttributeTransformer::class);
|
||||
$rectorConfig->when(YamlToAttributeTransformer::class)->needs('$classAttributeTransformers')->giveTagged(ClassAttributeTransformerInterface::class);
|
||||
$rectorConfig->when(YamlToAttributeTransformer::class)->needs('$propertyAttributeTransformers')->giveTagged(PropertyAttributeTransformerInterface::class);
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Doctrine\CodeQuality\AttributeTransformer\PropertyAttributeTransformer;
|
||||
|
||||
use PhpParser\Node\AttributeGroup;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use Rector\Doctrine\CodeQuality\Contract\PropertyAttributeTransformerInterface;
|
||||
use Rector\Doctrine\CodeQuality\NodeFactory\AttributeFactory;
|
||||
use Rector\Doctrine\CodeQuality\ValueObject\EntityMapping;
|
||||
use Rector\Doctrine\Enum\MappingClass;
|
||||
use Rector\PhpParser\Node\NodeFactory;
|
||||
final class InverseJoinColumnAttributeTransformer implements PropertyAttributeTransformerInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\PhpParser\Node\NodeFactory
|
||||
*/
|
||||
private $nodeFactory;
|
||||
public function __construct(NodeFactory $nodeFactory)
|
||||
{
|
||||
$this->nodeFactory = $nodeFactory;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
|
||||
*/
|
||||
public function transform(EntityMapping $entityMapping, $property) : void
|
||||
{
|
||||
$joinTableMapping = $entityMapping->matchManyToManyPropertyMapping($property)['joinTable'] ?? null;
|
||||
if (!\is_array($joinTableMapping)) {
|
||||
return;
|
||||
}
|
||||
$joinColumns = $joinTableMapping['inverseJoinColumns'] ?? null;
|
||||
if (!\is_array($joinColumns)) {
|
||||
return;
|
||||
}
|
||||
foreach ($joinColumns as $columnName => $joinColumn) {
|
||||
$property->attrGroups[] = $this->createInverseJoinColumnAttrGroup($columnName, $joinColumn);
|
||||
}
|
||||
}
|
||||
public function getClassName() : string
|
||||
{
|
||||
return MappingClass::INVERSE_JOIN_COLUMN;
|
||||
}
|
||||
/**
|
||||
* @param int|string $columnName
|
||||
* @param mixed $joinColumn
|
||||
*/
|
||||
private function createInverseJoinColumnAttrGroup($columnName, $joinColumn) : AttributeGroup
|
||||
{
|
||||
$joinColumn = \array_merge(['name' => $columnName], $joinColumn);
|
||||
$args = $this->nodeFactory->createArgs($joinColumn);
|
||||
return AttributeFactory::createGroup($this->getClassName(), $args);
|
||||
}
|
||||
}
|
|
@ -27,17 +27,25 @@ final class JoinColumnAttributeTransformer implements PropertyAttributeTransform
|
|||
*/
|
||||
public function transform(EntityMapping $entityMapping, $property) : void
|
||||
{
|
||||
$manyToOnePropertyMapping = $entityMapping->matchManyToOnePropertyMapping($property);
|
||||
if (!\is_array($manyToOnePropertyMapping)) {
|
||||
$this->transformMapping($property, $entityMapping->matchManyToManyPropertyMapping($property)['joinTable'] ?? null);
|
||||
$this->transformMapping($property, $entityMapping->matchManyToOnePropertyMapping($property));
|
||||
}
|
||||
/**
|
||||
* @param array<string, array<string, mixed>>|null $mapping
|
||||
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
|
||||
*/
|
||||
private function transformMapping($property, ?array $mapping) : void
|
||||
{
|
||||
if (!\is_array($mapping)) {
|
||||
return;
|
||||
}
|
||||
$singleJoinColumn = $manyToOnePropertyMapping['joinColumn'] ?? null;
|
||||
$singleJoinColumn = $mapping['joinColumn'] ?? null;
|
||||
if (\is_array($singleJoinColumn)) {
|
||||
$name = $singleJoinColumn['name'];
|
||||
unset($singleJoinColumn['name']);
|
||||
$manyToOnePropertyMapping['joinColumns'][$name] = $singleJoinColumn;
|
||||
$mapping['joinColumns'][$name] = $singleJoinColumn;
|
||||
}
|
||||
$joinColumns = $manyToOnePropertyMapping['joinColumns'] ?? null;
|
||||
$joinColumns = $mapping['joinColumns'] ?? null;
|
||||
if (!\is_array($joinColumns)) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Doctrine\CodeQuality\AttributeTransformer\PropertyAttributeTransformer;
|
||||
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use Rector\Doctrine\CodeQuality\Contract\PropertyAttributeTransformerInterface;
|
||||
use Rector\Doctrine\CodeQuality\Enum\EntityMappingKey;
|
||||
use Rector\Doctrine\CodeQuality\Helper\NodeValueNormalizer;
|
||||
use Rector\Doctrine\CodeQuality\NodeFactory\AttributeFactory;
|
||||
use Rector\Doctrine\CodeQuality\ValueObject\EntityMapping;
|
||||
use Rector\Doctrine\Enum\MappingClass;
|
||||
use Rector\PhpParser\Node\NodeFactory;
|
||||
final class JoinTableAttributeTransformer implements PropertyAttributeTransformerInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\PhpParser\Node\NodeFactory
|
||||
*/
|
||||
private $nodeFactory;
|
||||
public function __construct(NodeFactory $nodeFactory)
|
||||
{
|
||||
$this->nodeFactory = $nodeFactory;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
|
||||
*/
|
||||
public function transform(EntityMapping $entityMapping, $property) : void
|
||||
{
|
||||
$joinTableMapping = $entityMapping->matchManyToManyPropertyMapping($property)['joinTable'] ?? null;
|
||||
if (!\is_array($joinTableMapping)) {
|
||||
return;
|
||||
}
|
||||
// handled by another mapper
|
||||
unset($joinTableMapping['joinColumns'], $joinTableMapping['inverseJoinColumns']);
|
||||
$args = $this->nodeFactory->createArgs($joinTableMapping);
|
||||
$property->attrGroups[] = AttributeFactory::createGroup($this->getClassName(), $args);
|
||||
NodeValueNormalizer::ensureKeyIsClassConstFetch($args, EntityMappingKey::TARGET_ENTITY);
|
||||
}
|
||||
public function getClassName() : string
|
||||
{
|
||||
return MappingClass::JOIN_TABLE;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Doctrine\CodeQuality\AttributeTransformer\PropertyAttributeTransformer;
|
||||
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use Rector\Doctrine\CodeQuality\Contract\PropertyAttributeTransformerInterface;
|
||||
use Rector\Doctrine\CodeQuality\Enum\EntityMappingKey;
|
||||
use Rector\Doctrine\CodeQuality\Helper\NodeValueNormalizer;
|
||||
use Rector\Doctrine\CodeQuality\NodeFactory\AttributeFactory;
|
||||
use Rector\Doctrine\CodeQuality\ValueObject\EntityMapping;
|
||||
use Rector\Doctrine\Enum\MappingClass;
|
||||
use Rector\PhpParser\Node\NodeFactory;
|
||||
final class ManyToManyAttributeTransformer implements PropertyAttributeTransformerInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\PhpParser\Node\NodeFactory
|
||||
*/
|
||||
private $nodeFactory;
|
||||
public function __construct(NodeFactory $nodeFactory)
|
||||
{
|
||||
$this->nodeFactory = $nodeFactory;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
|
||||
*/
|
||||
public function transform(EntityMapping $entityMapping, $property) : void
|
||||
{
|
||||
$manyToManyMapping = $entityMapping->matchManyToManyPropertyMapping($property);
|
||||
if (!\is_array($manyToManyMapping)) {
|
||||
return;
|
||||
}
|
||||
// handled by another mapper
|
||||
unset($manyToManyMapping['joinTable']);
|
||||
$args = $this->nodeFactory->createArgs($manyToManyMapping);
|
||||
$property->attrGroups[] = AttributeFactory::createGroup($this->getClassName(), $args);
|
||||
NodeValueNormalizer::ensureKeyIsClassConstFetch($args, EntityMappingKey::TARGET_ENTITY);
|
||||
}
|
||||
public function getClassName() : string
|
||||
{
|
||||
return MappingClass::MANY_TO_MANY;
|
||||
}
|
||||
}
|
|
@ -50,6 +50,15 @@ final class EntityMapping
|
|||
$propertyName = $this->getPropertyName($property);
|
||||
return $this->entityMapping['embedded'][$propertyName] ?? null;
|
||||
}
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
|
||||
*/
|
||||
public function matchManyToManyPropertyMapping($property) : ?array
|
||||
{
|
||||
$propertyName = $this->getPropertyName($property);
|
||||
return $this->entityMapping['manyToMany'][$propertyName] ?? null;
|
||||
}
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
|
||||
|
|
|
@ -57,6 +57,18 @@ final class MappingClass
|
|||
* @var string
|
||||
*/
|
||||
public const INDEX = 'Doctrine\\ORM\\Mapping\\Index';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const INVERSE_JOIN_COLUMN = 'Doctrine\\ORM\\Mapping\\InverseJoinColumn';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const JOIN_TABLE = 'Doctrine\\ORM\\Mapping\\JoinTable';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const MANY_TO_MANY = 'Doctrine\\ORM\\Mapping\\ManyToMany';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue