From 4b8d1b0353742196a8a2101c5fc8f5aca1fc6d8f Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Tue, 31 May 2022 08:18:40 -0400 Subject: [PATCH] better naming conventions and remove default value --- src/Maker/MakeEntity.php | 1 - src/Maker/MakeRegistrationForm.php | 1 - src/Maker/MakeResetPassword.php | 4 +--- src/Maker/MakeUser.php | 9 ++++++--- src/Test/MakerTestRunner.php | 1 - tests/Util/ClassSourceManipulatorTest.php | 10 +++++----- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/Maker/MakeEntity.php b/src/Maker/MakeEntity.php index 85cb0056ce..2553d89aa6 100644 --- a/src/Maker/MakeEntity.php +++ b/src/Maker/MakeEntity.php @@ -801,7 +801,6 @@ private function createClassManipulator(string $path, ConsoleStyle $io, bool $ov $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 432b2744cc..407a59f880 100644 --- a/src/Maker/MakeRegistrationForm.php +++ b/src/Maker/MakeRegistrationForm.php @@ -392,7 +392,6 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen $userManipulator = new ClassSourceManipulator( sourceCode: file_get_contents($classDetails->getPath()), overwrite: false, - useAttributesForDoctrineMapping: true ); $userManipulator->setIo($io); diff --git a/src/Maker/MakeResetPassword.php b/src/Maker/MakeResetPassword.php index 905384104d..6b0f6cb6e9 100644 --- a/src/Maker/MakeResetPassword.php +++ b/src/Maker/MakeResetPassword.php @@ -401,12 +401,10 @@ private function generateRequestEntity(Generator $generator, ClassNameDetails $r $generator->writeChanges(); - $useAttributesForDoctrineMapping = $this->doctrineHelper->isDoctrineSupportingAttributes() && $this->doctrineHelper->doesClassUsesAttributes($requestClassNameDetails->getFullName()); - $manipulator = new ClassSourceManipulator( sourceCode: $this->fileManager->getFileContents($requestEntityPath), overwrite: false, - useAttributesForDoctrineMapping: $useAttributesForDoctrineMapping + useAttributesForDoctrineMapping: $this->doctrineHelper->doesClassUsesAttributes($requestClassNameDetails->getFullName()), ); $manipulator->addInterface(ResetPasswordRequestInterface::class); diff --git a/src/Maker/MakeUser.php b/src/Maker/MakeUser.php index 5b11625ab7..1bbb5da1fc 100644 --- a/src/Maker/MakeUser.php +++ b/src/Maker/MakeUser.php @@ -138,14 +138,17 @@ 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()); + $entityUsesAttributes = ($isEntity = $userClassConfiguration->isEntity()) && $this->doctrineHelper->doesClassUsesAttributes($userClassNameDetails->getFullName()); + + if ($isEntity && !$entityUsesAttributes) { + throw new \RuntimeException('MakeUser only supports attribute mapping with doctrine entities.'); + } // B) Implement UserInterface $manipulator = new ClassSourceManipulator( sourceCode: $this->fileManager->getFileContents($classPath), overwrite: true, - useAttributesForDoctrineMapping: $useAttributesForDoctrineMapping + useAttributesForDoctrineMapping: $entityUsesAttributes ); $manipulator->setIo($io); diff --git a/src/Test/MakerTestRunner.php b/src/Test/MakerTestRunner.php index 31c9b4aa9a..fb9029d051 100644 --- a/src/Test/MakerTestRunner.php +++ b/src/Test/MakerTestRunner.php @@ -244,7 +244,6 @@ public function manipulateClass(string $filename, \Closure $callback): void $manipulator = new ClassSourceManipulator( sourceCode: $contents, overwrite: true, - useAttributesForDoctrineMapping: true ); $callback($manipulator); diff --git a/tests/Util/ClassSourceManipulatorTest.php b/tests/Util/ClassSourceManipulatorTest.php index 91b48a29e5..43b3485f0f 100644 --- a/tests/Util/ClassSourceManipulatorTest.php +++ b/tests/Util/ClassSourceManipulatorTest.php @@ -225,7 +225,7 @@ public function testAddEntityField(string $sourceFilename, string $propertyName, private function runAddEntityFieldTests(string $source, string $propertyName, array $fieldOptions, string $expected): void { - $manipulator = new ClassSourceManipulator($source, false, true); + $manipulator = new ClassSourceManipulator($source, false); $manipulator->addEntityField($propertyName, $fieldOptions); $this->assertSame($expected, $manipulator->getSourceCode()); @@ -304,7 +304,7 @@ public function testAddManyToOneRelation(string $sourceFilename, $expectedSource public function runAddManyToOneRelationTests(string $source, string $expected, RelationManyToOne $manyToOne): void { - $manipulator = new ClassSourceManipulator($source, false, true); + $manipulator = new ClassSourceManipulator($source, false); $manipulator->addManyToOneRelation($manyToOne); $this->assertSame($expected, $manipulator->getSourceCode()); @@ -402,7 +402,7 @@ public function testAddOneToManyRelation(string $sourceFilename, string $expecte private function runAddOneToManyRelationTests(string $source, string $expected, RelationOneToMany $oneToMany): void { - $manipulator = new ClassSourceManipulator($source, false, true); + $manipulator = new ClassSourceManipulator($source, false); $manipulator->addOneToManyRelation($oneToMany); $this->assertSame($expected, $manipulator->getSourceCode()); @@ -463,7 +463,7 @@ public function testAddManyToManyRelation(string $sourceFilename, $expectedSourc private function runAddManyToManyRelationTest(string $source, string $expected, RelationManyToMany $manyToMany): void { - $manipulator = new ClassSourceManipulator($source, false, true); + $manipulator = new ClassSourceManipulator($source, false); $manipulator->addManyToManyRelation($manyToMany); $this->assertSame($expected, $manipulator->getSourceCode()); @@ -522,7 +522,7 @@ public function testAddOneToOneRelation(string $sourceFilename, $expectedSourceF private function runAddOneToOneRelation(string $source, string $expected, RelationOneToOne $oneToOne): void { - $manipulator = new ClassSourceManipulator($source, false, true); + $manipulator = new ClassSourceManipulator($source, false); $manipulator->addOneToOneRelation($oneToOne); $this->assertSame($expected, $manipulator->getSourceCode());