Skip to content

Commit c02f40a

Browse files
committed
feature #1125 [csm] strict typing && legacy code removal (jrushlow)
This PR was squashed before being merged into the 1.0-dev branch. Discussion ---------- [csm] strict typing && legacy code removal - drops CSM annotation support - cleans up legacy CSM code - implements strict typing - [x] Depends on #1126 Commits ------- ffc80c4 [csm] strict typing && legacy code removal
2 parents d2ce2ec + ffc80c4 commit c02f40a

File tree

69 files changed

+288
-2125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+288
-2125
lines changed

src/Doctrine/EntityRegenerator.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,12 @@ private function generateClass(ClassMetadata $metadata): string
199199
private function createClassManipulator(string $classPath): ClassSourceManipulator
200200
{
201201
return new ClassSourceManipulator(
202-
$this->fileManager->getFileContents($classPath),
203-
$this->overwrite,
204-
// use annotations
202+
sourceCode: $this->fileManager->getFileContents($classPath),
203+
overwrite: $this->overwrite,
205204
// if properties need to be generated then, by definition,
206205
// some non-annotation config is being used, and so, the
207206
// properties should not have annotations added to them
208-
false
207+
useAttributesForDoctrineMapping: false
209208
);
210209
}
211210

src/Maker/MakeAuthenticator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,10 @@ private function generateFormLoginFiles(string $controllerClass, string $userNam
333333
throw new RuntimeCommandException(sprintf('Method "login" already exists on class %s', $controllerClassNameDetails->getFullName()));
334334
}
335335

336-
$manipulator = new ClassSourceManipulator($controllerSourceCode, true);
336+
$manipulator = new ClassSourceManipulator(
337+
sourceCode: $controllerSourceCode,
338+
overwrite: true
339+
);
337340

338341
$this->securityControllerBuilder->addLoginMethod($manipulator);
339342

src/Maker/MakeEntity.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,11 @@ private function askRelationType(ConsoleStyle $io, string $entityClass, string $
804804

805805
private function createClassManipulator(string $path, ConsoleStyle $io, bool $overwrite): ClassSourceManipulator
806806
{
807-
$manipulator = new ClassSourceManipulator($this->fileManager->getFileContents($path), $overwrite, false, true, true);
807+
$manipulator = new ClassSourceManipulator(
808+
sourceCode: $this->fileManager->getFileContents($path),
809+
overwrite: $overwrite,
810+
useAttributesForDoctrineMapping: true
811+
);
808812

809813
$manipulator->setIo($io);
810814

src/Maker/MakeRegistrationForm.php

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
373373
if ($this->addUniqueEntityConstraint) {
374374
$classDetails = new ClassDetails($this->userClass);
375375
$userManipulator = new ClassSourceManipulator(
376-
file_get_contents($classDetails->getPath())
376+
sourceCode: file_get_contents($classDetails->getPath())
377377
);
378378
$userManipulator->setIo($io);
379379

@@ -382,34 +382,24 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
382382
UniqueEntity::class,
383383
['fields' => [$usernameField], 'message' => sprintf('There is already an account with this %s', $usernameField)]
384384
);
385-
} else {
386-
$userManipulator->addAnnotationToClass(
387-
UniqueEntity::class,
388-
[
389-
'fields' => [$usernameField],
390-
'message' => sprintf('There is already an account with this %s', $usernameField),
391-
]
392-
);
393385
}
386+
394387
$this->fileManager->dumpFile($classDetails->getPath(), $userManipulator->getSourceCode());
395388
}
396389

