Skip to content

Commit ee87da1

Browse files
committed
[make:crud] default to final
1 parent 4032122 commit ee87da1

File tree

6 files changed

+19
-11
lines changed

6 files changed

+19
-11
lines changed

src/Maker/MakeCrud.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Symfony\Bundle\MakerBundle\Maker\Common\CanGenerateTestsTrait;
2828
use Symfony\Bundle\MakerBundle\Renderer\FormTypeRenderer;
2929
use Symfony\Bundle\MakerBundle\Str;
30+
use Symfony\Bundle\MakerBundle\Util\ClassSource\Model\ClassData;
3031
use Symfony\Bundle\MakerBundle\Util\UseStatementGenerator;
3132
use Symfony\Bundle\MakerBundle\Validator;
3233
use Symfony\Bundle\TwigBundle\TwigBundle;
@@ -131,6 +132,11 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
131132
];
132133
}
133134

135+
$controllerClassData = ClassData::create(
136+
class: sprintf('App\Controller\%sController', $this->controllerClassName),
137+
extendsClass: AbstractController::class,
138+
);
139+
134140
$controllerClassDetails = $generator->createClassNameDetails(
135141
$this->controllerClassName,
136142
'Controller\\',
@@ -174,6 +180,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
174180
$controllerClassDetails->getFullName(),
175181
'crud/controller/Controller.tpl.php',
176182
array_merge([
183+
'class_data' => $controllerClassData,
177184
'use_statements' => $useStatements,
178185
'entity_class_name' => $entityClassDetails->getShortName(),
179186
'form_class_name' => $formClassDetails->getShortName(),
@@ -242,10 +249,9 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
242249
}
243250

244251
if ($this->shouldGenerateTests()) {
245-
$testClassDetails = $generator->createClassNameDetails(
246-
sprintf('\\App\\Tests\\Controller\\%s', $entityClassDetails->getRelativeNameWithoutSuffix()),
247-
'Controller\\',
248-
'ControllerTest'
252+
$testClassData = ClassData::create(
253+
class: sprintf('App\Tests\Controller\%sControllerTest', $entityClassDetails->getRelativeNameWithoutSuffix()),
254+
extendsClass: WebTestCase::class,
249255
);
250256

251257
$useStatements = new UseStatementGenerator([
@@ -262,17 +268,16 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
262268
}
263269

264270
$generator->generateClass(
265-
$testClassDetails->getFullName(),
271+
$testClassData->fullClassName,
266272
'crud/test/Test.EntityManager.tpl.php',
267273
[
274+
'class_data' => $testClassData,
268275
'use_statements' => $useStatements,
269276
'entity_full_class_name' => $entityClassDetails->getFullName(),
270277
'entity_class_name' => $entityClassDetails->getShortName(),
271278
'entity_var_singular' => $entityVarSingular,
272279
'route_path' => Str::asRoutePath($controllerClassDetails->getRelativeNameWithoutSuffix()),
273280
'route_name' => $routeName,
274-
'class_name' => Str::getShortClassName($testClassDetails->getFullName()),
275-
'namespace' => Str::getNamespace($testClassDetails->getFullName()),
276281
'form_fields' => $entityDoctrineDetails->getFormFields(),
277282
'repository_class_name' => EntityManagerInterface::class,
278283
'form_field_prefix' => strtolower(Str::asSnakeCase($entityTwigVarSingular)),

src/Resources/skeleton/crud/controller/Controller.tpl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<?= $use_statements; ?>
66

77
#[Route('<?= $route_path ?>')]
8-
class <?= $class_name ?> extends AbstractController
8+
<?= $class_data->getClassDeclaration() ?>
99
{
1010
<?= $generator->generateRouteForControllerMethod('/', sprintf('%s_index', $route_name), ['GET']) ?>
1111
<?php if (isset($repository_full_class_name)): ?>

src/Resources/skeleton/crud/test/Test.EntityManager.tpl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<?= $use_statements; ?>
77

8-
class <?= $class_name ?> extends WebTestCase<?= "\n" ?>
8+
<?= $class_data->getClassDeclaration() ?>
99
{
1010
private KernelBrowser $client;
1111
private EntityManagerInterface $manager;

src/Util/ClassSource/Model/ClassData.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ final class ClassData
2323
private function __construct(
2424
public readonly string $className,
2525
public readonly string $namespace,
26+
public readonly string $fullClassName,
2627
public readonly ?string $extends,
2728
public readonly bool $isEntity,
2829
private bool $isFinal = true,
@@ -34,8 +35,9 @@ public static function create(string $class, ?string $extendsClass = null, bool
3435
return new self(
3536
className: Str::getShortClassName($class),
3637
namespace: Str::getNamespace($class),
38+
fullClassName: $class,
3739
extends: null === $extendsClass ? null : Str::getShortClassName($extendsClass),
38-
isEntity: $isEntity
40+
isEntity: $isEntity,
3941
);
4042
}
4143

tests/Util/ClassSource/ClassDataTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function testStaticConstructor(): void
2727

2828
self::assertSame('MakerBundle', $meta->className);
2929
self::assertSame('Symfony\Bundle\MakerBundle', $meta->namespace);
30+
self::assertSame('Symfony\Bundle\MakerBundle\MakerBundle', $meta->fullClassName);
3031
}
3132

3233
public function testGetClassDeclaration(): void

tests/fixtures/make-crud/expected/WithCustomRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Symfony\Component\Routing\Attribute\Route;
1313

1414
#[Route('/sweet/food')]
15-
class SweetFoodController extends AbstractController
15+
final class SweetFoodController extends AbstractController
1616
{
1717
#[Route('/', name: 'app_sweet_food_index', methods: ['GET'])]
1818
public function index(SweetFoodRepository $sweetFoodRepository): Response

0 commit comments

Comments
 (0)