Skip to content

Commit d07601f

Browse files
committed
get the property type from global generator
1 parent ee2ea8b commit d07601f

File tree

4 files changed

+12
-25
lines changed

4 files changed

+12
-25
lines changed

src/Generator.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException;
1717
use Symfony\Bundle\MakerBundle\Util\ClassNameDetails;
1818
use Symfony\Bundle\MakerBundle\Util\PhpCompatUtil;
19-
use Symfony\Bundle\MakerBundle\Util\TemplateClassHelper;
2019
use Symfony\Bundle\MakerBundle\Util\TemplateComponentGenerator;
2120

2221
/**
@@ -157,15 +156,7 @@ public function createClassNameDetails(string $name, string $namespacePrefix, st
157156
$fullNamespacePrefix = $this->fileManager->getNamespacePrefixForClass($className);
158157
}
159158

160-
return new ClassNameDetails($className, $fullNamespacePrefix, $suffix, $this->phpCompatUtil->canUseTypedProperties());
161-
}
162-
163-
/**
164-
* @experimental The method signature may change, moved, or be removed.
165-
*/
166-
public function createClassHelper(string $fullyQualifiedClassName): TemplateClassHelper
167-
{
168-
return new TemplateClassHelper($fullyQualifiedClassName, $this->phpCompatUtil->canUseTypedProperties());
159+
return new ClassNameDetails($className, $fullNamespacePrefix, $suffix);
169160
}
170161

171162
public function getRootDirectory(): string

src/Resources/skeleton/registration/RegistrationController.tpl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class <?= $class_name; ?> extends <?= $parent_class_name; ?><?= "\n" ?>
88
{
99
<?php if ($will_verify_email): ?>
10-
private <?= $email_verifier_class_details->getPropertyType() ?>$emailVerifier;
10+
private <?= $generator->getPropertyType($email_verifier_class_details) ?>$emailVerifier;
1111

1212
public function __construct(<?= $email_verifier_class_details->getShortName() ?> $emailVerifier)
1313
{

src/Util/ClassNameDetails.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,12 @@ final class ClassNameDetails
1818
private $fullClassName;
1919
private $namespacePrefix;
2020
private $suffix;
21-
private $usesTypedProperties;
2221

23-
public function __construct(string $fullClassName, string $namespacePrefix, string $suffix = null, ?bool $usesTypedProperties = null)
22+
public function __construct(string $fullClassName, string $namespacePrefix, string $suffix = null)
2423
{
2524
$this->fullClassName = $fullClassName;
2625
$this->namespacePrefix = trim($namespacePrefix, '\\');
2726
$this->suffix = $suffix;
28-
$this->usesTypedProperties = $usesTypedProperties;
29-
30-
// @TODO throw deprecation if bool not passed....
3127
}
3228

3329
public function getFullName(): string
@@ -40,15 +36,6 @@ public function getShortName(): string
4036
return Str::getShortClassName($this->fullClassName);
4137
}
4238

43-
public function getPropertyType(): ?string
44-
{
45-
if (!$this->usesTypedProperties) {
46-
return null;
47-
}
48-
49-
return sprintf('%s ', $this->getShortName());
50-
}
51-
5239
/**
5340
* Returns the original class name the user entered (after
5441
* being cleaned up).

src/Util/TemplateComponentGenerator.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,13 @@ public function generateRouteForControllerMethod(string $routePath, string $rout
8787

8888
return $annotation;
8989
}
90+
91+
public function getPropertyType(ClassNameDetails $classNameDetails): ?string
92+
{
93+
if (!$this->phpCompatUtil->canUseTypedProperties()) {
94+
return null;
95+
}
96+
97+
return sprintf('%s ', $classNameDetails->getShortName());
98+
}
9099
}

0 commit comments

Comments
 (0)