Skip to content

Commit

Permalink
better naming conventions and remove default value
Browse files Browse the repository at this point in the history
  • Loading branch information
jrushlow committed May 31, 2022
1 parent 34e21bc commit 4b8d1b0
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/Maker/MakeEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/Maker/MakeRegistrationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 1 addition & 3 deletions src/Maker/MakeResetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions src/Maker/MakeUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/Test/MakerTestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ public function manipulateClass(string $filename, \Closure $callback): void
$manipulator = new ClassSourceManipulator(
sourceCode: $contents,
overwrite: true,
useAttributesForDoctrineMapping: true
);
$callback($manipulator);

Expand Down
10 changes: 5 additions & 5 deletions tests/Util/ClassSourceManipulatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 4b8d1b0

Please sign in to comment.