397390
if ($this->willVerifyEmail) {
398391
$classDetails = new ClassDetails($this->userClass);
399392
$userManipulator = new ClassSourceManipulator(
400-
file_get_contents($classDetails->getPath()),
401-
false,
402-
false,
403-
true,
404-
true
393+
sourceCode: file_get_contents($classDetails->getPath()),
394+
overwrite: false,
395+
useAttributesForDoctrineMapping: true
405396
);
406397
$userManipulator->setIo($io);
407398

408399
$userManipulator->addProperty(
409-
'isVerified',
410-
['@ORM\Column(type="boolean")'],
411-
false,
412-
[$userManipulator->buildAttributeNode(Column::class, ['type' => 'boolean'], 'ORM')]
400+
name: 'isVerified',
401+
defaultValue: false,
402+
attributes: [$userManipulator->buildAttributeNode(Column::class, ['type' => 'boolean'], 'ORM')]
413403
);
414404
$userManipulator->addAccessorMethod('isVerified', 'isVerified', 'bool', false);
415405
$userManipulator->addSetter('isVerified', 'bool', false);

src/Maker/MakeResetPassword.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -404,11 +404,9 @@ private function generateRequestEntity(Generator $generator, ClassNameDetails $r
404404
$useAttributesForDoctrineMapping = $this->doctrineHelper->isDoctrineSupportingAttributes() && $this->doctrineHelper->doesClassUsesAttributes($requestClassNameDetails->getFullName());
405405

406406
$manipulator = new ClassSourceManipulator(
407-
$this->fileManager->getFileContents($requestEntityPath),
408-
false,
409-
!$useAttributesForDoctrineMapping,
410-
true,
411-
$useAttributesForDoctrineMapping
407+
sourceCode: $this->fileManager->getFileContents($requestEntityPath),
408+
overwrite: false,
409+
useAttributesForDoctrineMapping: $useAttributesForDoctrineMapping
412410
);
413411

414412
$manipulator->addInterface(ResetPasswordRequestInterface::class);
@@ -453,7 +451,7 @@ private function generateRequestEntity(Generator $generator, ClassNameDetails $r
453451
);
454452

455453
$manipulator = new ClassSourceManipulator(
456-
$this->fileManager->getFileContents($pathRequestRepository)
454+
sourceCode: $this->fileManager->getFileContents($pathRequestRepository)
457455
);
458456

459457
$manipulator->addInterface(ResetPasswordRequestRepositoryInterface::class);

src/Maker/MakeUser.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,14 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
143143
// need to write changes early so we can modify the contents below
144144
$generator->writeChanges();
145145

146+
// @legacy @todo - refactor for better naming conventions BEFORE next release.
146147
$useAttributesForDoctrineMapping = $userClassConfiguration->isEntity() && ($this->doctrineHelper->isDoctrineSupportingAttributes()) && $this->doctrineHelper->doesClassUsesAttributes($userClassNameDetails->getFullName());
147148

148149
// B) Implement UserInterface
149150
$manipulator = new ClassSourceManipulator(
150-
$this->fileManager->getFileContents($classPath),
151-
true,
152-
!$useAttributesForDoctrineMapping,
153-
true,
154-
$useAttributesForDoctrineMapping
151+
sourceCode: $this->fileManager->getFileContents($classPath),
152+
overwrite: true,
153+
useAttributesForDoctrineMapping: $useAttributesForDoctrineMapping
155154
);
156155

157156
$manipulator->setIo($io);

src/Security/UserClassBuilder.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ private function addGetUsername(ClassSourceManipulator $manipulator, UserClassCo
7070
);
7171
} else {
7272
// add normal property
73-
$manipulator->addProperty($userClassConfig->getIdentityPropertyName());
73+
$manipulator->addProperty(
74+
name: $userClassConfig->getIdentityPropertyName()
75+
);
7476

7577
$manipulator->addGetter(
7678
$userClassConfig->getIdentityPropertyName(),
@@ -126,9 +128,8 @@ private function addGetRoles(ClassSourceManipulator $manipulator, UserClassConfi
126128
} else {
127129
// add normal property
128130
$manipulator->addProperty(
129-
'roles',
130-
[],
131-
new Node\Expr\Array_([], ['kind' => Node\Expr\Array_::KIND_SHORT])
131+
name: 'roles',
132+
defaultValue: new Node\Expr\Array_([], ['kind' => Node\Expr\Array_::KIND_SHORT])
132133
);
133134

134135
$manipulator->addGetter(
@@ -230,7 +231,10 @@ private function addGetPassword(ClassSourceManipulator $manipulator, UserClassCo
230231
);
231232
} else {
232233
// add normal property
233-
$manipulator->addProperty('password', [$propertyDocs]);
234+
$manipulator->addProperty(
235+
name: 'password',
236+
comments: [$propertyDocs]
237+
);
234238

235239
$manipulator->addGetter(
236240
'password',

src/Test/MakerTestRunner.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,11 @@ public function deleteFile(string $filename): void
241241
public function manipulateClass(string $filename, \Closure $callback): void
242242
{
243243
$contents = file_get_contents($this->getPath($filename));
244-
$manipulator = new ClassSourceManipulator($contents, true, false, true, true);
244+
$manipulator = new ClassSourceManipulator(
245+
sourceCode: $contents,
246+
overwrite: true,
247+
useAttributesForDoctrineMapping: true
248+
);
245249
$callback($manipulator);
246250

247251
file_put_contents($this->getPath($filename), $manipulator->getSourceCode());

0 commit comments

Comments
 (0)