Skip to content

Commit

Permalink
Updated Rector to commit c4dd05e2e3ae6359ff4eb57ce7d7bd7619da139d
Browse files Browse the repository at this point in the history
rectorphp/rector-src@c4dd05e [CodeQuality] Add StaticToSelfStaticMethodCallOnFinalClassRector (#5621)
  • Loading branch information
TomasVotruba committed Feb 15, 2024
1 parent 6ef7f81 commit faf7fee
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 26 deletions.
8 changes: 4 additions & 4 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -1679,12 +1679,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-doctrine.git",
"reference": "cc219a306d81cbfa263baa7e2a3e7a9daa663903"
"reference": "c44beb36a11bcc763ef4b65654c44d503bd158d4"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/cc219a306d81cbfa263baa7e2a3e7a9daa663903",
"reference": "cc219a306d81cbfa263baa7e2a3e7a9daa663903",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/c44beb36a11bcc763ef4b65654c44d503bd158d4",
"reference": "c44beb36a11bcc763ef4b65654c44d503bd158d4",
"shasum": ""
},
"require": {
Expand All @@ -1709,7 +1709,7 @@
"tomasvotruba\/unused-public": "^0.3",
"tracy\/tracy": "^2.10"
},
"time": "2024-02-15T09:34:20+00:00",
"time": "2024-02-15T14:46:39+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 cc219a3'), '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 8d1aab2'), '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 cdbe390'), '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 59edb62'));
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 c44beb3'), '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 8d1aab2'), '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 cdbe390'), '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 59edb62'));
private function __construct()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand All @@ -21,7 +22,10 @@ public function __construct(NodeFactory $nodeFactory)
{
$this->nodeFactory = $nodeFactory;
}
public function transform(EntityMapping $entityMapping, Property $property) : void
/**
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
*/
public function transform(EntityMapping $entityMapping, $property) : void
{
$propertyMapping = $entityMapping->matchFieldPropertyMapping($property);
if ($propertyMapping === null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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\Helper\NodeValueNormalizer;
Expand All @@ -21,7 +22,10 @@ public function __construct(NodeFactory $nodeFactory)
{
$this->nodeFactory = $nodeFactory;
}
public function transform(EntityMapping $entityMapping, Property $property) : void
/**
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
*/
public function transform(EntityMapping $entityMapping, $property) : void
{
$propertyMapping = $entityMapping->matchEmbeddedPropertyMapping($property);
if ($propertyMapping === null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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\NodeFactory\AttributeFactory;
Expand All @@ -20,7 +21,10 @@ public function __construct(NodeFactory $nodeFactory)
{
$this->nodeFactory = $nodeFactory;
}
public function transform(EntityMapping $entityMapping, Property $property) : void
/**
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
*/
public function transform(EntityMapping $entityMapping, $property) : void
{
$fieldPropertyMapping = $entityMapping->matchFieldPropertyMapping($property);
$timestampableMapping = $fieldPropertyMapping['gedmo']['timestampable'] ?? null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
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\NodeFactory\AttributeFactory;
use Rector\Doctrine\CodeQuality\ValueObject\EntityMapping;
use Rector\Doctrine\Enum\MappingClass;
final class IdAttributeTransformer implements PropertyAttributeTransformerInterface
{
public function transform(EntityMapping $entityMapping, Property $property) : void
/**
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
*/
public function transform(EntityMapping $entityMapping, $property) : void
{
$idMapping = $entityMapping->matchIdPropertyMapping($property);
if (!\is_array($idMapping)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
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\NodeFactory\AttributeFactory;
use Rector\Doctrine\CodeQuality\ValueObject\EntityMapping;
use Rector\Doctrine\Enum\MappingClass;
final class IdColumnAttributeTransformer implements PropertyAttributeTransformerInterface
{
public function transform(EntityMapping $entityMapping, Property $property) : void
/**
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
*/
public function transform(EntityMapping $entityMapping, $property) : void
{
$idMapping = $entityMapping->matchIdPropertyMapping($property);
if (!\is_array($idMapping)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand All @@ -27,7 +28,10 @@ public function __construct(NodeFactory $nodeFactory)
// private ArrayItemNodeFactory $arrayItemNodeFactory
$this->nodeFactory = $nodeFactory;
}
public function transform(EntityMapping $entityMapping, Property $property) : void
/**
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
*/
public function transform(EntityMapping $entityMapping, $property) : void
{
$idMapping = $entityMapping->matchIdPropertyMapping($property);
if (!\is_array($idMapping)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand All @@ -21,7 +22,10 @@ public function __construct(NodeFactory $nodeFactory)
{
$this->nodeFactory = $nodeFactory;
}
public function transform(EntityMapping $entityMapping, Property $property) : void
/**
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
*/
public function transform(EntityMapping $entityMapping, $property) : void
{
$manyToOnePropertyMapping = $entityMapping->matchManyToOnePropertyMapping($property);
if (!\is_array($manyToOnePropertyMapping)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand All @@ -22,7 +23,10 @@ public function __construct(NodeFactory $nodeFactory)
{
$this->nodeFactory = $nodeFactory;
}
public function transform(EntityMapping $entityMapping, Property $property) : void
/**
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
*/
public function transform(EntityMapping $entityMapping, $property) : void
{
$manyToOneMapping = $entityMapping->matchManyToOnePropertyMapping($property);
if (!\is_array($manyToOneMapping)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand All @@ -22,7 +23,10 @@ public function __construct(NodeFactory $nodeFactory)
{
$this->nodeFactory = $nodeFactory;
}
public function transform(EntityMapping $entityMapping, Property $property) : void
/**
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
*/
public function transform(EntityMapping $entityMapping, $property) : void
{
$oneToManyMapping = $entityMapping->matchOneToManyPropertyMapping($property);
if (!\is_array($oneToManyMapping)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand All @@ -21,7 +22,10 @@ public function __construct(NodeFactory $nodeFactory)
{
$this->nodeFactory = $nodeFactory;
}
public function transform(EntityMapping $entityMapping, Property $property) : void
/**
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
*/
public function transform(EntityMapping $entityMapping, $property) : void
{
$oneToManyMapping = $entityMapping->matchOneToManyPropertyMapping($property);
if (!\is_array($oneToManyMapping)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
declare (strict_types=1);
namespace Rector\Doctrine\CodeQuality\AttributeTransformer;

use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Property;
use Rector\Doctrine\CodeQuality\Contract\ClassAttributeTransformerInterface;
use Rector\Doctrine\CodeQuality\Contract\PropertyAttributeTransformerInterface;
use Rector\Doctrine\CodeQuality\ValueObject\EntityMapping;
use Rector\ValueObject\MethodName;
final class YamlToAttributeTransformer
{
/**
Expand Down Expand Up @@ -53,9 +56,26 @@ private function transformProperties(Class_ $class, EntityMapping $entityMapping
$propertyAttributeTransformer->transform($entityMapping, $property);
}
}
// handle promoted properties
$constructorClassMethod = $class->getMethod(MethodName::CONSTRUCT);
if (!$constructorClassMethod instanceof ClassMethod) {
return;
}
foreach ($constructorClassMethod->getParams() as $param) {
// is promoted property?
if ($param->flags === 0) {
continue;
}
foreach ($this->propertyAttributeTransformers as $propertyAttributeTransformer) {
if ($this->hasAttribute($param, $propertyAttributeTransformer->getClassName())) {
continue;
}
$propertyAttributeTransformer->transform($entityMapping, $param);
}
}
}
/**
* @param \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\Property $stmt
* @param \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $stmt
*/
private function hasAttribute($stmt, string $attributeClassName) : bool
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
declare (strict_types=1);
namespace Rector\Doctrine\CodeQuality\Contract;

use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Property;
use Rector\Doctrine\CodeQuality\ValueObject\EntityMapping;
interface PropertyAttributeTransformerInterface
{
/**
* @return MappingClass::*
*/
public function getClassName() : string;
public function transform(EntityMapping $entityMapping, Property $property) : void;
/**
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
*/
public function transform(EntityMapping $entityMapping, $property) : void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
declare (strict_types=1);
namespace Rector\Doctrine\CodeQuality\ValueObject;

use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Property;
use Rector\Exception\ShouldNotHappenException;
use RectorPrefix202402\Webmozart\Assert\Assert;
final class EntityMapping
{
Expand Down Expand Up @@ -31,32 +34,36 @@ public function getClassName() : string
}
/**
* @return mixed[]|null
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
*/
public function matchFieldPropertyMapping(Property $property) : ?array
public function matchFieldPropertyMapping($property) : ?array
{
$propertyName = $this->getPropertyName($property);
return $this->entityMapping['fields'][$propertyName] ?? null;
}
/**
* @return mixed[]|null
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
*/
public function matchEmbeddedPropertyMapping(Property $property) : ?array
public function matchEmbeddedPropertyMapping($property) : ?array
{
$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 matchManyToOnePropertyMapping(Property $property) : ?array
public function matchManyToOnePropertyMapping($property) : ?array
{
$propertyName = $this->getPropertyName($property);
return $this->entityMapping['manyToOne'][$propertyName] ?? null;
}
/**
* @return array<string, mixed>|null
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
*/
public function matchOneToManyPropertyMapping(Property $property) : ?array
public function matchOneToManyPropertyMapping($property) : ?array
{
$propertyName = $this->getPropertyName($property);
return $this->entityMapping['oneToMany'][$propertyName] ?? null;
Expand All @@ -73,14 +80,26 @@ public function getClassMapping() : array
}
/**
* @return array<string, mixed>|null
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
*/
public function matchIdPropertyMapping(Property $property) : ?array
public function matchIdPropertyMapping($property) : ?array
{
$propertyName = $this->getPropertyName($property);
return $this->entityMapping['id'][$propertyName] ?? null;
}
private function getPropertyName(Property $property) : string
/**
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
*/
private function getPropertyName($property) : string
{
return $property->props[0]->name->toString();
if ($property instanceof Property) {
return $property->props[0]->name->toString();
}
if ($property->var instanceof Variable) {
$paramName = $property->var->name;
Assert::string($paramName);
return $paramName;
}
throw new ShouldNotHappenException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare (strict_types=1);
namespace Rector\Doctrine\NodeManipulator;

use PhpParser\Node\Param;
use PhpParser\Node\Expr;
use PhpParser\Node\Stmt\Property;
use PHPStan\Type\Type;
Expand Down Expand Up @@ -88,8 +89,9 @@ private function processToManyRelation(Property $property, DoctrineAnnotationTag
}
/**
* @param \PhpParser\Node\Expr|string $targetEntity
* @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param $property
*/
private function resolveTypeFromTargetEntity($targetEntity, Property $property) : Type
private function resolveTypeFromTargetEntity($targetEntity, $property) : Type
{
if ($targetEntity instanceof Expr) {
$targetEntity = $this->valueResolver->getValue($targetEntity);
Expand Down

0 comments on commit faf7fee

Please sign in to comment.