Skip to content

Commit 4b8d1b0

Browse files
committed
better naming conventions and remove default value
1 parent 34e21bc commit 4b8d1b0

File tree

6 files changed

+12
-14
lines changed

6 files changed

+12
-14
lines changed

src/Maker/MakeEntity.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,6 @@ private function createClassManipulator(string $path, ConsoleStyle $io, bool $ov
801801
$manipulator = new ClassSourceManipulator(
802802
sourceCode: $this->fileManager->getFileContents($path),
803803
overwrite: $overwrite,
804-
useAttributesForDoctrineMapping: true
805804
);
806805

807806
$manipulator->setIo($io);

src/Maker/MakeRegistrationForm.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
392392
$userManipulator = new ClassSourceManipulator(
393393
sourceCode: file_get_contents($classDetails->getPath()),
394394
overwrite: false,
395-
useAttributesForDoctrineMapping: true
396395
);
397396
$userManipulator->setIo($io);
398397

src/Maker/MakeResetPassword.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,10 @@ private function generateRequestEntity(Generator $generator, ClassNameDetails $r
401401

402402
$generator->writeChanges();
403403

404-
$useAttributesForDoctrineMapping = $this->doctrineHelper->isDoctrineSupportingAttributes() && $this->doctrineHelper->doesClassUsesAttributes($requestClassNameDetails->getFullName());
405-
406404
$manipulator = new ClassSourceManipulator(
407405
sourceCode: $this->fileManager->getFileContents($requestEntityPath),
408406
overwrite: false,
409-
useAttributesForDoctrineMapping: $useAttributesForDoctrineMapping
407+
useAttributesForDoctrineMapping: $this->doctrineHelper->doesClassUsesAttributes($requestClassNameDetails->getFullName()),
410408
);
411409

412410
$manipulator->addInterface(ResetPasswordRequestInterface::class);

src/Maker/MakeUser.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,17 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
138138
// need to write changes early so we can modify the contents below
139139
$generator->writeChanges();
140140

141-
// @legacy @todo - refactor for better naming conventions BEFORE next release.
142-
$useAttributesForDoctrineMapping = $userClassConfiguration->isEntity() && ($this->doctrineHelper->isDoctrineSupportingAttributes()) && $this->doctrineHelper->doesClassUsesAttributes($userClassNameDetails->getFullName());
141+
$entityUsesAttributes = ($isEntity = $userClassConfiguration->isEntity()) && $this->doctrineHelper->doesClassUsesAttributes($userClassNameDetails->getFullName());
142+
143+
if ($isEntity && !$entityUsesAttributes) {
144+
throw new \RuntimeException('MakeUser only supports attribute mapping with doctrine entities.');
145+
}
143146

144147
// B) Implement UserInterface
145148
$manipulator = new ClassSourceManipulator(
146149
sourceCode: $this->fileManager->getFileContents($classPath),
147150
overwrite: true,
148-
useAttributesForDoctrineMapping: $useAttributesForDoctrineMapping
151+
useAttributesForDoctrineMapping: $entityUsesAttributes
149152
);
150153

151154
$manipulator->setIo($io);

src/Test/MakerTestRunner.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ public function manipulateClass(string $filename, \Closure $callback): void
244244
$manipulator = new ClassSourceManipulator(
245245
sourceCode: $contents,
246246
overwrite: true,
247-
useAttributesForDoctrineMapping: true
248247
);
249248
$callback($manipulator);
250249

tests/Util/ClassSourceManipulatorTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public function testAddEntityField(string $sourceFilename, string $propertyName,
225225

226226
private function runAddEntityFieldTests(string $source, string $propertyName, array $fieldOptions, string $expected): void
227227
{
228-
$manipulator = new ClassSourceManipulator($source, false, true);
228+
$manipulator = new ClassSourceManipulator($source, false);
229229
$manipulator->addEntityField($propertyName, $fieldOptions);
230230

231231
$this->assertSame($expected, $manipulator->getSourceCode());
@@ -304,7 +304,7 @@ public function testAddManyToOneRelation(string $sourceFilename, $expectedSource
304304

305305
public function runAddManyToOneRelationTests(string $source, string $expected, RelationManyToOne $manyToOne): void
306306
{
307-
$manipulator = new ClassSourceManipulator($source, false, true);
307+
$manipulator = new ClassSourceManipulator($source, false);
308308
$manipulator->addManyToOneRelation($manyToOne);
309309

310310
$this->assertSame($expected, $manipulator->getSourceCode());
@@ -402,7 +402,7 @@ public function testAddOneToManyRelation(string $sourceFilename, string $expecte
402402

403403
private function runAddOneToManyRelationTests(string $source, string $expected, RelationOneToMany $oneToMany): void
404404
{
405-
$manipulator = new ClassSourceManipulator($source, false, true);
405+
$manipulator = new ClassSourceManipulator($source, false);
406406
$manipulator->addOneToManyRelation($oneToMany);
407407

408408
$this->assertSame($expected, $manipulator->getSourceCode());
@@ -463,7 +463,7 @@ public function testAddManyToManyRelation(string $sourceFilename, $expectedSourc
463463

464464
private function runAddManyToManyRelationTest(string $source, string $expected, RelationManyToMany $manyToMany): void
465465
{
466-
$manipulator = new ClassSourceManipulator($source, false, true);
466+
$manipulator = new ClassSourceManipulator($source, false);
467467
$manipulator->addManyToManyRelation($manyToMany);
468468

469469
$this->assertSame($expected, $manipulator->getSourceCode());
@@ -522,7 +522,7 @@ public function testAddOneToOneRelation(string $sourceFilename, $expectedSourceF
522522

523523
private function runAddOneToOneRelation(string $source, string $expected, RelationOneToOne $oneToOne): void
524524
{
525-
$manipulator = new ClassSourceManipulator($source, false, true);
525+
$manipulator = new ClassSourceManipulator($source, false);
526526
$manipulator->addOneToOneRelation($oneToOne);
527527

528528
$this->assertSame($expected, $manipulator->getSourceCode());

0 commit comments

Comments
 (0)