From 8f20443e4c1260e4345e939fbac75b5a5a97a78a Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Wed, 18 May 2022 15:55:32 -0400 Subject: [PATCH 01/11] WIP - implement types and constructor property promotion for utilities --- src/Resources/config/services.xml | 1 - src/Util/AutoloaderUtil.php | 8 +------- src/Util/ClassDetails.php | 5 +---- src/Util/ClassNameDetails.php | 12 ++++++------ src/Util/ClassNameValue.php | 7 +------ src/Util/ComposeFileManipulator.php | 3 +-- src/Util/TemplateComponentGenerator.php | 7 ------- src/Util/UseStatementGenerator.php | 7 ++----- src/Util/YamlSourceManipulator.php | 5 +---- 9 files changed, 13 insertions(+), 42 deletions(-) diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index a61bf9e19..ed3438e8e 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -77,7 +77,6 @@ - diff --git a/src/Util/AutoloaderUtil.php b/src/Util/AutoloaderUtil.php index 5338637ce..f5c5199e8 100644 --- a/src/Util/AutoloaderUtil.php +++ b/src/Util/AutoloaderUtil.php @@ -20,14 +20,8 @@ */ class AutoloaderUtil { - /** - * @var ComposerAutoloaderFinder - */ - private $autoloaderFinder; - - public function __construct(ComposerAutoloaderFinder $autoloaderFinder) + public function __construct(private ComposerAutoloaderFinder $autoloaderFinder) { - $this->autoloaderFinder = $autoloaderFinder; } /** diff --git a/src/Util/ClassDetails.php b/src/Util/ClassDetails.php index 9ee94dda3..3eeb1798c 100644 --- a/src/Util/ClassDetails.php +++ b/src/Util/ClassDetails.php @@ -16,11 +16,8 @@ */ final class ClassDetails { - private $fullClassName; - - public function __construct(string $fullClassName) + public function __construct(private string $fullClassName) { - $this->fullClassName = $fullClassName; } /** diff --git a/src/Util/ClassNameDetails.php b/src/Util/ClassNameDetails.php index e0c282576..56184dd94 100644 --- a/src/Util/ClassNameDetails.php +++ b/src/Util/ClassNameDetails.php @@ -15,13 +15,13 @@ final class ClassNameDetails { - private $fullClassName; - private $namespacePrefix; - private $suffix; + private ?string $suffix; - public function __construct(string $fullClassName, string $namespacePrefix, string $suffix = null) - { - $this->fullClassName = $fullClassName; + public function __construct( + private string $fullClassName, + private string $namespacePrefix, + string $suffix = null + ) { $this->namespacePrefix = trim($namespacePrefix, '\\'); $this->suffix = $suffix; } diff --git a/src/Util/ClassNameValue.php b/src/Util/ClassNameValue.php index d8c4a8db0..4f56cd095 100644 --- a/src/Util/ClassNameValue.php +++ b/src/Util/ClassNameValue.php @@ -18,13 +18,8 @@ */ final class ClassNameValue { - private $typeHint; - private $fullClassName; - - public function __construct(string $typeHint, string $fullClassName) + public function __construct(private string $typeHint, private string $fullClassName) { - $this->typeHint = $typeHint; - $this->fullClassName = $fullClassName; } public function getShortName(): string diff --git a/src/Util/ComposeFileManipulator.php b/src/Util/ComposeFileManipulator.php index 339899bbd..30dbf9dae 100644 --- a/src/Util/ComposeFileManipulator.php +++ b/src/Util/ComposeFileManipulator.php @@ -26,8 +26,7 @@ class ComposeFileManipulator { public const COMPOSE_FILE_VERSION = '3.7'; - /** @var YamlSourceManipulator */ - private $manipulator; + private YamlSourceManipulator $manipulator; public function __construct(string $contents) { diff --git a/src/Util/TemplateComponentGenerator.php b/src/Util/TemplateComponentGenerator.php index 0f4e444dd..5b8bbd566 100644 --- a/src/Util/TemplateComponentGenerator.php +++ b/src/Util/TemplateComponentGenerator.php @@ -21,13 +21,6 @@ */ final class TemplateComponentGenerator { - private $phpCompatUtil; - - public function __construct(PhpCompatUtil $phpCompatUtil) - { - $this->phpCompatUtil = $phpCompatUtil; - } - public function generateRouteForControllerMethod(string $routePath, string $routeName, array $methods = [], bool $indent = true, bool $trailingNewLine = true): string { $attribute = sprintf('%s#[Route(\'%s\', name: \'%s\'', $indent ? ' ' : null, $routePath, $routeName); diff --git a/src/Util/UseStatementGenerator.php b/src/Util/UseStatementGenerator.php index ccc5cbff2..6b155057f 100644 --- a/src/Util/UseStatementGenerator.php +++ b/src/Util/UseStatementGenerator.php @@ -20,8 +20,6 @@ */ final class UseStatementGenerator implements \Stringable { - private $classesToBeImported; - /** * For use statements that contain aliases, the $classesToBeImported array * may contain an array(s) like [\Some\Class::class => 'ZYX']. The generated @@ -30,9 +28,8 @@ final class UseStatementGenerator implements \Stringable * * @param string[]|array $classesToBeImported */ - public function __construct(array $classesToBeImported) + public function __construct(private array $classesToBeImported) { - $this->classesToBeImported = $classesToBeImported; } public function __toString(): string @@ -72,7 +69,7 @@ public function __toString(): string /** * @param string|string[]|array $className */ - public function addUseStatement($className): void + public function addUseStatement(array|string $className): void { if (\is_array($className)) { $this->classesToBeImported = array_merge($this->classesToBeImported, $className); diff --git a/src/Util/YamlSourceManipulator.php b/src/Util/YamlSourceManipulator.php index 90b8914ca..70cab28cd 100644 --- a/src/Util/YamlSourceManipulator.php +++ b/src/Util/YamlSourceManipulator.php @@ -38,8 +38,6 @@ class YamlSourceManipulator * @var LoggerInterface|null */ private $logger; - - private $contents; private $currentData; private $currentPosition = 0; @@ -50,9 +48,8 @@ class YamlSourceManipulator private $arrayFormatForDepths = []; private $arrayTypeForDepths = []; - public function __construct(string $contents) + public function __construct(private string $contents) { - $this->contents = $contents; $this->currentData = Yaml::parse($contents); if (!\is_array($this->currentData)) { From 890fe118c5bbce63f461c08e2901ad8421c9fbc1 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Wed, 18 May 2022 16:07:52 -0400 Subject: [PATCH 02/11] csm property types --- src/Util/ClassSourceManipulator.php | 42 ++++++++++++++++------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/Util/ClassSourceManipulator.php b/src/Util/ClassSourceManipulator.php index 8bb2b545b..49003896d 100644 --- a/src/Util/ClassSourceManipulator.php +++ b/src/Util/ClassSourceManipulator.php @@ -46,25 +46,29 @@ 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 $sourceCode; - private $oldStmts; - private $oldTokens; - private $newStmts; - - private $pendingComments = []; - - public function __construct(string $sourceCode, bool $overwrite = false, bool $useAnnotations = true, bool $fluentMutators = true, bool $useAttributesForDoctrineMapping = false) - { + private bool $overwrite; + private bool $useAnnotations; + private bool $fluentMutators; + private bool $useAttributesForDoctrineMapping; + private Parser\Php7 $parser; + private Lexer\Emulative $lexer; + private PrettyPrinter $printer; + private ?ConsoleStyle $io = null; + + private string $sourceCode; + private ?array $oldStmts = null; + private array $oldTokens = []; + private array $newStmts= []; + + 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; From c2578662e8dde9c827690563cae1110c3d8d4880 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Thu, 19 May 2022 09:29:34 -0400 Subject: [PATCH 03/11] strict typing --- src/Security/InteractiveSecurityHelper.php | 10 ++++------ src/Security/SecurityConfigUpdater.php | 7 ++----- src/Security/SecurityControllerBuilder.php | 5 +---- src/Security/UserClassConfiguration.php | 16 +++------------- 4 files changed, 10 insertions(+), 28 deletions(-) diff --git a/src/Security/InteractiveSecurityHelper.php b/src/Security/InteractiveSecurityHelper.php index cc4cf276f..6da9cb6e4 100644 --- a/src/Security/InteractiveSecurityHelper.php +++ b/src/Security/InteractiveSecurityHelper.php @@ -25,7 +25,7 @@ public function guessFirewallName(SymfonyStyle $io, array $securityData, string { $realFirewalls = array_filter( $securityData['security']['firewalls'] ?? [], - function ($item) { + static function ($item) { return !isset($item['security']) || true === $item['security']; } ); @@ -53,13 +53,11 @@ public function guessUserClass(SymfonyStyle $io, array $providers, string $quest return $entityProvider['entity']['class']; } - $userClass = $io->ask( + return $io->ask( $questionText ?? 'Enter the User class that you want to authenticate (e.g. App\\Entity\\User)', $this->guessUserClassDefault(), [Validator::class, 'classIsUserInterface'] ); - - return $userClass; } private function guessUserClassDefault(): string @@ -147,7 +145,7 @@ public function guessPasswordField(SymfonyStyle $io, string $userClass): string public function getAuthenticatorClasses(array $firewallData): array { if (isset($firewallData['guard'])) { - return array_filter($firewallData['guard']['authenticators'] ?? [], function ($authenticator) { + return array_filter($firewallData['guard']['authenticators'] ?? [], static function ($authenticator) { return class_exists($authenticator); }); } @@ -158,7 +156,7 @@ public function getAuthenticatorClasses(array $firewallData): array $authenticators = [$authenticators]; } - return array_filter($authenticators, function ($authenticator) { + return array_filter($authenticators, static function ($authenticator) { return class_exists($authenticator); }); } diff --git a/src/Security/SecurityConfigUpdater.php b/src/Security/SecurityConfigUpdater.php index 19d3d7749..d73562e6a 100644 --- a/src/Security/SecurityConfigUpdater.php +++ b/src/Security/SecurityConfigUpdater.php @@ -23,11 +23,8 @@ */ final class SecurityConfigUpdater { - /** @var YamlSourceManipulator */ - private $manipulator; - - /** @var Logger|null */ - private $ysmLogger; + private ?YamlSourceManipulator $manipulator; + private ?Logger $ysmLogger; public function __construct(Logger $ysmLogger = null) { diff --git a/src/Security/SecurityControllerBuilder.php b/src/Security/SecurityControllerBuilder.php index 6123c401d..857fb9153 100644 --- a/src/Security/SecurityControllerBuilder.php +++ b/src/Security/SecurityControllerBuilder.php @@ -22,11 +22,8 @@ */ final class SecurityControllerBuilder { - private $phpCompatUtil; - - public function __construct(PhpCompatUtil $phpCompatUtil) + public function __construct(private PhpCompatUtil $phpCompatUtil) { - $this->phpCompatUtil = $phpCompatUtil; } public function addLoginMethod(ClassSourceManipulator $manipulator): void diff --git a/src/Security/UserClassConfiguration.php b/src/Security/UserClassConfiguration.php index bb03e188b..eda0d45b4 100644 --- a/src/Security/UserClassConfiguration.php +++ b/src/Security/UserClassConfiguration.php @@ -18,21 +18,11 @@ */ final class UserClassConfiguration { - private $isEntity; + private bool $useArgon2 = false; + private string $userProviderClass; - private $identityPropertyName; - - private $hasPassword; - - private $useArgon2 = false; - - private $userProviderClass; - - public function __construct(bool $isEntity, string $identityPropertyName, bool $hasPassword) + public function __construct(private bool $isEntity, private string $identityPropertyName, private bool $hasPassword) { - $this->isEntity = $isEntity; - $this->identityPropertyName = $identityPropertyName; - $this->hasPassword = $hasPassword; } public function isEntity(): bool From 400869bb47c9d689a0edc5eb6721a678707dc2ee Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Thu, 19 May 2022 09:33:00 -0400 Subject: [PATCH 04/11] Revert "csm property types" This reverts commit 890fe118c5bbce63f461c08e2901ad8421c9fbc1. --- src/Util/ClassSourceManipulator.php | 42 +++++++++++++---------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/Util/ClassSourceManipulator.php b/src/Util/ClassSourceManipulator.php index 49003896d..8bb2b545b 100644 --- a/src/Util/ClassSourceManipulator.php +++ b/src/Util/ClassSourceManipulator.php @@ -46,29 +46,25 @@ final class ClassSourceManipulator private const CONTEXT_CLASS = 'class'; private const CONTEXT_CLASS_METHOD = 'class_method'; - private bool $overwrite; - private bool $useAnnotations; - private bool $fluentMutators; - private bool $useAttributesForDoctrineMapping; - private Parser\Php7 $parser; - private Lexer\Emulative $lexer; - private PrettyPrinter $printer; - private ?ConsoleStyle $io = null; - - private string $sourceCode; - private ?array $oldStmts = null; - private array $oldTokens = []; - private array $newStmts= []; - - private array $pendingComments = []; - - public function __construct( - string $sourceCode, - bool $overwrite = false, - bool $useAnnotations = true, - bool $fluentMutators = true, - bool $useAttributesForDoctrineMapping = false - ) { + private $overwrite; + private $useAnnotations; + private $fluentMutators; + private $useAttributesForDoctrineMapping; + private $parser; + private $lexer; + private $printer; + /** @var ConsoleStyle|null */ + private $io; + + private $sourceCode; + private $oldStmts; + private $oldTokens; + private $newStmts; + + private $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; From 7932c612514f3a035aeb18664726c63929499839 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Thu, 19 May 2022 10:17:55 -0400 Subject: [PATCH 05/11] strict typing for doctrine where possible --- src/Doctrine/DoctrineHelper.php | 5 +- src/Doctrine/EntityClassGenerator.php | 7 +- src/Doctrine/EntityDetails.php | 8 +- src/Doctrine/EntityRegenerator.php | 22 ++-- src/Doctrine/EntityRelation.php | 154 ++++++++++---------------- 5 files changed, 72 insertions(+), 124 deletions(-) diff --git a/src/Doctrine/DoctrineHelper.php b/src/Doctrine/DoctrineHelper.php index b5f7fb55c..ff54aa3da 100644 --- a/src/Doctrine/DoctrineHelper.php +++ b/src/Doctrine/DoctrineHelper.php @@ -166,10 +166,7 @@ public function getEntitiesForAutocomplete(): array return $entities; } - /** - * @return array|ClassMetadata - */ - public function getMetadata(string $classOrNamespace = null, bool $disconnected = false) + public function getMetadata(string $classOrNamespace = null, bool $disconnected = false): array|ClassMetadata { // Invalidating the cached AnnotationDriver::$classNames to find new Entity classes foreach ($this->mappingDriversByPrefix ?? [] as $managerName => $prefixes) { diff --git a/src/Doctrine/EntityClassGenerator.php b/src/Doctrine/EntityClassGenerator.php index b937824f4..da263c883 100644 --- a/src/Doctrine/EntityClassGenerator.php +++ b/src/Doctrine/EntityClassGenerator.php @@ -30,13 +30,8 @@ */ final class EntityClassGenerator { - private $generator; - private $doctrineHelper; - - public function __construct(Generator $generator, DoctrineHelper $doctrineHelper) + public function __construct(private Generator $generator, private DoctrineHelper $doctrineHelper) { - $this->generator = $generator; - $this->doctrineHelper = $doctrineHelper; } public function generateEntityClass(ClassNameDetails $entityClassDetails, bool $apiResource, bool $withPasswordUpgrade = false, bool $generateRepositoryClass = true, bool $broadcast = false): string diff --git a/src/Doctrine/EntityDetails.php b/src/Doctrine/EntityDetails.php index 36b3cb83c..ad3c0fe04 100644 --- a/src/Doctrine/EntityDetails.php +++ b/src/Doctrine/EntityDetails.php @@ -21,14 +21,8 @@ */ final class EntityDetails { - private $metadata; - - /** - * @param ClassMetadata|LegacyClassMetadata $metadata - */ - public function __construct($metadata) + public function __construct(private ClassMetadata|LegacyClassMetadata $metadata) { - $this->metadata = $metadata; } public function getRepositoryClass(): ?string diff --git a/src/Doctrine/EntityRegenerator.php b/src/Doctrine/EntityRegenerator.php index b5caadee7..49f5940ed 100644 --- a/src/Doctrine/EntityRegenerator.php +++ b/src/Doctrine/EntityRegenerator.php @@ -25,19 +25,13 @@ */ final class EntityRegenerator { - private $doctrineHelper; - private $fileManager; - private $generator; - private $entityClassGenerator; - private $overwrite; - - public function __construct(DoctrineHelper $doctrineHelper, FileManager $fileManager, Generator $generator, EntityClassGenerator $entityClassGenerator, bool $overwrite) - { - $this->doctrineHelper = $doctrineHelper; - $this->fileManager = $fileManager; - $this->generator = $generator; - $this->entityClassGenerator = $entityClassGenerator; - $this->overwrite = $overwrite; + public function __construct( + private DoctrineHelper $doctrineHelper, + private FileManager $fileManager, + private Generator $generator, + private EntityClassGenerator $entityClassGenerator, + private bool $overwrite + ) { } public function regenerateEntities(string $classOrNamespace): void @@ -263,7 +257,7 @@ private function getMappedFieldsInEntity(ClassMetadata $classMetadata): array $targetFields = array_diff($targetFields, $traitProperties); // exclude inherited properties - $targetFields = array_filter($targetFields, function ($field) use ($classReflection) { + $targetFields = array_filter($targetFields, static function ($field) use ($classReflection) { return $classReflection->hasProperty($field) && $classReflection->getProperty($field)->getDeclaringClass()->getName() == $classReflection->getName(); }); diff --git a/src/Doctrine/EntityRelation.php b/src/Doctrine/EntityRelation.php index 0897555da..ba3dbe3ce 100644 --- a/src/Doctrine/EntityRelation.php +++ b/src/Doctrine/EntityRelation.php @@ -21,25 +21,14 @@ final class EntityRelation public const MANY_TO_MANY = 'ManyToMany'; public const ONE_TO_ONE = 'OneToOne'; - private $type; - - private $owningClass; - - private $inverseClass; - private $owningProperty; - private $inverseProperty; + private bool $isNullable = false; + private bool $isSelfReferencing; + private bool $orphanRemoval = false; + private bool $mapInverseRelation = true; - private $isNullable = false; - - private $isSelfReferencing = false; - - private $orphanRemoval = false; - - private $mapInverseRelation = true; - - public function __construct(string $type, string $owningClass, string $inverseClass) + public function __construct(private string $type, private string $owningClass, private string $inverseClass) { if (!\in_array($type, self::getValidRelationTypes())) { throw new \Exception(sprintf('Invalid relation type "%s"', $type)); @@ -49,9 +38,6 @@ public function __construct(string $type, string $owningClass, string $inverseCl throw new \Exception('Use ManyToOne instead of OneToMany'); } - $this->type = $type; - $this->owningClass = $owningClass; - $this->inverseClass = $inverseClass; $this->isSelfReferencing = $owningClass === $inverseClass; } @@ -89,78 +75,60 @@ public static function getValidRelationTypes(): array ]; } - public function getOwningRelation() - { - switch ($this->getType()) { - case self::MANY_TO_ONE: - return (new RelationManyToOne()) - ->setPropertyName($this->owningProperty) - ->setTargetClassName($this->inverseClass) - ->setTargetPropertyName($this->inverseProperty) - ->setIsNullable($this->isNullable) - ->setIsSelfReferencing($this->isSelfReferencing) - ->setMapInverseRelation($this->mapInverseRelation) - ; - break; - case self::MANY_TO_MANY: - return (new RelationManyToMany()) - ->setPropertyName($this->owningProperty) - ->setTargetClassName($this->inverseClass) - ->setTargetPropertyName($this->inverseProperty) - ->setIsOwning(true)->setMapInverseRelation($this->mapInverseRelation) - ->setIsSelfReferencing($this->isSelfReferencing) - ; - break; - case self::ONE_TO_ONE: - return (new RelationOneToOne()) - ->setPropertyName($this->owningProperty) - ->setTargetClassName($this->inverseClass) - ->setTargetPropertyName($this->inverseProperty) - ->setIsNullable($this->isNullable) - ->setIsOwning(true) - ->setIsSelfReferencing($this->isSelfReferencing) - ->setMapInverseRelation($this->mapInverseRelation) - ; - break; - default: - throw new \InvalidArgumentException('Invalid type'); - } - } - - public function getInverseRelation() - { - switch ($this->getType()) { - case self::MANY_TO_ONE: - return (new RelationOneToMany()) - ->setPropertyName($this->inverseProperty) - ->setTargetClassName($this->owningClass) - ->setTargetPropertyName($this->owningProperty) - ->setOrphanRemoval($this->orphanRemoval) - ->setIsSelfReferencing($this->isSelfReferencing) - ; - break; - case self::MANY_TO_MANY: - return (new RelationManyToMany()) - ->setPropertyName($this->inverseProperty) - ->setTargetClassName($this->owningClass) - ->setTargetPropertyName($this->owningProperty) - ->setIsOwning(false) - ->setIsSelfReferencing($this->isSelfReferencing) - ; - break; - case self::ONE_TO_ONE: - return (new RelationOneToOne()) - ->setPropertyName($this->inverseProperty) - ->setTargetClassName($this->owningClass) - ->setTargetPropertyName($this->owningProperty) - ->setIsNullable($this->isNullable) - ->setIsOwning(false) - ->setIsSelfReferencing($this->isSelfReferencing) - ; - break; - default: - throw new \InvalidArgumentException('Invalid type'); - } + public function getOwningRelation(): RelationManyToMany|RelationOneToOne|RelationManyToOne + { + return match ($this->getType()) { + self::MANY_TO_ONE => (new RelationManyToOne()) + ->setPropertyName($this->owningProperty) + ->setTargetClassName($this->inverseClass) + ->setTargetPropertyName($this->inverseProperty) + ->setIsNullable($this->isNullable) + ->setIsSelfReferencing($this->isSelfReferencing) + ->setMapInverseRelation($this->mapInverseRelation), + self::MANY_TO_MANY => (new RelationManyToMany()) + ->setPropertyName($this->owningProperty) + ->setTargetClassName($this->inverseClass) + ->setTargetPropertyName($this->inverseProperty) + ->setIsOwning(true)->setMapInverseRelation( + $this->mapInverseRelation + ) + ->setIsSelfReferencing($this->isSelfReferencing), + self::ONE_TO_ONE => (new RelationOneToOne()) + ->setPropertyName($this->owningProperty) + ->setTargetClassName($this->inverseClass) + ->setTargetPropertyName($this->inverseProperty) + ->setIsNullable($this->isNullable) + ->setIsOwning(true) + ->setIsSelfReferencing($this->isSelfReferencing) + ->setMapInverseRelation($this->mapInverseRelation), + default => throw new \InvalidArgumentException('Invalid type'), + }; + } + + public function getInverseRelation(): RelationManyToMany|RelationOneToOne|RelationOneToMany + { + return match ($this->getType()) { + self::MANY_TO_ONE => (new RelationOneToMany()) + ->setPropertyName($this->inverseProperty) + ->setTargetClassName($this->owningClass) + ->setTargetPropertyName($this->owningProperty) + ->setOrphanRemoval($this->orphanRemoval) + ->setIsSelfReferencing($this->isSelfReferencing), + self::MANY_TO_MANY => (new RelationManyToMany()) + ->setPropertyName($this->inverseProperty) + ->setTargetClassName($this->owningClass) + ->setTargetPropertyName($this->owningProperty) + ->setIsOwning(false) + ->setIsSelfReferencing($this->isSelfReferencing), + self::ONE_TO_ONE => (new RelationOneToOne()) + ->setPropertyName($this->inverseProperty) + ->setTargetClassName($this->owningClass) + ->setTargetPropertyName($this->owningProperty) + ->setIsNullable($this->isNullable) + ->setIsOwning(false) + ->setIsSelfReferencing($this->isSelfReferencing), + default => throw new \InvalidArgumentException('Invalid type'), + }; } public function getType(): string @@ -178,7 +146,7 @@ public function getInverseClass(): string return $this->inverseClass; } - public function getOwningProperty() + public function getOwningProperty(): string { return $this->owningProperty; } @@ -203,7 +171,7 @@ public function getMapInverseRelation(): bool return $this->mapInverseRelation; } - public function setMapInverseRelation(bool $mapInverseRelation) + public function setMapInverseRelation(bool $mapInverseRelation): void { if ($mapInverseRelation && $this->inverseProperty) { throw new \Exception('Cannot set setMapInverseRelation() to true when the inverse relation property is set.'); From 2113a9eecb7797bceb7256359551a50988db0869 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow <40327885+jrushlow@users.noreply.github.com> Date: Thu, 19 May 2022 10:29:32 -0400 Subject: [PATCH 06/11] new lines Co-authored-by: Oskar Stark --- src/Doctrine/EntityClassGenerator.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Doctrine/EntityClassGenerator.php b/src/Doctrine/EntityClassGenerator.php index da263c883..6a4310e05 100644 --- a/src/Doctrine/EntityClassGenerator.php +++ b/src/Doctrine/EntityClassGenerator.php @@ -30,7 +30,10 @@ */ final class EntityClassGenerator { - public function __construct(private Generator $generator, private DoctrineHelper $doctrineHelper) + public function __construct( + private Generator $generator, + private DoctrineHelper $doctrineHelper, + ) { } From 9273428d628ad0f7bd748da9fc49c520576b9c17 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow <40327885+jrushlow@users.noreply.github.com> Date: Thu, 19 May 2022 10:33:37 -0400 Subject: [PATCH 07/11] new lines Co-authored-by: Oskar Stark --- src/Security/UserClassConfiguration.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Security/UserClassConfiguration.php b/src/Security/UserClassConfiguration.php index eda0d45b4..f7a63fa60 100644 --- a/src/Security/UserClassConfiguration.php +++ b/src/Security/UserClassConfiguration.php @@ -21,7 +21,11 @@ final class UserClassConfiguration private bool $useArgon2 = false; private string $userProviderClass; - public function __construct(private bool $isEntity, private string $identityPropertyName, private bool $hasPassword) + public function __construct( + private bool $isEntity, + private string $identityPropertyName, + private bool $hasPassword, + ) { } From 6dcb60f6249f4d5470dddd5f56bcf55f7b06fb2c Mon Sep 17 00:00:00 2001 From: Jesse Rushlow <40327885+jrushlow@users.noreply.github.com> Date: Thu, 19 May 2022 10:34:25 -0400 Subject: [PATCH 08/11] const prop promo Co-authored-by: Oskar Stark --- src/Security/SecurityConfigUpdater.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Security/SecurityConfigUpdater.php b/src/Security/SecurityConfigUpdater.php index d73562e6a..01302f4bf 100644 --- a/src/Security/SecurityConfigUpdater.php +++ b/src/Security/SecurityConfigUpdater.php @@ -26,7 +26,7 @@ final class SecurityConfigUpdater private ?YamlSourceManipulator $manipulator; private ?Logger $ysmLogger; - public function __construct(Logger $ysmLogger = null) + public function __construct(private ?Logger $ysmLogger = null) { $this->ysmLogger = $ysmLogger; } From 10b13d1e263b36a51304dc57a225ba9c96cfdf22 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow <40327885+jrushlow@users.noreply.github.com> Date: Thu, 19 May 2022 10:34:41 -0400 Subject: [PATCH 09/11] const prop promo Co-authored-by: Oskar Stark --- src/Util/ClassNameDetails.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Util/ClassNameDetails.php b/src/Util/ClassNameDetails.php index 56184dd94..54b11529a 100644 --- a/src/Util/ClassNameDetails.php +++ b/src/Util/ClassNameDetails.php @@ -20,7 +20,7 @@ final class ClassNameDetails public function __construct( private string $fullClassName, private string $namespacePrefix, - string $suffix = null + private ?string $suffix = null ) { $this->namespacePrefix = trim($namespacePrefix, '\\'); $this->suffix = $suffix; From 104da07a738b6d2111ff487e7d516f13a2d9fcab Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Thu, 19 May 2022 10:40:46 -0400 Subject: [PATCH 10/11] cleanup --- src/Doctrine/EntityClassGenerator.php | 3 +-- src/Doctrine/EntityDetails.php | 5 +++-- src/Doctrine/EntityRelation.php | 7 +++++-- src/Security/SecurityConfigUpdater.php | 7 +++---- src/Security/SecurityControllerBuilder.php | 5 +++-- src/Security/UserClassConfiguration.php | 3 +-- src/Util/AutoloaderUtil.php | 5 +++-- src/Util/ClassDetails.php | 5 +++-- src/Util/ClassNameDetails.php | 3 --- src/Util/ClassNameValue.php | 6 ++++-- src/Util/UseStatementGenerator.php | 5 +++-- src/Util/YamlSourceManipulator.php | 5 +++-- 12 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/Doctrine/EntityClassGenerator.php b/src/Doctrine/EntityClassGenerator.php index 6a4310e05..09821e267 100644 --- a/src/Doctrine/EntityClassGenerator.php +++ b/src/Doctrine/EntityClassGenerator.php @@ -33,8 +33,7 @@ final class EntityClassGenerator public function __construct( private Generator $generator, private DoctrineHelper $doctrineHelper, - ) - { + ) { } public function generateEntityClass(ClassNameDetails $entityClassDetails, bool $apiResource, bool $withPasswordUpgrade = false, bool $generateRepositoryClass = true, bool $broadcast = false): string diff --git a/src/Doctrine/EntityDetails.php b/src/Doctrine/EntityDetails.php index ad3c0fe04..22c94ae81 100644 --- a/src/Doctrine/EntityDetails.php +++ b/src/Doctrine/EntityDetails.php @@ -21,8 +21,9 @@ */ final class EntityDetails { - public function __construct(private ClassMetadata|LegacyClassMetadata $metadata) - { + public function __construct( + private ClassMetadata|LegacyClassMetadata $metadata + ) { } public function getRepositoryClass(): ?string diff --git a/src/Doctrine/EntityRelation.php b/src/Doctrine/EntityRelation.php index ba3dbe3ce..36d665dea 100644 --- a/src/Doctrine/EntityRelation.php +++ b/src/Doctrine/EntityRelation.php @@ -28,8 +28,11 @@ final class EntityRelation private bool $orphanRemoval = false; private bool $mapInverseRelation = true; - public function __construct(private string $type, private string $owningClass, private string $inverseClass) - { + public function __construct( + private string $type, + private string $owningClass, + private string $inverseClass + ) { if (!\in_array($type, self::getValidRelationTypes())) { throw new \Exception(sprintf('Invalid relation type "%s"', $type)); } diff --git a/src/Security/SecurityConfigUpdater.php b/src/Security/SecurityConfigUpdater.php index 01302f4bf..4c7c971b9 100644 --- a/src/Security/SecurityConfigUpdater.php +++ b/src/Security/SecurityConfigUpdater.php @@ -24,11 +24,10 @@ final class SecurityConfigUpdater { private ?YamlSourceManipulator $manipulator; - private ?Logger $ysmLogger; - public function __construct(private ?Logger $ysmLogger = null) - { - $this->ysmLogger = $ysmLogger; + public function __construct( + private ?Logger $ysmLogger = null + ) { } /** diff --git a/src/Security/SecurityControllerBuilder.php b/src/Security/SecurityControllerBuilder.php index 857fb9153..e5da6d0b0 100644 --- a/src/Security/SecurityControllerBuilder.php +++ b/src/Security/SecurityControllerBuilder.php @@ -22,8 +22,9 @@ */ final class SecurityControllerBuilder { - public function __construct(private PhpCompatUtil $phpCompatUtil) - { + public function __construct( + private PhpCompatUtil $phpCompatUtil + ) { } public function addLoginMethod(ClassSourceManipulator $manipulator): void diff --git a/src/Security/UserClassConfiguration.php b/src/Security/UserClassConfiguration.php index f7a63fa60..9fb547269 100644 --- a/src/Security/UserClassConfiguration.php +++ b/src/Security/UserClassConfiguration.php @@ -25,8 +25,7 @@ public function __construct( private bool $isEntity, private string $identityPropertyName, private bool $hasPassword, - ) - { + ) { } public function isEntity(): bool diff --git a/src/Util/AutoloaderUtil.php b/src/Util/AutoloaderUtil.php index f5c5199e8..b006e91b1 100644 --- a/src/Util/AutoloaderUtil.php +++ b/src/Util/AutoloaderUtil.php @@ -20,8 +20,9 @@ */ class AutoloaderUtil { - public function __construct(private ComposerAutoloaderFinder $autoloaderFinder) - { + public function __construct( + private ComposerAutoloaderFinder $autoloaderFinder + ) { } /** diff --git a/src/Util/ClassDetails.php b/src/Util/ClassDetails.php index 3eeb1798c..8f4b3352c 100644 --- a/src/Util/ClassDetails.php +++ b/src/Util/ClassDetails.php @@ -16,8 +16,9 @@ */ final class ClassDetails { - public function __construct(private string $fullClassName) - { + public function __construct( + private string $fullClassName + ) { } /** diff --git a/src/Util/ClassNameDetails.php b/src/Util/ClassNameDetails.php index 54b11529a..e1df74ee0 100644 --- a/src/Util/ClassNameDetails.php +++ b/src/Util/ClassNameDetails.php @@ -15,15 +15,12 @@ final class ClassNameDetails { - private ?string $suffix; - public function __construct( private string $fullClassName, private string $namespacePrefix, private ?string $suffix = null ) { $this->namespacePrefix = trim($namespacePrefix, '\\'); - $this->suffix = $suffix; } public function getFullName(): string diff --git a/src/Util/ClassNameValue.php b/src/Util/ClassNameValue.php index 4f56cd095..71e7a42ff 100644 --- a/src/Util/ClassNameValue.php +++ b/src/Util/ClassNameValue.php @@ -18,8 +18,10 @@ */ final class ClassNameValue { - public function __construct(private string $typeHint, private string $fullClassName) - { + public function __construct( + private string $typeHint, + private string $fullClassName + ) { } public function getShortName(): string diff --git a/src/Util/UseStatementGenerator.php b/src/Util/UseStatementGenerator.php index 6b155057f..a5d297851 100644 --- a/src/Util/UseStatementGenerator.php +++ b/src/Util/UseStatementGenerator.php @@ -28,8 +28,9 @@ final class UseStatementGenerator implements \Stringable * * @param string[]|array $classesToBeImported */ - public function __construct(private array $classesToBeImported) - { + public function __construct( + private array $classesToBeImported + ) { } public function __toString(): string diff --git a/src/Util/YamlSourceManipulator.php b/src/Util/YamlSourceManipulator.php index 70cab28cd..f1049ecd7 100644 --- a/src/Util/YamlSourceManipulator.php +++ b/src/Util/YamlSourceManipulator.php @@ -48,8 +48,9 @@ class YamlSourceManipulator private $arrayFormatForDepths = []; private $arrayTypeForDepths = []; - public function __construct(private string $contents) - { + public function __construct( + private string $contents + ) { $this->currentData = Yaml::parse($contents); if (!\is_array($this->currentData)) { From 7dd6592e94e0ea71ee3ba9bbf9633a0688caf145 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow <40327885+jrushlow@users.noreply.github.com> Date: Thu, 19 May 2022 10:59:45 -0400 Subject: [PATCH 11/11] default false Co-authored-by: Ryan Weaver --- src/Doctrine/EntityRelation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Doctrine/EntityRelation.php b/src/Doctrine/EntityRelation.php index 36d665dea..ff81f5350 100644 --- a/src/Doctrine/EntityRelation.php +++ b/src/Doctrine/EntityRelation.php @@ -24,7 +24,7 @@ final class EntityRelation private $owningProperty; private $inverseProperty; private bool $isNullable = false; - private bool $isSelfReferencing; + private bool $isSelfReferencing = false; private bool $orphanRemoval = false; private bool $mapInverseRelation = true;