diff --git a/src/Doctrine/EntityRegenerator.php b/src/Doctrine/EntityRegenerator.php index e8f5e88b4..7f5cb70dc 100644 --- a/src/Doctrine/EntityRegenerator.php +++ b/src/Doctrine/EntityRegenerator.php @@ -199,13 +199,12 @@ private function generateClass(ClassMetadata $metadata): string private function createClassManipulator(string $classPath): ClassSourceManipulator { return new ClassSourceManipulator( - $this->fileManager->getFileContents($classPath), - $this->overwrite, - // use annotations + sourceCode: $this->fileManager->getFileContents($classPath), + overwrite: $this->overwrite, // if properties need to be generated then, by definition, // some non-annotation config is being used, and so, the // properties should not have annotations added to them - false + useAttributesForDoctrineMapping: false ); } diff --git a/src/Maker/MakeAuthenticator.php b/src/Maker/MakeAuthenticator.php index f0c68413d..72d375e05 100644 --- a/src/Maker/MakeAuthenticator.php +++ b/src/Maker/MakeAuthenticator.php @@ -333,7 +333,10 @@ private function generateFormLoginFiles(string $controllerClass, string $userNam throw new RuntimeCommandException(sprintf('Method "login" already exists on class %s', $controllerClassNameDetails->getFullName())); } - $manipulator = new ClassSourceManipulator($controllerSourceCode, true); + $manipulator = new ClassSourceManipulator( + sourceCode: $controllerSourceCode, + overwrite: true + ); $this->securityControllerBuilder->addLoginMethod($manipulator); diff --git a/src/Maker/MakeEntity.php b/src/Maker/MakeEntity.php index 63116832d..da4b0e493 100644 --- a/src/Maker/MakeEntity.php +++ b/src/Maker/MakeEntity.php @@ -804,7 +804,11 @@ private function askRelationType(ConsoleStyle $io, string $entityClass, string $ private function createClassManipulator(string $path, ConsoleStyle $io, bool $overwrite): ClassSourceManipulator { - $manipulator = new ClassSourceManipulator($this->fileManager->getFileContents($path), $overwrite, false, true, true); + $manipulator = new ClassSourceManipulator( + sourceCode: $this->fileManager->getFileContents($path), + overwrite: $overwrite, + useAttributesForDoctrineMapping: true + ); $manipulator->setIo($io); diff --git a/src/Maker/MakeRegistrationForm.php b/src/Maker/MakeRegistrationForm.php index 7d1e8c2b6..fb25f8ed7 100644 --- a/src/Maker/MakeRegistrationForm.php +++ b/src/Maker/MakeRegistrationForm.php @@ -373,7 +373,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen if ($this->addUniqueEntityConstraint) { $classDetails = new ClassDetails($this->userClass); $userManipulator = new ClassSourceManipulator( - file_get_contents($classDetails->getPath()) + sourceCode: file_get_contents($classDetails->getPath()) ); $userManipulator->setIo($io); @@ -382,34 +382,24 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen UniqueEntity::class, ['fields' => [$usernameField], 'message' => sprintf('There is already an account with this %s', $usernameField)] ); - } else { - $userManipulator->addAnnotationToClass( - UniqueEntity::class, - [ - 'fields' => [$usernameField], - 'message' => sprintf('There is already an account with this %s', $usernameField), - ] - ); } + $this->fileManager->dumpFile($classDetails->getPath(), $userManipulator->getSourceCode()); } if ($this->willVerifyEmail) { $classDetails = new ClassDetails($this->userClass); $userManipulator = new ClassSourceManipulator( - file_get_contents($classDetails->getPath()), - false, - false, - true, - true + sourceCode: file_get_contents($classDetails->getPath()), + overwrite: false, + useAttributesForDoctrineMapping: true ); $userManipulator->setIo($io); $userManipulator->addProperty( - 'isVerified', - ['@ORM\Column(type="boolean")'], - false, - [$userManipulator->buildAttributeNode(Column::class, ['type' => 'boolean'], 'ORM')] + name: 'isVerified', + defaultValue: false, + attributes: [$userManipulator->buildAttributeNode(Column::class, ['type' => 'boolean'], 'ORM')] ); $userManipulator->addAccessorMethod('isVerified', 'isVerified', 'bool', false); $userManipulator->addSetter('isVerified', 'bool', false); diff --git a/src/Maker/MakeResetPassword.php b/src/Maker/MakeResetPassword.php index 9363d9ff8..4a1488015 100644 --- a/src/Maker/MakeResetPassword.php +++ b/src/Maker/MakeResetPassword.php @@ -404,11 +404,9 @@ private function generateRequestEntity(Generator $generator, ClassNameDetails $r $useAttributesForDoctrineMapping = $this->doctrineHelper->isDoctrineSupportingAttributes() && $this->doctrineHelper->doesClassUsesAttributes($requestClassNameDetails->getFullName()); $manipulator = new ClassSourceManipulator( - $this->fileManager->getFileContents($requestEntityPath), - false, - !$useAttributesForDoctrineMapping, - true, - $useAttributesForDoctrineMapping + sourceCode: $this->fileManager->getFileContents($requestEntityPath), + overwrite: false, + useAttributesForDoctrineMapping: $useAttributesForDoctrineMapping ); $manipulator->addInterface(ResetPasswordRequestInterface::class); @@ -453,7 +451,7 @@ private function generateRequestEntity(Generator $generator, ClassNameDetails $r ); $manipulator = new ClassSourceManipulator( - $this->fileManager->getFileContents($pathRequestRepository) + sourceCode: $this->fileManager->getFileContents($pathRequestRepository) ); $manipulator->addInterface(ResetPasswordRequestRepositoryInterface::class); diff --git a/src/Maker/MakeUser.php b/src/Maker/MakeUser.php index 8c4426b87..854cf49b1 100644 --- a/src/Maker/MakeUser.php +++ b/src/Maker/MakeUser.php @@ -143,15 +143,14 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen // need to write changes early so we can modify the contents below $generator->writeChanges(); + // @legacy @todo - refactor for better naming conventions BEFORE next release. $useAttributesForDoctrineMapping = $userClassConfiguration->isEntity() && ($this->doctrineHelper->isDoctrineSupportingAttributes()) && $this->doctrineHelper->doesClassUsesAttributes($userClassNameDetails->getFullName()); // B) Implement UserInterface $manipulator = new ClassSourceManipulator( - $this->fileManager->getFileContents($classPath), - true, - !$useAttributesForDoctrineMapping, - true, - $useAttributesForDoctrineMapping + sourceCode: $this->fileManager->getFileContents($classPath), + overwrite: true, + useAttributesForDoctrineMapping: $useAttributesForDoctrineMapping ); $manipulator->setIo($io); diff --git a/src/Security/UserClassBuilder.php b/src/Security/UserClassBuilder.php index 0860d4199..407f90ac5 100644 --- a/src/Security/UserClassBuilder.php +++ b/src/Security/UserClassBuilder.php @@ -70,7 +70,9 @@ private function addGetUsername(ClassSourceManipulator $manipulator, UserClassCo ); } else { // add normal property - $manipulator->addProperty($userClassConfig->getIdentityPropertyName()); + $manipulator->addProperty( + name: $userClassConfig->getIdentityPropertyName() + ); $manipulator->addGetter( $userClassConfig->getIdentityPropertyName(), @@ -126,9 +128,8 @@ private function addGetRoles(ClassSourceManipulator $manipulator, UserClassConfi } else { // add normal property $manipulator->addProperty( - 'roles', - [], - new Node\Expr\Array_([], ['kind' => Node\Expr\Array_::KIND_SHORT]) + name: 'roles', + defaultValue: new Node\Expr\Array_([], ['kind' => Node\Expr\Array_::KIND_SHORT]) ); $manipulator->addGetter( @@ -230,7 +231,10 @@ private function addGetPassword(ClassSourceManipulator $manipulator, UserClassCo ); } else { // add normal property - $manipulator->addProperty('password', [$propertyDocs]); + $manipulator->addProperty( + name: 'password', + comments: [$propertyDocs] + ); $manipulator->addGetter( 'password', diff --git a/src/Test/MakerTestRunner.php b/src/Test/MakerTestRunner.php index 17287013d..248eed326 100644 --- a/src/Test/MakerTestRunner.php +++ b/src/Test/MakerTestRunner.php @@ -253,7 +253,11 @@ public function deleteFile(string $filename): void public function manipulateClass(string $filename, \Closure $callback): void { $contents = file_get_contents($this->getPath($filename)); - $manipulator = new ClassSourceManipulator($contents, true, false, true, true); + $manipulator = new ClassSourceManipulator( + sourceCode: $contents, + overwrite: true, + useAttributesForDoctrineMapping: true + ); $callback($manipulator); file_put_contents($this->getPath($filename), $manipulator->getSourceCode()); diff --git a/src/Util/ClassSourceManipulator.php b/src/Util/ClassSourceManipulator.php index c6ec9a335..3a6615e64 100644 --- a/src/Util/ClassSourceManipulator.php +++ b/src/Util/ClassSourceManipulator.php @@ -22,7 +22,6 @@ use Doctrine\ORM\Mapping\OneToOne; use PhpParser\Builder; use PhpParser\BuilderHelpers; -use PhpParser\Comment\Doc; use PhpParser\Lexer; use PhpParser\Node; use PhpParser\NodeTraverser; @@ -46,29 +45,22 @@ final class ClassSourceManipulator private const CONTEXT_CLASS = 'class'; private const CONTEXT_CLASS_METHOD = 'class_method'; - private $overwrite; - private $useAnnotations; - private $fluentMutators; - private $useAttributesForDoctrineMapping; - private $parser; - private $lexer; - private $printer; - /** @var ConsoleStyle|null */ - private $io; + private Parser\Php7 $parser; + private Lexer\Emulative $lexer; + private PrettyPrinter $printer; + private ?ConsoleStyle $io = null; - private $sourceCode; - private $oldStmts; - private $oldTokens; - private $newStmts; + private ?array $oldStmts = null; + private array $oldTokens = []; + private array $newStmts = []; - private $pendingComments = []; + private array $pendingComments = []; - public function __construct(string $sourceCode, bool $overwrite = false, bool $useAnnotations = true, bool $fluentMutators = true, bool $useAttributesForDoctrineMapping = false) - { - $this->overwrite = $overwrite; - $this->useAnnotations = $useAnnotations; - $this->fluentMutators = $fluentMutators; - $this->useAttributesForDoctrineMapping = $useAttributesForDoctrineMapping; + public function __construct( + private string $sourceCode, + private bool $overwrite = false, + private bool $useAttributesForDoctrineMapping = true, + ) { $this->lexer = new Lexer\Emulative([ 'usedAttributes' => [ 'comments', @@ -97,20 +89,19 @@ public function addEntityField(string $propertyName, array $columnOptions, array $typeHint = $this->getEntityTypeHint($columnOptions['type']); $nullable = $columnOptions['nullable'] ?? false; $isId = (bool) ($columnOptions['id'] ?? false); - $attributes = []; - - if ($this->useAttributesForDoctrineMapping) { - $attributes[] = $this->buildAttributeNode(Column::class, $columnOptions, 'ORM'); - } else { - $comments[] = $this->buildAnnotationLine('@ORM\Column', $columnOptions); - } + $attributes[] = $this->buildAttributeNode(Column::class, $columnOptions, 'ORM'); $defaultValue = null; if ('array' === $typeHint) { $defaultValue = new Node\Expr\Array_([], ['kind' => Node\Expr\Array_::KIND_SHORT]); } - $this->addProperty($propertyName, $comments, $defaultValue, $attributes); + $this->addProperty( + name: $propertyName, + defaultValue: $defaultValue, + attributes: $attributes, + comments: $comments, + ); $this->addGetter( $propertyName, @@ -130,29 +121,15 @@ public function addEmbeddedEntity(string $propertyName, string $className): void { $typeHint = $this->addUseStatementIfNecessary($className); - $annotations = []; - $attributes = []; - - if (!$this->useAttributesForDoctrineMapping) { - $annotations = [ - $this->buildAnnotationLine( - '@ORM\\Embedded', - [ - 'class' => new ClassNameValue($className, $typeHint), - ] - ), - ]; - } else { - $attributes = [ - $this->buildAttributeNode( - Embedded::class, - ['class' => new ClassNameValue($className, $typeHint)], - 'ORM' - ), - ]; - } + $attributes = [ + $this->buildAttributeNode( + Embedded::class, + ['class' => new ClassNameValue($className, $typeHint)], + 'ORM' + ), + ]; - $this->addProperty($propertyName, $annotations, null, $attributes); + $this->addProperty(name: $propertyName, attributes: $attributes); // logic to avoid re-adding the same ArrayCollection line $addEmbedded = true; @@ -257,7 +234,7 @@ public function addGetter(string $propertyName, $returnType, bool $isReturnTypeN $this->addCustomGetter($propertyName, $methodName, $returnType, $isReturnTypeNullable, $commentLines); } - public function addSetter(string $propertyName, $type, bool $isNullable, array $commentLines = []): void + public function addSetter(string $propertyName, string $type, bool $isNullable, array $commentLines = []): void { $builder = $this->createSetterNodeBuilder($propertyName, $type, $isNullable, $commentLines); $builder->addStmt( @@ -341,7 +318,7 @@ public function createMethodLevelBlankLine() /** * @param array $attributes */ - public function addProperty(string $name, array $annotationLines = [], $defaultValue = null, array $attributes = []): void + public function addProperty(string $name, $defaultValue = null, array $attributes = [], array $comments = []): void { if ($this->propertyExists($name)) { // we never overwrite properties @@ -354,8 +331,10 @@ public function addProperty(string $name, array $annotationLines = [], $defaultV foreach ($attributes as $attribute) { $newPropertyBuilder->addAttribute($attribute); } - } elseif ($annotationLines && $this->useAnnotations) { - $newPropertyBuilder->setDocComment($this->createDocBlock($annotationLines)); + } + + if ($comments) { + $newPropertyBuilder->setDocComment($this->createDocBlock($comments)); } if (null !== $defaultValue) { @@ -377,44 +356,6 @@ public function addAttributeToClass(string $attributeClass, array $options): voi $this->updateSourceCodeFromNewStmts(); } - public function addAnnotationToClass(string $annotationClass, array $options): void - { - $annotationClassAlias = $this->addUseStatementIfNecessary($annotationClass); - $docComment = $this->getClassNode()->getDocComment(); - - $docLines = $docComment ? explode("\n", $docComment->getText()) : []; - if (0 === \count($docLines)) { - $docLines = ['/**', ' */']; - } elseif (1 === \count($docLines)) { - // /** inline doc syntax */ - // imperfect way to try to find where to split the lines - $endOfOpening = strpos($docLines[0], '* '); - $endingPosition = strrpos($docLines[0], ' *', $endOfOpening); - $extraComments = trim(substr($docLines[0], $endOfOpening + 2, $endingPosition - $endOfOpening - 2)); - $newDocLines = [ - substr($docLines[0], 0, $endOfOpening + 1), - ]; - - if ($extraComments) { - $newDocLines[] = ' * '.$extraComments; - } - - $newDocLines[] = substr($docLines[0], $endingPosition); - $docLines = $newDocLines; - } - - array_splice( - $docLines, - \count($docLines) - 1, - 0, - ' * '.$this->buildAnnotationLine('@'.$annotationClassAlias, $options) - ); - - $docComment = new Doc(implode("\n", $docLines)); - $this->getClassNode()->setDocComment($docComment); - $this->updateSourceCodeFromNewStmts(); - } - private function addCustomGetter(string $propertyName, string $methodName, $returnType, bool $isReturnTypeNullable, array $commentLines = [], $typeCast = null): void { $propertyFetch = new Node\Expr\PropertyFetch(new Node\Expr\Variable('this'), $propertyName); @@ -458,74 +399,17 @@ private function createSetterNodeBuilder(string $propertyName, $type, bool $isNu $paramBuilder = new Builder\Param($propertyName); if (null !== $type) { - $paramBuilder->setTypeHint($isNullable ? new Node\NullableType($type) : $type); + $paramBuilder->setType($isNullable ? new Node\NullableType($type) : $type); } $setterNodeBuilder->addParam($paramBuilder->getNode()); return $setterNodeBuilder; } - /** - * @param string $annotationClass The annotation: e.g. "@ORM\Column" - * @param array $options Key-value pair of options for the annotation - */ - private function buildAnnotationLine(string $annotationClass, array $options): string - { - $formattedOptions = array_map(function ($option, $value) { - if (\is_array($value)) { - if (!isset($value[0])) { - return sprintf('%s={%s}', $option, implode(', ', array_map(function ($val, $key) { - return sprintf('"%s" = %s', $key, $this->quoteAnnotationValue($val)); - }, $value, array_keys($value)))); - } - - return sprintf('%s={%s}', $option, implode(', ', array_map(function ($val) { - return $this->quoteAnnotationValue($val); - }, $value))); - } - - return sprintf('%s=%s', $option, $this->quoteAnnotationValue($value)); - }, array_keys($options), array_values($options)); - - return sprintf('%s(%s)', $annotationClass, implode(', ', $formattedOptions)); - } - - private function quoteAnnotationValue($value) - { - if (\is_bool($value)) { - return $value ? 'true' : 'false'; - } - - if (null === $value) { - return 'null'; - } - - if (\is_int($value) || '0' === $value) { - return $value; - } - - if ($value instanceof ClassNameValue) { - return sprintf('%s::class', $value->getShortName()); - } - - if (\is_array($value)) { - throw new \Exception('Invalid value: loop before quoting.'); - } - - if (\function_exists('enum_exists')) { - // do we have an enum ? - if (\is_object($value) && enum_exists(\get_class($value))) { - $value = $value->value; - } - } - - return sprintf('"%s"', $value); - } - private function addSingularRelation(BaseRelation $relation): void { $typeHint = $this->addUseStatementIfNecessary($relation->getTargetClassName()); - if ($relation->getTargetClassName() == $this->getThisFullClassName()) { + if ($relation->getTargetClassName() === $this->getThisFullClassName()) { $typeHint = 'self'; } @@ -545,37 +429,19 @@ private function addSingularRelation(BaseRelation $relation): void $annotationOptions['cascade'] = ['persist', 'remove']; } - $annotations = []; - $attributes = []; - - if (!$this->useAttributesForDoctrineMapping) { - $annotations = [ - $this->buildAnnotationLine( - $relation instanceof RelationManyToOne ? '@ORM\\ManyToOne' : '@ORM\\OneToOne', - $annotationOptions - ), - ]; - } else { - $attributes = [ + $attributes = [ $this->buildAttributeNode( $relation instanceof RelationManyToOne ? ManyToOne::class : OneToOne::class, $annotationOptions, 'ORM' ), ]; - } if (!$relation->isNullable() && $relation->isOwning()) { - if (!$this->useAttributesForDoctrineMapping) { - $annotations[] = $this->buildAnnotationLine('@ORM\\JoinColumn', [ - 'nullable' => false, - ]); - } else { - $attributes[] = $this->buildAttributeNode(JoinColumn::class, ['nullable' => false], 'ORM'); - } + $attributes[] = $this->buildAttributeNode(JoinColumn::class, ['nullable' => false], 'ORM'); } - $this->addProperty($relation->getPropertyName(), $annotations, null, $attributes); + $this->addProperty(name: $relation->getPropertyName(), attributes: $attributes); $this->addGetter( $relation->getPropertyName(), @@ -640,27 +506,15 @@ private function addCollectionRelation(BaseCollectionRelation $relation): void $annotationOptions['orphanRemoval'] = true; } - $annotations = []; - $attributes = []; - - if (!$this->useAttributesForDoctrineMapping) { - $annotations = [ - $this->buildAnnotationLine( - $relation instanceof RelationManyToMany ? '@ORM\\ManyToMany' : '@ORM\\OneToMany', - $annotationOptions - ), - ]; - } else { - $attributes = [ + $attributes = [ $this->buildAttributeNode( $relation instanceof RelationManyToMany ? ManyToMany::class : OneToMany::class, $annotationOptions, 'ORM' ), ]; - } - $this->addProperty($relation->getPropertyName(), $annotations, null, $attributes); + $this->addProperty(name: $relation->getPropertyName(), attributes: $attributes); // logic to avoid re-adding the same ArrayCollection line $addArrayCollection = true; @@ -669,7 +523,7 @@ private function addCollectionRelation(BaseCollectionRelation $relation): void // look for "$this->propertyName = " $constructorString = $this->printer->prettyPrint([$this->getConstructorNode()]); - if (false !== strpos($constructorString, sprintf('$this->%s = ', $relation->getPropertyName()))) { + if (str_contains($constructorString, sprintf('$this->%s = ', $relation->getPropertyName()))) { $addArrayCollection = false; } } @@ -697,7 +551,7 @@ private function addCollectionRelation(BaseCollectionRelation $relation): void $adderNodeBuilder = (new Builder\Method($relation->getAdderMethodName()))->makePublic(); $paramBuilder = new Builder\Param($argName); - $paramBuilder->setTypeHint($typeHint); + $paramBuilder->setType($typeHint); $adderNodeBuilder->addParam($paramBuilder->getNode()); // if (!$this->avatars->contains($avatar)) @@ -938,7 +792,11 @@ public function buildAttributeNode(string $attributeClass, array $options, ?stri $options = $this->sortOptionsByClassConstructorParameters($options, $attributeClass); $context = $this; - $nodeArguments = array_map(static function ($option, $value) use ($context) { + $nodeArguments = array_map(static function (string $option, mixed $value) use ($context) { + if (null === $value) { + return new Node\NullableType($option); + } + return new Node\Arg($context->buildNodeExprByValue($value), false, false, [], new Node\Identifier($option)); }, array_keys($options), array_values($options)); @@ -967,7 +825,7 @@ private function updateSourceCodeFromNewStmts(): void foreach ($this->pendingComments as $i => $comment) { // sanity check $placeholder = sprintf('$__COMMENT__VAR_%d;', $i); - if (false === strpos($newCode, $placeholder)) { + if (!str_contains($newCode, $placeholder)) { // this can happen if a comment is createSingleLineCommentNode() // is called, but then that generated code is ultimately not added continue; @@ -1056,21 +914,22 @@ private function findAllNodes(callable $filterCallback): array return $visitor->getFoundNodes(); } - private function createBlankLineNode(string $context) + private function createBlankLineNode(string $context): Node\Stmt\Use_|Node|Node\Stmt\Property|Node\Expr\Variable { - switch ($context) { - case self::CONTEXT_OUTSIDE_CLASS: - return (new Builder\Use_('__EXTRA__LINE', Node\Stmt\Use_::TYPE_NORMAL)) - ->getNode(); - case self::CONTEXT_CLASS: - return (new Builder\Property('__EXTRA__LINE')) - ->makePrivate() - ->getNode(); - case self::CONTEXT_CLASS_METHOD: - return new Node\Expr\Variable('__EXTRA__LINE'); - default: - throw new \Exception('Unknown context: '.$context); - } + return match ($context) { + self::CONTEXT_OUTSIDE_CLASS => (new Builder\Use_( + '__EXTRA__LINE', + Node\Stmt\Use_::TYPE_NORMAL + )) + ->getNode(), + self::CONTEXT_CLASS => (new Builder\Property('__EXTRA__LINE')) + ->makePrivate() + ->getNode(), + self::CONTEXT_CLASS_METHOD => new Node\Expr\Variable( + '__EXTRA__LINE' + ), + default => throw new \Exception('Unknown context: '.$context), + }; } private function createSingleLineCommentNode(string $comment, string $context): Node\Stmt @@ -1153,68 +1012,29 @@ private function addMethod(Node\Stmt\ClassMethod $methodNode): void private function makeMethodFluent(Builder\Method $methodBuilder): void { - if (!$this->fluentMutators) { - return; - } - $methodBuilder ->addStmt($this->createBlankLineNode(self::CONTEXT_CLASS_METHOD)) ->addStmt(new Node\Stmt\Return_(new Node\Expr\Variable('this'))); $methodBuilder->setReturnType('self'); } - private function getEntityTypeHint($doctrineType): ?string + private function getEntityTypeHint(string $doctrineType): ?string { - switch ($doctrineType) { - case 'string': - case 'text': - case 'guid': - case 'bigint': - case 'decimal': - return 'string'; - - case 'array': - case 'simple_array': - case 'json': - case 'json_array': - return 'array'; - - case 'boolean': - return 'bool'; - - case 'integer': - case 'smallint': - return 'int'; - - case 'float': - return 'float'; - - case 'datetime': - case 'datetimetz': - case 'date': - case 'time': - return '\\'.\DateTimeInterface::class; - - case 'datetime_immutable': - case 'datetimetz_immutable': - case 'date_immutable': - case 'time_immutable': - return '\\'.\DateTimeImmutable::class; - - case 'dateinterval': - return '\\'.\DateInterval::class; - - case 'object': - return 'object'; - - case 'binary': - case 'blob': - default: - return null; - } + return match ($doctrineType) { + 'string', 'text', 'guid', 'bigint', 'decimal' => 'string', + 'array', 'simple_array', 'json', 'json_array' => 'array', + 'boolean' => 'bool', + 'integer', 'smallint' => 'int', + 'float' => 'float', + 'datetime', 'datetimetz', 'date', 'time' => '\\'.\DateTimeInterface::class, + 'datetime_immutable', 'datetimetz_immutable', 'date_immutable', 'time_immutable' => '\\'.\DateTimeImmutable::class, + 'dateinterval' => '\\'.\DateInterval::class, + 'object' => 'object', + default => null, + }; } - private function isInSameNamespace($class): bool + private function isInSameNamespace(string $class): bool { $namespace = substr($class, 0, strrpos($class, '\\')); @@ -1425,11 +1245,9 @@ private function addMethodParams(Builder\Method $methodBuilder, array $params): * builds a PHPParser Expr Node based on the value given in $value * throws an Exception when the given $value is not resolvable by this method. * - * @param mixed $value - * * @throws \Exception */ - private function buildNodeExprByValue($value): Node\Expr + private function buildNodeExprByValue(mixed $value): Node\Expr { switch (\gettype($value)) { case 'string': @@ -1481,7 +1299,7 @@ private function buildNodeExprByValue($value): Node\Expr */ private function sortOptionsByClassConstructorParameters(array $options, string $classString): array { - if ('ORM\\' === substr($classString, 0, 4)) { + if (str_starts_with($classString, 'ORM\\')) { $classString = sprintf('Doctrine\\ORM\\Mapping\\%s', substr($classString, 4)); } diff --git a/tests/Security/fixtures/expected/UserEntityWithEmailAsIdentifier.php b/tests/Security/fixtures/expected/UserEntityWithEmailAsIdentifier.php index fc12819be..dd2798864 100644 --- a/tests/Security/fixtures/expected/UserEntityWithEmailAsIdentifier.php +++ b/tests/Security/fixtures/expected/UserEntityWithEmailAsIdentifier.php @@ -6,32 +6,24 @@ use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\UserInterface; -/** - * @ORM\Entity() - */ +#[ORM\Entity] class User implements UserInterface, PasswordAuthenticatedUserInterface { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] private $id; - /** - * @ORM\Column(type="string", length=180, unique=true) - */ + #[ORM\Column(type: 'string', length: 180, unique: true)] private $email; - /** - * @ORM\Column(type="json") - */ + #[ORM\Column(type: 'json')] private $roles = []; /** * @var string The hashed password - * @ORM\Column(type="string") */ + #[ORM\Column(type: 'string')] private $password; public function getId(): ?int diff --git a/tests/Security/fixtures/expected/UserEntityWithPassword.php b/tests/Security/fixtures/expected/UserEntityWithPassword.php index 3a26a68be..f38aeaad4 100644 --- a/tests/Security/fixtures/expected/UserEntityWithPassword.php +++ b/tests/Security/fixtures/expected/UserEntityWithPassword.php @@ -6,32 +6,24 @@ use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\UserInterface; -/** - * @ORM\Entity() - */ +#[ORM\Entity] class User implements UserInterface, PasswordAuthenticatedUserInterface { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] private $id; - /** - * @ORM\Column(type="string", length=180, unique=true) - */ + #[ORM\Column(type: 'string', length: 180, unique: true)] private $userIdentifier; - /** - * @ORM\Column(type="json") - */ + #[ORM\Column(type: 'json')] private $roles = []; /** * @var string The hashed password - * @ORM\Column(type="string") */ + #[ORM\Column(type: 'string')] private $password; public function getId(): ?int diff --git a/tests/Security/fixtures/expected/UserEntityWithUser_IdentifierAsIdentifier.php b/tests/Security/fixtures/expected/UserEntityWithUser_IdentifierAsIdentifier.php index 2d172b16e..30b8ba863 100644 --- a/tests/Security/fixtures/expected/UserEntityWithUser_IdentifierAsIdentifier.php +++ b/tests/Security/fixtures/expected/UserEntityWithUser_IdentifierAsIdentifier.php @@ -6,32 +6,24 @@ use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\UserInterface; -/** - * @ORM\Entity() - */ +#[ORM\Entity] class User implements UserInterface, PasswordAuthenticatedUserInterface { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] private $id; - /** - * @ORM\Column(type="string", length=180, unique=true) - */ + #[ORM\Column(type: 'string', length: 180, unique: true)] private $user_identifier; - /** - * @ORM\Column(type="json") - */ + #[ORM\Column(type: 'json')] private $roles = []; /** * @var string The hashed password - * @ORM\Column(type="string") */ + #[ORM\Column(type: 'string')] private $password; public function getId(): ?int diff --git a/tests/Security/fixtures/expected/UserEntityWithoutPassword.php b/tests/Security/fixtures/expected/UserEntityWithoutPassword.php index 0328dab30..4faf649b3 100644 --- a/tests/Security/fixtures/expected/UserEntityWithoutPassword.php +++ b/tests/Security/fixtures/expected/UserEntityWithoutPassword.php @@ -5,26 +5,18 @@ use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Security\Core\User\UserInterface; -/** - * @ORM\Entity() - */ +#[ORM\Entity] class User implements UserInterface { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] private $id; - /** - * @ORM\Column(type="string", length=180, unique=true) - */ + #[ORM\Column(type: 'string', length: 180, unique: true)] private $userIdentifier; - /** - * @ORM\Column(type="json") - */ + #[ORM\Column(type: 'json')] private $roles = []; public function getId(): ?int diff --git a/tests/Security/fixtures/expected/legacy_5_user_class/UserEntityWithEmailAsIdentifier.php b/tests/Security/fixtures/expected/legacy_5_user_class/UserEntityWithEmailAsIdentifier.php index cadbb6483..e939a4a41 100644 --- a/tests/Security/fixtures/expected/legacy_5_user_class/UserEntityWithEmailAsIdentifier.php +++ b/tests/Security/fixtures/expected/legacy_5_user_class/UserEntityWithEmailAsIdentifier.php @@ -6,32 +6,24 @@ use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\UserInterface; -/** - * @ORM\Entity() - */ +#[ORM\Entity] class User implements UserInterface, PasswordAuthenticatedUserInterface { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] private $id; - /** - * @ORM\Column(type="string", length=180, unique=true) - */ + #[ORM\Column(type: 'string', length: 180, unique: true)] private $email; - /** - * @ORM\Column(type="json") - */ + #[ORM\Column(type: 'json')] private $roles = []; /** * @var string The hashed password - * @ORM\Column(type="string") */ + #[ORM\Column(type: 'string')] private $password; public function getId(): ?int diff --git a/tests/Security/fixtures/expected/legacy_5_user_class/UserEntityWithPassword.php b/tests/Security/fixtures/expected/legacy_5_user_class/UserEntityWithPassword.php index b7c75eebe..3de10273d 100644 --- a/tests/Security/fixtures/expected/legacy_5_user_class/UserEntityWithPassword.php +++ b/tests/Security/fixtures/expected/legacy_5_user_class/UserEntityWithPassword.php @@ -6,32 +6,24 @@ use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\UserInterface; -/** - * @ORM\Entity() - */ +#[ORM\Entity] class User implements UserInterface, PasswordAuthenticatedUserInterface { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] private $id; - /** - * @ORM\Column(type="string", length=180, unique=true) - */ + #[ORM\Column(type: 'string', length: 180, unique: true)] private $userIdentifier; - /** - * @ORM\Column(type="json") - */ + #[ORM\Column(type: 'json')] private $roles = []; /** * @var string The hashed password - * @ORM\Column(type="string") */ + #[ORM\Column(type: 'string')] private $password; public function getId(): ?int diff --git a/tests/Security/fixtures/expected/legacy_5_user_class/UserEntityWithUser_IdentifierAsIdentifier.php b/tests/Security/fixtures/expected/legacy_5_user_class/UserEntityWithUser_IdentifierAsIdentifier.php index 08a2ee1f1..a036b2f2e 100644 --- a/tests/Security/fixtures/expected/legacy_5_user_class/UserEntityWithUser_IdentifierAsIdentifier.php +++ b/tests/Security/fixtures/expected/legacy_5_user_class/UserEntityWithUser_IdentifierAsIdentifier.php @@ -6,32 +6,24 @@ use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\UserInterface; -/** - * @ORM\Entity() - */ +#[ORM\Entity] class User implements UserInterface, PasswordAuthenticatedUserInterface { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] private $id; - /** - * @ORM\Column(type="string", length=180, unique=true) - */ + #[ORM\Column(type: 'string', length: 180, unique: true)] private $user_identifier; - /** - * @ORM\Column(type="json") - */ + #[ORM\Column(type: 'json')] private $roles = []; /** * @var string The hashed password - * @ORM\Column(type="string") */ + #[ORM\Column(type: 'string')] private $password; public function getId(): ?int diff --git a/tests/Security/fixtures/expected/legacy_5_user_class/UserEntityWithoutPassword.php b/tests/Security/fixtures/expected/legacy_5_user_class/UserEntityWithoutPassword.php index bdaa8328f..5dd9e2d85 100644 --- a/tests/Security/fixtures/expected/legacy_5_user_class/UserEntityWithoutPassword.php +++ b/tests/Security/fixtures/expected/legacy_5_user_class/UserEntityWithoutPassword.php @@ -5,26 +5,18 @@ use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Security\Core\User\UserInterface; -/** - * @ORM\Entity() - */ +#[ORM\Entity] class User implements UserInterface { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] private $id; - /** - * @ORM\Column(type="string", length=180, unique=true) - */ + #[ORM\Column(type: 'string', length: 180, unique: true)] private $userIdentifier; - /** - * @ORM\Column(type="json") - */ + #[ORM\Column(type: 'json')] private $roles = []; public function getId(): ?int diff --git a/tests/Security/fixtures/source/UserEntity.php b/tests/Security/fixtures/source/UserEntity.php index 5274d16db..c9aaa7f05 100644 --- a/tests/Security/fixtures/source/UserEntity.php +++ b/tests/Security/fixtures/source/UserEntity.php @@ -4,16 +4,12 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity() - */ +#[ORM\Entity] class User { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] private $id; public function getId(): ?int diff --git a/tests/Util/ClassSourceManipulatorTest.php b/tests/Util/ClassSourceManipulatorTest.php index 3d5ffe15e..91b48a29e 100644 --- a/tests/Util/ClassSourceManipulatorTest.php +++ b/tests/Util/ClassSourceManipulatorTest.php @@ -27,7 +27,7 @@ class ClassSourceManipulatorTest extends TestCase /** * @dataProvider getAddPropertyTests */ - public function testAddProperty(string $sourceFilename, $propertyName, array $commentLines, $expectedSourceFilename) + public function testAddProperty(string $sourceFilename, $propertyName, array $commentLines, $expectedSourceFilename): void { $source = file_get_contents(__DIR__.'/fixtures/source/'.$sourceFilename); $expectedSource = file_get_contents(__DIR__.'/fixtures/add_property/'.$expectedSourceFilename); @@ -35,15 +35,15 @@ public function testAddProperty(string $sourceFilename, $propertyName, array $co $manipulator = new ClassSourceManipulator($source); $method = (new \ReflectionObject($manipulator))->getMethod('addProperty'); $method->setAccessible(true); - $method->invoke($manipulator, $propertyName, $commentLines); + $method->invoke($manipulator, name: $propertyName, comments: $commentLines); $this->assertSame($expectedSource, $manipulator->getSourceCode()); } - public function getAddPropertyTests() + public function getAddPropertyTests(): \Generator { yield 'normal_property_add' => [ - 'legacy/User_simple.php', + 'User_simple.php', 'fooProp', [], 'User_simple.php', @@ -67,7 +67,7 @@ public function getAddPropertyTests() ]; yield 'property_empty_class' => [ - 'legacy/User_empty.php', + 'User_empty.php', 'fooProp', [], 'User_empty.php', @@ -77,7 +77,7 @@ public function getAddPropertyTests() /** * @dataProvider getAddGetterTests */ - public function testAddGetter(string $sourceFilename, string $propertyName, string $type, array $commentLines, $expectedSourceFilename) + public function testAddGetter(string $sourceFilename, string $propertyName, string $type, array $commentLines, $expectedSourceFilename): void { $source = file_get_contents(__DIR__.'/fixtures/source/'.$sourceFilename); $expectedSource = file_get_contents(__DIR__.'/fixtures/add_getter/'.$expectedSourceFilename); @@ -90,10 +90,10 @@ public function testAddGetter(string $sourceFilename, string $propertyName, stri $this->assertSame($expectedSource, $manipulator->getSourceCode()); } - public function getAddGetterTests() + public function getAddGetterTests(): \Generator { yield 'normal_getter_add' => [ - 'legacy/User_simple.php', + 'User_simple.php', 'fooProp', 'string', [], @@ -101,7 +101,7 @@ public function getAddGetterTests() ]; yield 'normal_getter_add_bool' => [ - 'legacy/User_simple.php', + 'User_simple.php', 'fooProp', 'bool', [], @@ -120,7 +120,7 @@ public function getAddGetterTests() ]; yield 'getter_empty_class' => [ - 'legacy/User_empty.php', + 'User_empty.php', 'fooProp', 'string', [], @@ -131,7 +131,7 @@ public function getAddGetterTests() /** * @dataProvider getAddSetterTests */ - public function testAddSetter(string $sourceFilename, string $propertyName, string $type, bool $isNullable, array $commentLines, $expectedSourceFilename) + public function testAddSetter(string $sourceFilename, string $propertyName, string $type, bool $isNullable, array $commentLines, $expectedSourceFilename): void { $source = file_get_contents(__DIR__.'/fixtures/source/'.$sourceFilename); $expectedSource = file_get_contents(__DIR__.'/fixtures/add_setter/'.$expectedSourceFilename); @@ -144,10 +144,10 @@ public function testAddSetter(string $sourceFilename, string $propertyName, stri $this->assertSame($expectedSource, $manipulator->getSourceCode()); } - public function getAddSetterTests() + public function getAddSetterTests(): \Generator { yield 'normal_setter_add' => [ - 'legacy/User_simple.php', + 'User_simple.php', 'fooProp', 'string', false, @@ -168,7 +168,7 @@ public function getAddSetterTests() ]; yield 'setter_empty_class' => [ - 'legacy/User_empty.php', + 'User_empty.php', 'fooProp', 'string', false, @@ -182,11 +182,6 @@ public function getAddSetterTests() */ public function testAddAttributeToClass(string $sourceFilename, string $expectedSourceFilename, string $attributeClass, array $attributeOptions, string $attributePrefix = null): void { - // @legacy Remove conditional when PHP < 8.0 support is dropped. - if ((\PHP_VERSION_ID < 80000)) { - $this->markTestSkipped('Requires PHP >= PHP 8.0'); - } - $source = file_get_contents(__DIR__.'/fixtures/source/'.$sourceFilename); $expectedSource = file_get_contents(__DIR__.'/fixtures/add_class_attribute/'.$expectedSourceFilename); $manipulator = new ClassSourceManipulator($source); @@ -212,38 +207,6 @@ public function getAttributeClassTests(): \Generator ]; } - /** - * @dataProvider getAnnotationTests - */ - public function testBuildAnnotationLine(string $annotationClass, array $annotationOptions, string $expectedAnnotation) - { - $manipulator = new ClassSourceManipulator(''); - $method = (new \ReflectionObject($manipulator))->getMethod('buildAnnotationLine'); - $method->setAccessible(true); - $actualAnnotation = $method->invoke($manipulator, $annotationClass, $annotationOptions); - - $this->assertSame($expectedAnnotation, $actualAnnotation); - } - - public function getAnnotationTests() - { - yield 'empty_annotation' => [ - '@ORM\Column', - [], - '@ORM\Column()', - ]; - - yield 'complex_annotation' => [ - '@ORM\Column', - [ - 'name' => 'firstName', - 'length' => 10, - 'nullable' => false, - ], - '@ORM\Column(name="firstName", length=10, nullable=false)', - ]; - } - /** * @dataProvider getAddEntityFieldTests */ @@ -252,30 +215,17 @@ public function testAddEntityField(string $sourceFilename, string $propertyName, $sourcePath = __DIR__.'/fixtures/source'; $expectedPath = __DIR__.'/fixtures/add_entity_field'; - // Legacy Annotation Tests $this->runAddEntityFieldTests( - file_get_contents(sprintf('%s/legacy/%s', $sourcePath, $sourceFilename)), - $propertyName, - $fieldOptions, - file_get_contents(sprintf('%s/legacy/%s', $expectedPath, $expectedSourceFilename)), - false - ); - - // Run Attribute Tests - if ((\PHP_VERSION_ID >= 80000)) { - $this->runAddEntityFieldTests( file_get_contents(sprintf('%s/%s', $sourcePath, $sourceFilename)), $propertyName, $fieldOptions, - file_get_contents(sprintf('%s/%s', $expectedPath, $expectedSourceFilename)), - true + file_get_contents(sprintf('%s/%s', $expectedPath, $expectedSourceFilename)) ); - } } - private function runAddEntityFieldTests(string $source, string $propertyName, array $fieldOptions, string $expected, bool $php8): void + private function runAddEntityFieldTests(string $source, string $propertyName, array $fieldOptions, string $expected): void { - $manipulator = new ClassSourceManipulator($source, false, !$php8, true, $php8); + $manipulator = new ClassSourceManipulator($source, false, true); $manipulator->addEntityField($propertyName, $fieldOptions); $this->assertSame($expected, $manipulator->getSourceCode()); @@ -345,28 +295,16 @@ public function testAddManyToOneRelation(string $sourceFilename, $expectedSource $sourcePath = __DIR__.'/fixtures/source'; $expectedPath = __DIR__.'/fixtures/add_many_to_one_relation'; - // Legacy Annotation Tests $this->runAddManyToOneRelationTests( - file_get_contents(sprintf('%s/legacy/%s', $sourcePath, $sourceFilename)), - file_get_contents(sprintf('%s/legacy/%s', $expectedPath, $expectedSourceFilename)), - $manyToOne, - false - ); - - // Run Attribute Tests - if ((\PHP_VERSION_ID >= 80000)) { - $this->runAddManyToOneRelationTests( file_get_contents(sprintf('%s/%s', $sourcePath, $sourceFilename)), file_get_contents(sprintf('%s/%s', $expectedPath, $expectedSourceFilename)), - $manyToOne, - true + $manyToOne ); - } } - public function runAddManyToOneRelationTests(string $source, string $expected, RelationManyToOne $manyToOne, bool $php8): void + public function runAddManyToOneRelationTests(string $source, string $expected, RelationManyToOne $manyToOne): void { - $manipulator = new ClassSourceManipulator($source, false, !$php8, true, $php8); + $manipulator = new ClassSourceManipulator($source, false, true); $manipulator->addManyToOneRelation($manyToOne); $this->assertSame($expected, $manipulator->getSourceCode()); @@ -450,33 +388,21 @@ public function getAddManyToOneRelationTests(): \Generator /** * @dataProvider getAddOneToManyRelationTests */ - public function testAddOneToManyRelation(string $sourceFilename, string $expectedSourceFilename, RelationOneToMany $oneToMany) + public function testAddOneToManyRelation(string $sourceFilename, string $expectedSourceFilename, RelationOneToMany $oneToMany): void { $sourcePath = __DIR__.'/fixtures/source'; $expectedPath = __DIR__.'/fixtures/add_one_to_many_relation'; - // Legacy Annotation Tests $this->runAddOneToManyRelationTests( - file_get_contents(sprintf('%s/legacy/%s', $sourcePath, $sourceFilename)), - file_get_contents(sprintf('%s/legacy/%s', $expectedPath, $expectedSourceFilename)), - $oneToMany, - false - ); - - // Run Attribute Tests - if ((\PHP_VERSION_ID >= 80000)) { - $this->runAddOneToManyRelationTests( file_get_contents(sprintf('%s/%s', $sourcePath, $sourceFilename)), file_get_contents(sprintf('%s/%s', $expectedPath, $expectedSourceFilename)), - $oneToMany, - true + $oneToMany ); - } } - private function runAddOneToManyRelationTests(string $source, string $expected, RelationOneToMany $oneToMany, bool $php8): void + private function runAddOneToManyRelationTests(string $source, string $expected, RelationOneToMany $oneToMany): void { - $manipulator = new ClassSourceManipulator($source, false, !$php8, true, $php8); + $manipulator = new ClassSourceManipulator($source, false, true); $manipulator->addOneToManyRelation($oneToMany); $this->assertSame($expected, $manipulator->getSourceCode()); @@ -528,28 +454,16 @@ public function testAddManyToManyRelation(string $sourceFilename, $expectedSourc $sourcePath = __DIR__.'/fixtures/source'; $expectedPath = __DIR__.'/fixtures/add_many_to_many_relation'; - // Legacy Annotation Tests $this->runAddManyToManyRelationTest( - file_get_contents(sprintf('%s/legacy/%s', $sourcePath, $sourceFilename)), - file_get_contents(sprintf('%s/legacy/%s', $expectedPath, $expectedSourceFilename)), - $manyToMany, - false - ); - - // Run Attribute Tests - if ((\PHP_VERSION_ID >= 80000)) { - $this->runAddManyToManyRelationTest( file_get_contents(sprintf('%s/%s', $sourcePath, $sourceFilename)), file_get_contents(sprintf('%s/%s', $expectedPath, $expectedSourceFilename)), - $manyToMany, - true + $manyToMany ); - } } - private function runAddManyToManyRelationTest(string $source, string $expected, RelationManyToMany $manyToMany, bool $php8): void + private function runAddManyToManyRelationTest(string $source, string $expected, RelationManyToMany $manyToMany): void { - $manipulator = new ClassSourceManipulator($source, false, !$php8, true, $php8); + $manipulator = new ClassSourceManipulator($source, false, true); $manipulator->addManyToManyRelation($manyToMany); $this->assertSame($expected, $manipulator->getSourceCode()); @@ -599,28 +513,16 @@ public function testAddOneToOneRelation(string $sourceFilename, $expectedSourceF $sourcePath = __DIR__.'/fixtures/source'; $expectedPath = __DIR__.'/fixtures/add_one_to_one_relation'; - // Legacy Annotation Tests $this->runAddOneToOneRelation( - file_get_contents(sprintf('%s/legacy/%s', $sourcePath, $sourceFilename)), - file_get_contents(sprintf('%s/legacy/%s', $expectedPath, $expectedSourceFilename)), - $oneToOne, - false - ); - - // Run Attribute Tests - if ((\PHP_VERSION_ID >= 80000)) { - $this->runAddOneToOneRelation( file_get_contents(sprintf('%s/%s', $sourcePath, $sourceFilename)), file_get_contents(sprintf('%s/%s', $expectedPath, $expectedSourceFilename)), - $oneToOne, - true + $oneToOne ); - } } - private function runAddOneToOneRelation(string $source, string $expected, RelationOneToOne $oneToOne, bool $php8): void + private function runAddOneToOneRelation(string $source, string $expected, RelationOneToOne $oneToOne): void { - $manipulator = new ClassSourceManipulator($source, false, !$php8, true, $php8); + $manipulator = new ClassSourceManipulator($source, false, true); $manipulator->addOneToOneRelation($oneToOne); $this->assertSame($expected, $manipulator->getSourceCode()); @@ -722,8 +624,9 @@ public function getAddOneToOneRelationTests(): \Generator ]; } - public function testGenerationWithTabs() + public function testGenerationWithTabs(): void { + $this->markTestIncomplete('We need to refactor the invoked addProperty method to pass an attribute node instead of an annotation array'); $source = file_get_contents(__DIR__.'/fixtures/source/ProductWithTabs.php'); $expectedSource = file_get_contents(__DIR__.'/fixtures/with_tabs/ProductWithTabs.php'); @@ -740,9 +643,9 @@ public function testGenerationWithTabs() $this->assertSame($expectedSource, $manipulator->getSourceCode()); } - public function testAddInterface() + public function testAddInterface(): void { - $source = file_get_contents(__DIR__.'/fixtures/source/legacy/User_simple.php'); + $source = file_get_contents(__DIR__.'/fixtures/source/User_simple.php'); $expectedSource = file_get_contents(__DIR__.'/fixtures/implements_interface/User_simple.php'); $manipulator = new ClassSourceManipulator($source); @@ -751,7 +654,7 @@ public function testAddInterface() $this->assertSame($expectedSource, $manipulator->getSourceCode()); } - public function testAddInterfaceToClassWithOtherInterface() + public function testAddInterfaceToClassWithOtherInterface(): void { $source = file_get_contents(__DIR__.'/fixtures/source/User_simple_with_interface.php'); $expectedSource = file_get_contents(__DIR__.'/fixtures/implements_interface/User_simple_with_interface.php'); @@ -762,9 +665,9 @@ public function testAddInterfaceToClassWithOtherInterface() $this->assertSame($expectedSource, $manipulator->getSourceCode()); } - public function testAddMethodBuilder() + public function testAddMethodBuilder(): void { - $source = file_get_contents(__DIR__.'/fixtures/source/legacy/User_empty.php'); + $source = file_get_contents(__DIR__.'/fixtures/source/User_empty.php'); $expectedSource = file_get_contents(__DIR__.'/fixtures/add_method/UserEmpty_with_newMethod.php'); $manipulator = new ClassSourceManipulator($source); @@ -784,7 +687,7 @@ public function testAddMethodBuilder() $this->assertSame($expectedSource, $manipulator->getSourceCode()); } - public function testAddMethodWithBody() + public function testAddMethodWithBody(): void { $source = file_get_contents(__DIR__.'/fixtures/source/EmptyController.php'); $expectedSource = file_get_contents(__DIR__.'/fixtures/add_method/Controller_with_action.php'); @@ -808,141 +711,9 @@ public function testAddMethodWithBody() $this->assertSame($expectedSource, $manipulator->getSourceCode()); } - /** - * @dataProvider getTestsForAddAnnotationToClass - */ - public function testAddAnnotationToClass(string $source, string $expectedSource) - { - $manipulator = new ClassSourceManipulator($source); - $manipulator->addAnnotationToClass('Bar\\SomeAnnotation', [ - 'message' => 'Foo', - ]); - - $this->assertEquals($expectedSource, $manipulator->getSourceCode()); - } - - public function getTestsForAddAnnotationToClass() - { - yield 'no_doc_block' => [ -<< [ -<< [ -<< [ -<<assertSame($expectedSource, $manipulator->getSourceCode()); } - public function testAddTraitWithProperty() + public function testAddTraitWithProperty(): void { - $source = file_get_contents(__DIR__.'/fixtures/source/legacy/User_simple.php'); + $source = file_get_contents(__DIR__.'/fixtures/source/User_simple.php'); $expectedSource = file_get_contents(__DIR__.'/fixtures/add_trait/User_with_prop_trait.php'); $manipulator = new ClassSourceManipulator($source); @@ -964,7 +735,7 @@ public function testAddTraitWithProperty() $this->assertSame($expectedSource, $manipulator->getSourceCode()); } - public function testAddTraitWithConstant() + public function testAddTraitWithConstant(): void { $source = file_get_contents(__DIR__.'/fixtures/source/User_with_const.php'); $expectedSource = file_get_contents(__DIR__.'/fixtures/add_trait/User_with_const_trait.php'); @@ -976,7 +747,7 @@ public function testAddTraitWithConstant() $this->assertSame($expectedSource, $manipulator->getSourceCode()); } - public function testAddTraitWithTrait() + public function testAddTraitWithTrait(): void { $source = file_get_contents(__DIR__.'/fixtures/source/User_with_trait.php'); $expectedSource = file_get_contents(__DIR__.'/fixtures/add_trait/User_with_trait_trait.php'); @@ -988,7 +759,7 @@ public function testAddTraitWithTrait() $this->assertSame($expectedSource, $manipulator->getSourceCode()); } - public function testAddTraitAlReadyExists() + public function testAddTraitAlReadyExists(): void { $source = file_get_contents(__DIR__.'/fixtures/add_trait/User_with_trait_trait.php'); $expectedSource = file_get_contents(__DIR__.'/fixtures/add_trait/User_with_trait_trait.php'); @@ -1000,9 +771,9 @@ public function testAddTraitAlReadyExists() $this->assertSame($expectedSource, $manipulator->getSourceCode()); } - public function testAddConstructor() + public function testAddConstructor(): void { - $source = file_get_contents(__DIR__.'/fixtures/source/legacy/User_empty.php'); + $source = file_get_contents(__DIR__.'/fixtures/source/User_empty.php'); $expectedSource = file_get_contents(__DIR__.'/fixtures/add_constructor/UserEmpty_with_constructor.php'); $manipulator = new ClassSourceManipulator($source); @@ -1020,9 +791,9 @@ public function testAddConstructor() $this->assertSame($expectedSource, $manipulator->getSourceCode()); } - public function testAddConstructorInClassContainsPropsAndMethods() + public function testAddConstructorInClassContainsPropsAndMethods(): void { - $source = file_get_contents(__DIR__.'/fixtures/source/legacy/User_simple.php'); + $source = file_get_contents(__DIR__.'/fixtures/source/User_simple.php'); $expectedSource = file_get_contents(__DIR__.'/fixtures/add_constructor/UserSimple_with_constructor.php'); $manipulator = new ClassSourceManipulator($source); @@ -1040,7 +811,7 @@ public function testAddConstructorInClassContainsPropsAndMethods() $this->assertSame($expectedSource, $manipulator->getSourceCode()); } - public function testAddConstructorInClassContainsOnlyConstants() + public function testAddConstructorInClassContainsOnlyConstants(): void { $source = file_get_contents(__DIR__.'/fixtures/source/User_with_const.php'); $expectedSource = file_get_contents(__DIR__.'/fixtures/add_constructor/User_with_constructor_constante.php'); @@ -1060,7 +831,7 @@ public function testAddConstructorInClassContainsOnlyConstants() $this->assertSame($expectedSource, $manipulator->getSourceCode()); } - public function testAddConstructorInClassContainsConstructor() + public function testAddConstructorInClassContainsConstructor(): void { $source = file_get_contents(__DIR__.'/fixtures/source/User_with_constructor.php'); diff --git a/tests/Util/fixtures/add_constructor/UserSimple_with_constructor.php b/tests/Util/fixtures/add_constructor/UserSimple_with_constructor.php index 92889e86b..07417b955 100644 --- a/tests/Util/fixtures/add_constructor/UserSimple_with_constructor.php +++ b/tests/Util/fixtures/add_constructor/UserSimple_with_constructor.php @@ -4,16 +4,12 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity() - */ +#[ORM\Entity] class User { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] private $id; public function __construct(object $someObjectParam, string $someStringParam) diff --git a/tests/Util/fixtures/add_entity_field/legacy/User_simple.php b/tests/Util/fixtures/add_entity_field/legacy/User_simple.php deleted file mode 100644 index 6c528dbe0..000000000 --- a/tests/Util/fixtures/add_entity_field/legacy/User_simple.php +++ /dev/null @@ -1,40 +0,0 @@ -id; - } - - public function getFooProp(): ?string - { - return $this->fooProp; - } - - public function setFooProp(string $fooProp): self - { - $this->fooProp = $fooProp; - - return $this; - } -} diff --git a/tests/Util/fixtures/add_entity_field/legacy/User_simple_datetime.php b/tests/Util/fixtures/add_entity_field/legacy/User_simple_datetime.php deleted file mode 100644 index 06ca3506c..000000000 --- a/tests/Util/fixtures/add_entity_field/legacy/User_simple_datetime.php +++ /dev/null @@ -1,40 +0,0 @@ -id; - } - - public function getCreatedAt(): ?\DateTimeInterface - { - return $this->createdAt; - } - - public function setCreatedAt(?\DateTimeInterface $createdAt): self - { - $this->createdAt = $createdAt; - - return $this; - } -} diff --git a/tests/Util/fixtures/add_entity_field/legacy/User_simple_object.php b/tests/Util/fixtures/add_entity_field/legacy/User_simple_object.php deleted file mode 100644 index 9a17bee32..000000000 --- a/tests/Util/fixtures/add_entity_field/legacy/User_simple_object.php +++ /dev/null @@ -1,40 +0,0 @@ -id; - } - - public function getSomeObject(): ?object - { - return $this->someObject; - } - - public function setSomeObject(object $someObject): self - { - $this->someObject = $someObject; - - return $this; - } -} diff --git a/tests/Util/fixtures/add_entity_field/legacy/User_simple_prop_already_exists.php b/tests/Util/fixtures/add_entity_field/legacy/User_simple_prop_already_exists.php deleted file mode 100644 index d4ae050a1..000000000 --- a/tests/Util/fixtures/add_entity_field/legacy/User_simple_prop_already_exists.php +++ /dev/null @@ -1,46 +0,0 @@ -id; - } - - /** - * Some custom comments - * - * @return string - */ - public function getFirstName() - { - // some custom comment - return $this->firstName; - } - - public function setFirstName(string $firstName): self - { - $this->firstName = $firstName; - - return $this; - } -} diff --git a/tests/Util/fixtures/add_entity_field/legacy/User_simple_prop_zero.php b/tests/Util/fixtures/add_entity_field/legacy/User_simple_prop_zero.php deleted file mode 100644 index 846c75e3d..000000000 --- a/tests/Util/fixtures/add_entity_field/legacy/User_simple_prop_zero.php +++ /dev/null @@ -1,40 +0,0 @@ -id; - } - - public function getDecimal(): ?string - { - return $this->decimal; - } - - public function setDecimal(string $decimal): self - { - $this->decimal = $decimal; - - return $this; - } -} diff --git a/tests/Util/fixtures/add_getter/User_no_props.php b/tests/Util/fixtures/add_getter/User_no_props.php index 71573267d..a7d6586d5 100644 --- a/tests/Util/fixtures/add_getter/User_no_props.php +++ b/tests/Util/fixtures/add_getter/User_no_props.php @@ -5,9 +5,7 @@ use App\Repository\UserRepository; use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity(repositoryClass=UserRepository::class) - */ +#[ORM\Entity(repositoryClass: UserRepository::class)] class User // extra space to keep things interesting { diff --git a/tests/Util/fixtures/add_getter/User_simple.php b/tests/Util/fixtures/add_getter/User_simple.php index 359a2ebb1..4485f6689 100644 --- a/tests/Util/fixtures/add_getter/User_simple.php +++ b/tests/Util/fixtures/add_getter/User_simple.php @@ -4,16 +4,12 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity() - */ +#[ORM\Entity] class User { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] private $id; public function getId(): ?int diff --git a/tests/Util/fixtures/add_getter/User_simple_bool.php b/tests/Util/fixtures/add_getter/User_simple_bool.php index 1b0eb7c41..efb2846db 100644 --- a/tests/Util/fixtures/add_getter/User_simple_bool.php +++ b/tests/Util/fixtures/add_getter/User_simple_bool.php @@ -4,16 +4,12 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity() - */ +#[ORM\Entity] class User { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] private $id; public function getId(): ?int diff --git a/tests/Util/fixtures/add_many_to_many_relation/legacy/User_simple_inverse.php b/tests/Util/fixtures/add_many_to_many_relation/legacy/User_simple_inverse.php deleted file mode 100644 index fddd639f6..000000000 --- a/tests/Util/fixtures/add_many_to_many_relation/legacy/User_simple_inverse.php +++ /dev/null @@ -1,62 +0,0 @@ -recipes = new ArrayCollection(); - } - - public function getId(): ?int - { - return $this->id; - } - - /** - * @return Collection - */ - public function getRecipes(): Collection - { - return $this->recipes; - } - - public function addRecipe(Recipe $recipe): self - { - if (!$this->recipes->contains($recipe)) { - $this->recipes[] = $recipe; - $recipe->addFood($this); - } - - return $this; - } - - public function removeRecipe(Recipe $recipe): self - { - if ($this->recipes->removeElement($recipe)) { - $recipe->removeFood($this); - } - - return $this; - } -} diff --git a/tests/Util/fixtures/add_many_to_many_relation/legacy/User_simple_no_inverse.php b/tests/Util/fixtures/add_many_to_many_relation/legacy/User_simple_no_inverse.php deleted file mode 100644 index 82c080971..000000000 --- a/tests/Util/fixtures/add_many_to_many_relation/legacy/User_simple_no_inverse.php +++ /dev/null @@ -1,59 +0,0 @@ -recipes = new ArrayCollection(); - } - - public function getId(): ?int - { - return $this->id; - } - - /** - * @return Collection - */ - public function getRecipes(): Collection - { - return $this->recipes; - } - - public function addRecipe(Recipe $recipe): self - { - if (!$this->recipes->contains($recipe)) { - $this->recipes[] = $recipe; - } - - return $this; - } - - public function removeRecipe(Recipe $recipe): self - { - $this->recipes->removeElement($recipe); - - return $this; - } -} diff --git a/tests/Util/fixtures/add_many_to_many_relation/legacy/User_simple_owning.php b/tests/Util/fixtures/add_many_to_many_relation/legacy/User_simple_owning.php deleted file mode 100644 index 65afb0cbc..000000000 --- a/tests/Util/fixtures/add_many_to_many_relation/legacy/User_simple_owning.php +++ /dev/null @@ -1,59 +0,0 @@ -recipes = new ArrayCollection(); - } - - public function getId(): ?int - { - return $this->id; - } - - /** - * @return Collection - */ - public function getRecipes(): Collection - { - return $this->recipes; - } - - public function addRecipe(Recipe $recipe): self - { - if (!$this->recipes->contains($recipe)) { - $this->recipes[] = $recipe; - } - - return $this; - } - - public function removeRecipe(Recipe $recipe): self - { - $this->recipes->removeElement($recipe); - - return $this; - } -} diff --git a/tests/Util/fixtures/add_many_to_one_relation/legacy/User_empty_other_namespace.php b/tests/Util/fixtures/add_many_to_one_relation/legacy/User_empty_other_namespace.php deleted file mode 100644 index 0a9e5b220..000000000 --- a/tests/Util/fixtures/add_many_to_one_relation/legacy/User_empty_other_namespace.php +++ /dev/null @@ -1,25 +0,0 @@ -category; - } - - public function setCategory(?Category $category): self - { - $this->category = $category; - - return $this; - } -} diff --git a/tests/Util/fixtures/add_many_to_one_relation/legacy/User_simple_no_inverse.php b/tests/Util/fixtures/add_many_to_one_relation/legacy/User_simple_no_inverse.php deleted file mode 100644 index 8ddae8637..000000000 --- a/tests/Util/fixtures/add_many_to_one_relation/legacy/User_simple_no_inverse.php +++ /dev/null @@ -1,40 +0,0 @@ -id; - } - - public function getCategory(): ?Category - { - return $this->category; - } - - public function setCategory(?Category $category): self - { - $this->category = $category; - - return $this; - } -} diff --git a/tests/Util/fixtures/add_many_to_one_relation/legacy/User_simple_not_nullable.php b/tests/Util/fixtures/add_many_to_one_relation/legacy/User_simple_not_nullable.php deleted file mode 100644 index 59de47292..000000000 --- a/tests/Util/fixtures/add_many_to_one_relation/legacy/User_simple_not_nullable.php +++ /dev/null @@ -1,41 +0,0 @@ -id; - } - - public function getCategory(): ?Category - { - return $this->category; - } - - public function setCategory(?Category $category): self - { - $this->category = $category; - - return $this; - } -} diff --git a/tests/Util/fixtures/add_many_to_one_relation/legacy/User_simple_nullable.php b/tests/Util/fixtures/add_many_to_one_relation/legacy/User_simple_nullable.php deleted file mode 100644 index 311d30afd..000000000 --- a/tests/Util/fixtures/add_many_to_one_relation/legacy/User_simple_nullable.php +++ /dev/null @@ -1,40 +0,0 @@ -id; - } - - public function getCategory(): ?Category - { - return $this->category; - } - - public function setCategory(?Category $category): self - { - $this->category = $category; - - return $this; - } -} diff --git a/tests/Util/fixtures/add_many_to_one_relation/legacy/User_simple_other_namespace.php b/tests/Util/fixtures/add_many_to_one_relation/legacy/User_simple_other_namespace.php deleted file mode 100644 index 633067951..000000000 --- a/tests/Util/fixtures/add_many_to_one_relation/legacy/User_simple_other_namespace.php +++ /dev/null @@ -1,41 +0,0 @@ -id; - } - - public function getCategory(): ?Category - { - return $this->category; - } - - public function setCategory(?Category $category): self - { - $this->category = $category; - - return $this; - } -} diff --git a/tests/Util/fixtures/add_many_to_one_relation/legacy/User_with_relation_same_and_other_namespaces.php b/tests/Util/fixtures/add_many_to_one_relation/legacy/User_with_relation_same_and_other_namespaces.php deleted file mode 100644 index 264def97f..000000000 --- a/tests/Util/fixtures/add_many_to_one_relation/legacy/User_with_relation_same_and_other_namespaces.php +++ /dev/null @@ -1,42 +0,0 @@ -category; - } - - public function setCategory(?Category $category): self - { - $this->category = $category; - - return $this; - } - - public function getSubCategory(): ?\App\Entity\SubDirectory\Category - { - return $this->subCategory; - } - - public function setSubCategory(?\App\Entity\SubDirectory\Category $subCategory): self - { - $this->subCategory = $subCategory; - - return $this; - } -} diff --git a/tests/Util/fixtures/add_one_to_many_relation/legacy/User_simple.php b/tests/Util/fixtures/add_one_to_many_relation/legacy/User_simple.php deleted file mode 100644 index fc0c27ec3..000000000 --- a/tests/Util/fixtures/add_one_to_many_relation/legacy/User_simple.php +++ /dev/null @@ -1,65 +0,0 @@ -avatarPhotos = new ArrayCollection(); - } - - public function getId(): ?int - { - return $this->id; - } - - /** - * @return Collection - */ - public function getAvatarPhotos(): Collection - { - return $this->avatarPhotos; - } - - public function addAvatarPhoto(UserAvatarPhoto $avatarPhoto): self - { - if (!$this->avatarPhotos->contains($avatarPhoto)) { - $this->avatarPhotos[] = $avatarPhoto; - $avatarPhoto->setUser($this); - } - - return $this; - } - - public function removeAvatarPhoto(UserAvatarPhoto $avatarPhoto): self - { - if ($this->avatarPhotos->removeElement($avatarPhoto)) { - // set the owning side to null (unless already changed) - if ($avatarPhoto->getUser() === $this) { - $avatarPhoto->setUser(null); - } - } - - return $this; - } -} diff --git a/tests/Util/fixtures/add_one_to_many_relation/legacy/User_simple_orphan_removal.php b/tests/Util/fixtures/add_one_to_many_relation/legacy/User_simple_orphan_removal.php deleted file mode 100644 index ae95a5bd2..000000000 --- a/tests/Util/fixtures/add_one_to_many_relation/legacy/User_simple_orphan_removal.php +++ /dev/null @@ -1,65 +0,0 @@ -avatarPhotos = new ArrayCollection(); - } - - public function getId(): ?int - { - return $this->id; - } - - /** - * @return Collection - */ - public function getAvatarPhotos(): Collection - { - return $this->avatarPhotos; - } - - public function addAvatarPhoto(UserAvatarPhoto $avatarPhoto): self - { - if (!$this->avatarPhotos->contains($avatarPhoto)) { - $this->avatarPhotos[] = $avatarPhoto; - $avatarPhoto->setUser($this); - } - - return $this; - } - - public function removeAvatarPhoto(UserAvatarPhoto $avatarPhoto): self - { - if ($this->avatarPhotos->removeElement($avatarPhoto)) { - // set the owning side to null (unless already changed) - if ($avatarPhoto->getUser() === $this) { - $avatarPhoto->setUser(null); - } - } - - return $this; - } -} diff --git a/tests/Util/fixtures/add_one_to_many_relation/legacy/User_with_use_statements.php b/tests/Util/fixtures/add_one_to_many_relation/legacy/User_with_use_statements.php deleted file mode 100644 index 78d158a78..000000000 --- a/tests/Util/fixtures/add_one_to_many_relation/legacy/User_with_use_statements.php +++ /dev/null @@ -1,67 +0,0 @@ -avatarPhotos = new ArrayCollection(); - } - - public function getId(): ?int - { - return $this->id; - } - - /** - * @return Collection - */ - public function getAvatarPhotos(): Collection - { - return $this->avatarPhotos; - } - - public function addAvatarPhoto(UserAvatarPhoto $avatarPhoto): self - { - if (!$this->avatarPhotos->contains($avatarPhoto)) { - $this->avatarPhotos[] = $avatarPhoto; - $avatarPhoto->setUser($this); - } - - return $this; - } - - public function removeAvatarPhoto(UserAvatarPhoto $avatarPhoto): self - { - if ($this->avatarPhotos->removeElement($avatarPhoto)) { - // set the owning side to null (unless already changed) - if ($avatarPhoto->getUser() === $this) { - $avatarPhoto->setUser(null); - } - } - - return $this; - } -} diff --git a/tests/Util/fixtures/add_one_to_one_relation/legacy/UserProfile_simple_inverse.php b/tests/Util/fixtures/add_one_to_one_relation/legacy/UserProfile_simple_inverse.php deleted file mode 100644 index 6ca0ec0d6..000000000 --- a/tests/Util/fixtures/add_one_to_one_relation/legacy/UserProfile_simple_inverse.php +++ /dev/null @@ -1,50 +0,0 @@ -id; - } - - public function getUser(): ?User - { - return $this->user; - } - - public function setUser(?User $user): self - { - // unset the owning side of the relation if necessary - if ($user === null && $this->user !== null) { - $this->user->setUserProfile(null); - } - - // set the owning side of the relation if necessary - if ($user !== null && $user->getUserProfile() !== $this) { - $user->setUserProfile($this); - } - - $this->user = $user; - - return $this; - } -} diff --git a/tests/Util/fixtures/add_one_to_one_relation/legacy/UserProfile_simple_inverse_not_nullable.php b/tests/Util/fixtures/add_one_to_one_relation/legacy/UserProfile_simple_inverse_not_nullable.php deleted file mode 100644 index e52100ee3..000000000 --- a/tests/Util/fixtures/add_one_to_one_relation/legacy/UserProfile_simple_inverse_not_nullable.php +++ /dev/null @@ -1,45 +0,0 @@ -id; - } - - public function getUser(): ?User - { - return $this->user; - } - - public function setUser(User $user): self - { - // set the owning side of the relation if necessary - if ($user->getUserProfile() !== $this) { - $user->setUserProfile($this); - } - - $this->user = $user; - - return $this; - } -} diff --git a/tests/Util/fixtures/add_one_to_one_relation/legacy/User_simple_no_inverse.php b/tests/Util/fixtures/add_one_to_one_relation/legacy/User_simple_no_inverse.php deleted file mode 100644 index 0f00f5bc5..000000000 --- a/tests/Util/fixtures/add_one_to_one_relation/legacy/User_simple_no_inverse.php +++ /dev/null @@ -1,40 +0,0 @@ -id; - } - - public function getUserProfile(): ?UserProfile - { - return $this->userProfile; - } - - public function setUserProfile(?UserProfile $userProfile): self - { - $this->userProfile = $userProfile; - - return $this; - } -} diff --git a/tests/Util/fixtures/add_one_to_one_relation/legacy/User_simple_no_inverse_not_nullable.php b/tests/Util/fixtures/add_one_to_one_relation/legacy/User_simple_no_inverse_not_nullable.php deleted file mode 100644 index 913d5efd6..000000000 --- a/tests/Util/fixtures/add_one_to_one_relation/legacy/User_simple_no_inverse_not_nullable.php +++ /dev/null @@ -1,41 +0,0 @@ -id; - } - - public function getUserProfile(): ?UserProfile - { - return $this->userProfile; - } - - public function setUserProfile(UserProfile $userProfile): self - { - $this->userProfile = $userProfile; - - return $this; - } -} diff --git a/tests/Util/fixtures/add_one_to_one_relation/legacy/User_simple_owning.php b/tests/Util/fixtures/add_one_to_one_relation/legacy/User_simple_owning.php deleted file mode 100644 index f05664cc3..000000000 --- a/tests/Util/fixtures/add_one_to_one_relation/legacy/User_simple_owning.php +++ /dev/null @@ -1,40 +0,0 @@ -id; - } - - public function getUserProfile(): ?UserProfile - { - return $this->userProfile; - } - - public function setUserProfile(?UserProfile $userProfile): self - { - $this->userProfile = $userProfile; - - return $this; - } -} diff --git a/tests/Util/fixtures/add_one_to_one_relation/legacy/User_simple_self.php b/tests/Util/fixtures/add_one_to_one_relation/legacy/User_simple_self.php deleted file mode 100644 index fadc4a199..000000000 --- a/tests/Util/fixtures/add_one_to_one_relation/legacy/User_simple_self.php +++ /dev/null @@ -1,40 +0,0 @@ -id; - } - - public function getEmbeddedUser(): ?self - { - return $this->embeddedUser; - } - - public function setEmbeddedUser(?self $embeddedUser): self - { - $this->embeddedUser = $embeddedUser; - - return $this; - } -} diff --git a/tests/Util/fixtures/add_one_to_one_relation/legacy/User_with_use_statements_avoid_duplicate_use.php b/tests/Util/fixtures/add_one_to_one_relation/legacy/User_with_use_statements_avoid_duplicate_use.php deleted file mode 100644 index 045ebe968..000000000 --- a/tests/Util/fixtures/add_one_to_one_relation/legacy/User_with_use_statements_avoid_duplicate_use.php +++ /dev/null @@ -1,43 +0,0 @@ -id; - } - - public function getUserProfile(): ?\App\OtherEntity\UserProfile - { - return $this->userProfile; - } - - public function setUserProfile(?\App\OtherEntity\UserProfile $userProfile): self - { - $this->userProfile = $userProfile; - - return $this; - } -} diff --git a/tests/Util/fixtures/add_one_to_one_relation/legacy/User_with_use_statements_avoid_duplicate_use_alias.php b/tests/Util/fixtures/add_one_to_one_relation/legacy/User_with_use_statements_avoid_duplicate_use_alias.php deleted file mode 100644 index 4478065d7..000000000 --- a/tests/Util/fixtures/add_one_to_one_relation/legacy/User_with_use_statements_avoid_duplicate_use_alias.php +++ /dev/null @@ -1,43 +0,0 @@ -id; - } - - public function getCategory(): ?\App\OtherEntity\Category - { - return $this->category; - } - - public function setCategory(?\App\OtherEntity\Category $category): self - { - $this->category = $category; - - return $this; - } -} diff --git a/tests/Util/fixtures/add_property/User_no_props.php b/tests/Util/fixtures/add_property/User_no_props.php index 43507d9b6..015341163 100644 --- a/tests/Util/fixtures/add_property/User_no_props.php +++ b/tests/Util/fixtures/add_property/User_no_props.php @@ -5,9 +5,7 @@ use App\Repository\UserRepository; use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity(repositoryClass=UserRepository::class) - */ +#[ORM\Entity(repositoryClass: UserRepository::class)] class User // extra space to keep things interesting { diff --git a/tests/Util/fixtures/add_property/User_no_props_constants.php b/tests/Util/fixtures/add_property/User_no_props_constants.php index a200061dc..4f5ec194d 100644 --- a/tests/Util/fixtures/add_property/User_no_props_constants.php +++ b/tests/Util/fixtures/add_property/User_no_props_constants.php @@ -4,9 +4,7 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity() - */ +#[ORM\Entity] class User { const FOO = 'bar'; diff --git a/tests/Util/fixtures/add_property/User_simple.php b/tests/Util/fixtures/add_property/User_simple.php index 43c3e0be8..068893fb2 100644 --- a/tests/Util/fixtures/add_property/User_simple.php +++ b/tests/Util/fixtures/add_property/User_simple.php @@ -4,16 +4,12 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity() - */ +#[ORM\Entity] class User { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] private $id; private $fooProp; diff --git a/tests/Util/fixtures/add_setter/User_no_props.php b/tests/Util/fixtures/add_setter/User_no_props.php index b11886744..cb262e569 100644 --- a/tests/Util/fixtures/add_setter/User_no_props.php +++ b/tests/Util/fixtures/add_setter/User_no_props.php @@ -5,9 +5,7 @@ use App\Repository\UserRepository; use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity(repositoryClass=UserRepository::class) - */ +#[ORM\Entity(repositoryClass: UserRepository::class)] class User // extra space to keep things interesting { diff --git a/tests/Util/fixtures/add_setter/User_simple.php b/tests/Util/fixtures/add_setter/User_simple.php index 83af6717b..04bc53747 100644 --- a/tests/Util/fixtures/add_setter/User_simple.php +++ b/tests/Util/fixtures/add_setter/User_simple.php @@ -4,16 +4,12 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity() - */ +#[ORM\Entity] class User { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] private $id; public function getId(): ?int diff --git a/tests/Util/fixtures/add_trait/User_with_prop_trait.php b/tests/Util/fixtures/add_trait/User_with_prop_trait.php index 58df85c93..4768e33c7 100644 --- a/tests/Util/fixtures/add_trait/User_with_prop_trait.php +++ b/tests/Util/fixtures/add_trait/User_with_prop_trait.php @@ -5,18 +5,14 @@ use App\TestTrait; use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity() - */ +#[ORM\Entity] class User { use TestTrait; - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] private $id; public function getId(): ?int diff --git a/tests/Util/fixtures/clear_classNode_stmts/UserProfile_stmts_clear.php b/tests/Util/fixtures/clear_classNode_stmts/UserProfile_stmts_clear.php index 700a79ffa..123b37a1a 100644 --- a/tests/Util/fixtures/clear_classNode_stmts/UserProfile_stmts_clear.php +++ b/tests/Util/fixtures/clear_classNode_stmts/UserProfile_stmts_clear.php @@ -4,9 +4,7 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity() - */ +#[ORM\Entity] class UserProfile { } diff --git a/tests/Util/fixtures/implements_interface/User_simple.php b/tests/Util/fixtures/implements_interface/User_simple.php index 5c8d5ea32..af8592406 100644 --- a/tests/Util/fixtures/implements_interface/User_simple.php +++ b/tests/Util/fixtures/implements_interface/User_simple.php @@ -5,16 +5,12 @@ use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Security\Core\User\UserInterface; -/** - * @ORM\Entity() - */ +#[ORM\Entity] class User implements UserInterface { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] private $id; public function getId(): ?int diff --git a/tests/Util/fixtures/implements_interface/User_simple_with_interface.php b/tests/Util/fixtures/implements_interface/User_simple_with_interface.php index 18075f0ba..a3089dba8 100644 --- a/tests/Util/fixtures/implements_interface/User_simple_with_interface.php +++ b/tests/Util/fixtures/implements_interface/User_simple_with_interface.php @@ -5,16 +5,12 @@ use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Security\Core\User\UserInterface; -/** - * @ORM\Entity() - */ +#[ORM\Entity] class User implements DummyInterface, UserInterface { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] private $id; public function getId(): ?int diff --git a/tests/Util/fixtures/source/ProductWithTabs.php b/tests/Util/fixtures/source/ProductWithTabs.php index bf0e3dda3..5969a6fd4 100644 --- a/tests/Util/fixtures/source/ProductWithTabs.php +++ b/tests/Util/fixtures/source/ProductWithTabs.php @@ -5,15 +5,11 @@ use App\Repository\ProductRepository; use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity(repositoryClass=ProductRepository::class) - */ +#[ORM\Entity(repositoryClass: ProductRepository::class)] class Product { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] private $id; } diff --git a/tests/Util/fixtures/source/User_no_props.php b/tests/Util/fixtures/source/User_no_props.php index 46b3bacf5..739b91af4 100644 --- a/tests/Util/fixtures/source/User_no_props.php +++ b/tests/Util/fixtures/source/User_no_props.php @@ -5,9 +5,7 @@ use App\Repository\UserRepository; use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity(repositoryClass=UserRepository::class) - */ +#[ORM\Entity(repositoryClass: UserRepository::class)] class User // extra space to keep things interesting { diff --git a/tests/Util/fixtures/source/User_no_props_constants.php b/tests/Util/fixtures/source/User_no_props_constants.php index ca830f3a5..ed619759b 100644 --- a/tests/Util/fixtures/source/User_no_props_constants.php +++ b/tests/Util/fixtures/source/User_no_props_constants.php @@ -4,9 +4,7 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity() - */ +#[ORM\Entity] class User { const FOO = 'bar'; diff --git a/tests/Util/fixtures/source/User_only_props.php b/tests/Util/fixtures/source/User_only_props.php index a6b52af50..d73260cf1 100644 --- a/tests/Util/fixtures/source/User_only_props.php +++ b/tests/Util/fixtures/source/User_only_props.php @@ -4,16 +4,12 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity() - */ +#[ORM\Entity] class User { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] private $id; /** diff --git a/tests/Util/fixtures/source/User_simple_with_interface.php b/tests/Util/fixtures/source/User_simple_with_interface.php index 0d287b88f..96c6df6e9 100644 --- a/tests/Util/fixtures/source/User_simple_with_interface.php +++ b/tests/Util/fixtures/source/User_simple_with_interface.php @@ -4,16 +4,12 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity() - */ +#[ORM\Entity] class User implements DummyInterface { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] private $id; public function getId(): ?int diff --git a/tests/Util/fixtures/source/legacy/UserProfile_simple.php b/tests/Util/fixtures/source/legacy/UserProfile_simple.php deleted file mode 100644 index ed9730300..000000000 --- a/tests/Util/fixtures/source/legacy/UserProfile_simple.php +++ /dev/null @@ -1,23 +0,0 @@ -id; - } -} diff --git a/tests/Util/fixtures/source/legacy/User_empty.php b/tests/Util/fixtures/source/legacy/User_empty.php deleted file mode 100644 index fe362adb5..000000000 --- a/tests/Util/fixtures/source/legacy/User_empty.php +++ /dev/null @@ -1,5 +0,0 @@ -id; - } -} diff --git a/tests/Util/fixtures/source/legacy/User_some_props.php b/tests/Util/fixtures/source/legacy/User_some_props.php deleted file mode 100644 index 7b95b36c2..000000000 --- a/tests/Util/fixtures/source/legacy/User_some_props.php +++ /dev/null @@ -1,39 +0,0 @@ -id; - } - - /** - * Some custom comments - * - * @return string - */ - public function getFirstName() - { - // some custom comment - return $this->firstName; - } -} diff --git a/tests/Util/fixtures/source/legacy/User_with_relation.php b/tests/Util/fixtures/source/legacy/User_with_relation.php deleted file mode 100644 index 23a90e648..000000000 --- a/tests/Util/fixtures/source/legacy/User_with_relation.php +++ /dev/null @@ -1,25 +0,0 @@ -category; - } - - public function setCategory(?Category $category): self - { - $this->category = $category; - - return $this; - } -} diff --git a/tests/Util/fixtures/source/legacy/User_with_use_statements.php b/tests/Util/fixtures/source/legacy/User_with_use_statements.php deleted file mode 100644 index 9db2b7fc9..000000000 --- a/tests/Util/fixtures/source/legacy/User_with_use_statements.php +++ /dev/null @@ -1,26 +0,0 @@ -id; - } -} diff --git a/tests/Util/fixtures/with_tabs/ProductWithTabs.php b/tests/Util/fixtures/with_tabs/ProductWithTabs.php index 75142c422..5d570545c 100644 --- a/tests/Util/fixtures/with_tabs/ProductWithTabs.php +++ b/tests/Util/fixtures/with_tabs/ProductWithTabs.php @@ -5,21 +5,15 @@ use App\Repository\ProductRepository; use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity(repositoryClass=ProductRepository::class) - */ +#[ORM\Entity(repositoryClass: ProductRepository::class)] class Product { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ - private $id; + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] + private $id; - /** - * @ORM\Column(type="string", length=255) - */ + #[ORM\Column(type: 'string', length: 255)] private $name; public function getId(): int