Skip to content

Commit 543a1cb

Browse files
committed
Fix ClassData::create() calls
1 parent a4d76ad commit 543a1cb

File tree

8 files changed

+18
-22
lines changed

8 files changed

+18
-22
lines changed

src/Doctrine/DoctrineHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private function isDoctrineInstalled(): bool
6464

6565
public function getEntityNamespace(): string
6666
{
67-
return sprintf(
67+
return \sprintf(
6868
'%s\\%s',
6969
$this->namespacesHelper->getRootNamespace(),
7070
$this->namespacesHelper->getEntityNamespace()

src/Maker/MakeController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
142142
}
143143

144144
if ($this->shouldGenerateTests()) {
145-
$testClassName =\sprintf(
145+
$testClassName = \sprintf(
146146
'%s\%s\%s',
147147
$this->namespacesHelper->getTestNamespace(),
148148
$this->namespacesHelper->getControllerNamespace(),

src/Maker/MakeCrud.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class: \sprintf('%s\%s', $generator->getNamespacesHelper()->getControllerNamespa
248248
}
249249

250250
if ($this->shouldGenerateTests()) {
251-
$testClassName =\sprintf(
251+
$testClassName = \sprintf(
252252
'%s\%s\%s',
253253
$generator->getNamespacesHelper()->getTestNamespace(),
254254
$generator->getNamespacesHelper()->getControllerNamespace(),

src/Util/ClassSource/Model/ClassData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ private function __construct(
2727
public readonly ?string $extends,
2828
public readonly bool $isEntity,
2929
private UseStatementGenerator $useStatementGenerator,
30-
private bool $isFinal = true,
3130
private string $rootNamespace,
31+
private bool $isFinal = true,
3232
private ?string $classSuffix = null,
3333
) {
3434
if (str_starts_with(haystack: $this->namespace, needle: $this->rootNamespace)) {

src/Util/NamespacesHelper.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@
1313

1414
final class NamespacesHelper
1515
{
16-
/** @var string[] */
17-
private $namespaces;
18-
19-
public function __construct(array $namespaces = null)
16+
public function __construct(private array $namespaces = [])
2017
{
21-
$this->namespaces = $namespaces ?? [];
2218
}
2319

2420
public function getCommandNamespace(): string

tests/GeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testCreateClassNameDetails(
2727
string $suffix,
2828
string $expectedFullClassName,
2929
string $expectedRelativeClassName,
30-
array $namespaces = []
30+
array $namespaces = [],
3131
): void {
3232
$fileManager = $this->createMock(FileManager::class);
3333
$fileManager->expects($this->any())

tests/Util/ClassSource/ClassDataTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ClassDataTest extends TestCase
2020
{
2121
public function testStaticConstructor(): void
2222
{
23-
$meta = ClassData::create(MakerBundle::class);
23+
$meta = ClassData::create(MakerBundle::class, 'App\\');
2424

2525
// Sanity check in case Maker's NS changes
2626
self::assertSame('Symfony\Bundle\MakerBundle\MakerBundle', MakerBundle::class);
@@ -32,14 +32,14 @@ public function testStaticConstructor(): void
3232

3333
public function testGetClassDeclaration(): void
3434
{
35-
$meta = ClassData::create(MakerBundle::class);
35+
$meta = ClassData::create(MakerBundle::class, 'App\\');
3636

3737
self::assertSame('final class MakerBundle', $meta->getClassDeclaration());
3838
}
3939

4040
public function testIsFinal(): void
4141
{
42-
$meta = ClassData::create(MakerBundle::class);
42+
$meta = ClassData::create(MakerBundle::class, 'App\\');
4343

4444
// Default - isFinal - true
4545
self::assertSame('final class MakerBundle', $meta->getClassDeclaration());
@@ -51,15 +51,15 @@ public function testIsFinal(): void
5151

5252
public function testGetClassDeclarationWithExtends(): void
5353
{
54-
$meta = ClassData::create(class: MakerBundle::class, extendsClass: MakerTestKernel::class);
54+
$meta = ClassData::create(class: MakerBundle::class, rootNamespace: 'App\\', extendsClass: MakerTestKernel::class);
5555

5656
self::assertSame('final class MakerBundle extends MakerTestKernel', $meta->getClassDeclaration());
5757
}
5858

5959
/** @dataProvider suffixDataProvider */
6060
public function testSuffix(?string $suffix, string $expectedResult): void
6161
{
62-
$data = ClassData::create(class: MakerBundle::class, suffix: $suffix);
62+
$data = ClassData::create(class: MakerBundle::class, rootNamespace: 'App\\', suffix: $suffix);
6363

6464
self::assertSame($expectedResult, $data->getClassName());
6565
}
@@ -74,7 +74,7 @@ public function suffixDataProvider(): \Generator
7474
/** @dataProvider namespaceDataProvider */
7575
public function testNamespace(string $class, ?string $rootNamespace, string $expectedNamespace, string $expectedFullClassName): void
7676
{
77-
$class = ClassData::create($class);
77+
$class = ClassData::create($class, 'App\\');
7878

7979
if (null !== $rootNamespace) {
8080
$class->setRootNamespace($rootNamespace);
@@ -94,7 +94,7 @@ public function namespaceDataProvider(): \Generator
9494

9595
public function testGetClassName(): void
9696
{
97-
$class = ClassData::create(class: 'Controller\\Foo', suffix: 'Controller');
97+
$class = ClassData::create(class: 'Controller\\Foo', rootNamespace: 'App\\', suffix: 'Controller');
9898
self::assertSame('FooController', $class->getClassName());
9999
self::assertSame('Foo', $class->getClassName(relative: false, withoutSuffix: true));
100100
self::assertSame('FooController', $class->getClassName(relative: true, withoutSuffix: false));
@@ -104,7 +104,7 @@ public function testGetClassName(): void
104104

105105
public function testGetClassNameRelativeNamespace(): void
106106
{
107-
$class = ClassData::create(class: 'Controller\\Admin\\Foo', suffix: 'Controller');
107+
$class = ClassData::create(class: 'Controller\\Admin\\Foo', rootNamespace: 'App\\', suffix: 'Controller');
108108
self::assertSame('FooController', $class->getClassName());
109109
self::assertSame('Foo', $class->getClassName(relative: false, withoutSuffix: true));
110110
self::assertSame('Admin\FooController', $class->getClassName(relative: true, withoutSuffix: false));
@@ -114,7 +114,7 @@ public function testGetClassNameRelativeNamespace(): void
114114

115115
public function testGetClassNameWithAbsoluteNamespace(): void
116116
{
117-
$class = ClassData::create(class: '\\Foo\\Bar\\Admin\\Baz', suffix: 'Controller');
117+
$class = ClassData::create(class: '\\Foo\\Bar\\Admin\\Baz', rootNamespace: 'App\\', suffix: 'Controller');
118118
self::assertSame('BazController', $class->getClassName());
119119
self::assertSame('Foo\Bar\Admin', $class->getNamespace());
120120
self::assertSame('Foo\Bar\Admin\BazController', $class->getFullClassName());
@@ -123,7 +123,7 @@ public function testGetClassNameWithAbsoluteNamespace(): void
123123
/** @dataProvider fullClassNameProvider */
124124
public function testGetFullClassName(string $class, ?string $rootNamespace, bool $withoutRootNamespace, bool $withoutSuffix, string $expectedFullClassName): void
125125
{
126-
$class = ClassData::create($class, suffix: 'Controller');
126+
$class = ClassData::create($class, rootNamespace: 'App\\', suffix: 'Controller');
127127

128128
if (null !== $rootNamespace) {
129129
$class->setRootNamespace($rootNamespace);

tests/Util/TemplateComponentGeneratorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function testGetFinalClassDeclaration(bool $finalClass, bool $finalEntity
9999
{
100100
$generator = new TemplateComponentGenerator($finalClass, $finalEntity, new NamespacesHelper());
101101

102-
$classData = ClassData::create(MakerBundle::class, isEntity: $isEntity);
102+
$classData = ClassData::create(MakerBundle::class, rootNamespace: 'App\\', isEntity: $isEntity);
103103

104104
$generator->configureClass($classData);
105105

@@ -122,7 +122,7 @@ public function testConfiguresClassDataWithRootNamespace(): void
122122
{
123123
$generator = new TemplateComponentGenerator(false, false, new NamespacesHelper(['root' => 'MakerTest']));
124124

125-
$classData = ClassData::create(MakerBundle::class);
125+
$classData = ClassData::create(MakerBundle::class, 'App\\');
126126

127127
$generator->configureClass($classData);
128128

0 commit comments

Comments
 (0)