diff --git a/src/Doctrine/DoctrineHelper.php b/src/Doctrine/DoctrineHelper.php
index b5f7fb55c..ff54aa3da 100644
--- a/src/Doctrine/DoctrineHelper.php
+++ b/src/Doctrine/DoctrineHelper.php
@@ -166,10 +166,7 @@ public function getEntitiesForAutocomplete(): array
return $entities;
}
- /**
- * @return array|ClassMetadata
- */
- public function getMetadata(string $classOrNamespace = null, bool $disconnected = false)
+ public function getMetadata(string $classOrNamespace = null, bool $disconnected = false): array|ClassMetadata
{
// Invalidating the cached AnnotationDriver::$classNames to find new Entity classes
foreach ($this->mappingDriversByPrefix ?? [] as $managerName => $prefixes) {
diff --git a/src/Doctrine/EntityClassGenerator.php b/src/Doctrine/EntityClassGenerator.php
index b937824f4..09821e267 100644
--- a/src/Doctrine/EntityClassGenerator.php
+++ b/src/Doctrine/EntityClassGenerator.php
@@ -30,13 +30,10 @@
*/
final class EntityClassGenerator
{
- private $generator;
- private $doctrineHelper;
-
- public function __construct(Generator $generator, DoctrineHelper $doctrineHelper)
- {
- $this->generator = $generator;
- $this->doctrineHelper = $doctrineHelper;
+ public function __construct(
+ private Generator $generator,
+ private DoctrineHelper $doctrineHelper,
+ ) {
}
public function generateEntityClass(ClassNameDetails $entityClassDetails, bool $apiResource, bool $withPasswordUpgrade = false, bool $generateRepositoryClass = true, bool $broadcast = false): string
diff --git a/src/Doctrine/EntityDetails.php b/src/Doctrine/EntityDetails.php
index 36b3cb83c..22c94ae81 100644
--- a/src/Doctrine/EntityDetails.php
+++ b/src/Doctrine/EntityDetails.php
@@ -21,14 +21,9 @@
*/
final class EntityDetails
{
- private $metadata;
-
- /**
- * @param ClassMetadata|LegacyClassMetadata $metadata
- */
- public function __construct($metadata)
- {
- $this->metadata = $metadata;
+ public function __construct(
+ private ClassMetadata|LegacyClassMetadata $metadata
+ ) {
}
public function getRepositoryClass(): ?string
diff --git a/src/Doctrine/EntityRegenerator.php b/src/Doctrine/EntityRegenerator.php
index b5caadee7..49f5940ed 100644
--- a/src/Doctrine/EntityRegenerator.php
+++ b/src/Doctrine/EntityRegenerator.php
@@ -25,19 +25,13 @@
*/
final class EntityRegenerator
{
- private $doctrineHelper;
- private $fileManager;
- private $generator;
- private $entityClassGenerator;
- private $overwrite;
-
- public function __construct(DoctrineHelper $doctrineHelper, FileManager $fileManager, Generator $generator, EntityClassGenerator $entityClassGenerator, bool $overwrite)
- {
- $this->doctrineHelper = $doctrineHelper;
- $this->fileManager = $fileManager;
- $this->generator = $generator;
- $this->entityClassGenerator = $entityClassGenerator;
- $this->overwrite = $overwrite;
+ public function __construct(
+ private DoctrineHelper $doctrineHelper,
+ private FileManager $fileManager,
+ private Generator $generator,
+ private EntityClassGenerator $entityClassGenerator,
+ private bool $overwrite
+ ) {
}
public function regenerateEntities(string $classOrNamespace): void
@@ -263,7 +257,7 @@ private function getMappedFieldsInEntity(ClassMetadata $classMetadata): array
$targetFields = array_diff($targetFields, $traitProperties);
// exclude inherited properties
- $targetFields = array_filter($targetFields, function ($field) use ($classReflection) {
+ $targetFields = array_filter($targetFields, static function ($field) use ($classReflection) {
return $classReflection->hasProperty($field) &&
$classReflection->getProperty($field)->getDeclaringClass()->getName() == $classReflection->getName();
});
diff --git a/src/Doctrine/EntityRelation.php b/src/Doctrine/EntityRelation.php
index 0897555da..ff81f5350 100644
--- a/src/Doctrine/EntityRelation.php
+++ b/src/Doctrine/EntityRelation.php
@@ -21,26 +21,18 @@ final class EntityRelation
public const MANY_TO_MANY = 'ManyToMany';
public const ONE_TO_ONE = 'OneToOne';
- private $type;
-
- private $owningClass;
-
- private $inverseClass;
-
private $owningProperty;
-
private $inverseProperty;
-
- private $isNullable = false;
-
- private $isSelfReferencing = false;
-
- private $orphanRemoval = false;
-
- private $mapInverseRelation = true;
-
- public function __construct(string $type, string $owningClass, string $inverseClass)
- {
+ private bool $isNullable = false;
+ private bool $isSelfReferencing = false;
+ private bool $orphanRemoval = false;
+ private bool $mapInverseRelation = true;
+
+ public function __construct(
+ private string $type,
+ private string $owningClass,
+ private string $inverseClass
+ ) {
if (!\in_array($type, self::getValidRelationTypes())) {
throw new \Exception(sprintf('Invalid relation type "%s"', $type));
}
@@ -49,9 +41,6 @@ public function __construct(string $type, string $owningClass, string $inverseCl
throw new \Exception('Use ManyToOne instead of OneToMany');
}
- $this->type = $type;
- $this->owningClass = $owningClass;
- $this->inverseClass = $inverseClass;
$this->isSelfReferencing = $owningClass === $inverseClass;
}
@@ -89,78 +78,60 @@ public static function getValidRelationTypes(): array
];
}
- public function getOwningRelation()
- {
- switch ($this->getType()) {
- case self::MANY_TO_ONE:
- return (new RelationManyToOne())
- ->setPropertyName($this->owningProperty)
- ->setTargetClassName($this->inverseClass)
- ->setTargetPropertyName($this->inverseProperty)
- ->setIsNullable($this->isNullable)
- ->setIsSelfReferencing($this->isSelfReferencing)
- ->setMapInverseRelation($this->mapInverseRelation)
- ;
- break;
- case self::MANY_TO_MANY:
- return (new RelationManyToMany())
- ->setPropertyName($this->owningProperty)
- ->setTargetClassName($this->inverseClass)
- ->setTargetPropertyName($this->inverseProperty)
- ->setIsOwning(true)->setMapInverseRelation($this->mapInverseRelation)
- ->setIsSelfReferencing($this->isSelfReferencing)
- ;
- break;
- case self::ONE_TO_ONE:
- return (new RelationOneToOne())
- ->setPropertyName($this->owningProperty)
- ->setTargetClassName($this->inverseClass)
- ->setTargetPropertyName($this->inverseProperty)
- ->setIsNullable($this->isNullable)
- ->setIsOwning(true)
- ->setIsSelfReferencing($this->isSelfReferencing)
- ->setMapInverseRelation($this->mapInverseRelation)
- ;
- break;
- default:
- throw new \InvalidArgumentException('Invalid type');
- }
- }
-
- public function getInverseRelation()
- {
- switch ($this->getType()) {
- case self::MANY_TO_ONE:
- return (new RelationOneToMany())
- ->setPropertyName($this->inverseProperty)
- ->setTargetClassName($this->owningClass)
- ->setTargetPropertyName($this->owningProperty)
- ->setOrphanRemoval($this->orphanRemoval)
- ->setIsSelfReferencing($this->isSelfReferencing)
- ;
- break;
- case self::MANY_TO_MANY:
- return (new RelationManyToMany())
- ->setPropertyName($this->inverseProperty)
- ->setTargetClassName($this->owningClass)
- ->setTargetPropertyName($this->owningProperty)
- ->setIsOwning(false)
- ->setIsSelfReferencing($this->isSelfReferencing)
- ;
- break;
- case self::ONE_TO_ONE:
- return (new RelationOneToOne())
- ->setPropertyName($this->inverseProperty)
- ->setTargetClassName($this->owningClass)
- ->setTargetPropertyName($this->owningProperty)
- ->setIsNullable($this->isNullable)
- ->setIsOwning(false)
- ->setIsSelfReferencing($this->isSelfReferencing)
- ;
- break;
- default:
- throw new \InvalidArgumentException('Invalid type');
- }
+ public function getOwningRelation(): RelationManyToMany|RelationOneToOne|RelationManyToOne
+ {
+ return match ($this->getType()) {
+ self::MANY_TO_ONE => (new RelationManyToOne())
+ ->setPropertyName($this->owningProperty)
+ ->setTargetClassName($this->inverseClass)
+ ->setTargetPropertyName($this->inverseProperty)
+ ->setIsNullable($this->isNullable)
+ ->setIsSelfReferencing($this->isSelfReferencing)
+ ->setMapInverseRelation($this->mapInverseRelation),
+ self::MANY_TO_MANY => (new RelationManyToMany())
+ ->setPropertyName($this->owningProperty)
+ ->setTargetClassName($this->inverseClass)
+ ->setTargetPropertyName($this->inverseProperty)
+ ->setIsOwning(true)->setMapInverseRelation(
+ $this->mapInverseRelation
+ )
+ ->setIsSelfReferencing($this->isSelfReferencing),
+ self::ONE_TO_ONE => (new RelationOneToOne())
+ ->setPropertyName($this->owningProperty)
+ ->setTargetClassName($this->inverseClass)
+ ->setTargetPropertyName($this->inverseProperty)
+ ->setIsNullable($this->isNullable)
+ ->setIsOwning(true)
+ ->setIsSelfReferencing($this->isSelfReferencing)
+ ->setMapInverseRelation($this->mapInverseRelation),
+ default => throw new \InvalidArgumentException('Invalid type'),
+ };
+ }
+
+ public function getInverseRelation(): RelationManyToMany|RelationOneToOne|RelationOneToMany
+ {
+ return match ($this->getType()) {
+ self::MANY_TO_ONE => (new RelationOneToMany())
+ ->setPropertyName($this->inverseProperty)
+ ->setTargetClassName($this->owningClass)
+ ->setTargetPropertyName($this->owningProperty)
+ ->setOrphanRemoval($this->orphanRemoval)
+ ->setIsSelfReferencing($this->isSelfReferencing),
+ self::MANY_TO_MANY => (new RelationManyToMany())
+ ->setPropertyName($this->inverseProperty)
+ ->setTargetClassName($this->owningClass)
+ ->setTargetPropertyName($this->owningProperty)
+ ->setIsOwning(false)
+ ->setIsSelfReferencing($this->isSelfReferencing),
+ self::ONE_TO_ONE => (new RelationOneToOne())
+ ->setPropertyName($this->inverseProperty)
+ ->setTargetClassName($this->owningClass)
+ ->setTargetPropertyName($this->owningProperty)
+ ->setIsNullable($this->isNullable)
+ ->setIsOwning(false)
+ ->setIsSelfReferencing($this->isSelfReferencing),
+ default => throw new \InvalidArgumentException('Invalid type'),
+ };
}
public function getType(): string
@@ -178,7 +149,7 @@ public function getInverseClass(): string
return $this->inverseClass;
}
- public function getOwningProperty()
+ public function getOwningProperty(): string
{
return $this->owningProperty;
}
@@ -203,7 +174,7 @@ public function getMapInverseRelation(): bool
return $this->mapInverseRelation;
}
- public function setMapInverseRelation(bool $mapInverseRelation)
+ public function setMapInverseRelation(bool $mapInverseRelation): void
{
if ($mapInverseRelation && $this->inverseProperty) {
throw new \Exception('Cannot set setMapInverseRelation() to true when the inverse relation property is set.');
diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml
index a61bf9e19..ed3438e8e 100644
--- a/src/Resources/config/services.xml
+++ b/src/Resources/config/services.xml
@@ -77,7 +77,6 @@
-
diff --git a/src/Security/InteractiveSecurityHelper.php b/src/Security/InteractiveSecurityHelper.php
index cc4cf276f..6da9cb6e4 100644
--- a/src/Security/InteractiveSecurityHelper.php
+++ b/src/Security/InteractiveSecurityHelper.php
@@ -25,7 +25,7 @@ public function guessFirewallName(SymfonyStyle $io, array $securityData, string
{
$realFirewalls = array_filter(
$securityData['security']['firewalls'] ?? [],
- function ($item) {
+ static function ($item) {
return !isset($item['security']) || true === $item['security'];
}
);
@@ -53,13 +53,11 @@ public function guessUserClass(SymfonyStyle $io, array $providers, string $quest
return $entityProvider['entity']['class'];
}
- $userClass = $io->ask(
+ return $io->ask(
$questionText ?? 'Enter the User class that you want to authenticate (e.g. App\\Entity\\User>)',
$this->guessUserClassDefault(),
[Validator::class, 'classIsUserInterface']
);
-
- return $userClass;
}
private function guessUserClassDefault(): string
@@ -147,7 +145,7 @@ public function guessPasswordField(SymfonyStyle $io, string $userClass): string
public function getAuthenticatorClasses(array $firewallData): array
{
if (isset($firewallData['guard'])) {
- return array_filter($firewallData['guard']['authenticators'] ?? [], function ($authenticator) {
+ return array_filter($firewallData['guard']['authenticators'] ?? [], static function ($authenticator) {
return class_exists($authenticator);
});
}
@@ -158,7 +156,7 @@ public function getAuthenticatorClasses(array $firewallData): array
$authenticators = [$authenticators];
}
- return array_filter($authenticators, function ($authenticator) {
+ return array_filter($authenticators, static function ($authenticator) {
return class_exists($authenticator);
});
}
diff --git a/src/Security/SecurityConfigUpdater.php b/src/Security/SecurityConfigUpdater.php
index 19d3d7749..4c7c971b9 100644
--- a/src/Security/SecurityConfigUpdater.php
+++ b/src/Security/SecurityConfigUpdater.php
@@ -23,15 +23,11 @@
*/
final class SecurityConfigUpdater
{
- /** @var YamlSourceManipulator */
- private $manipulator;
+ private ?YamlSourceManipulator $manipulator;
- /** @var Logger|null */
- private $ysmLogger;
-
- public function __construct(Logger $ysmLogger = null)
- {
- $this->ysmLogger = $ysmLogger;
+ public function __construct(
+ private ?Logger $ysmLogger = null
+ ) {
}
/**
diff --git a/src/Security/SecurityControllerBuilder.php b/src/Security/SecurityControllerBuilder.php
index 6123c401d..e5da6d0b0 100644
--- a/src/Security/SecurityControllerBuilder.php
+++ b/src/Security/SecurityControllerBuilder.php
@@ -22,11 +22,9 @@
*/
final class SecurityControllerBuilder
{
- private $phpCompatUtil;
-
- public function __construct(PhpCompatUtil $phpCompatUtil)
- {
- $this->phpCompatUtil = $phpCompatUtil;
+ public function __construct(
+ private PhpCompatUtil $phpCompatUtil
+ ) {
}
public function addLoginMethod(ClassSourceManipulator $manipulator): void
diff --git a/src/Security/UserClassConfiguration.php b/src/Security/UserClassConfiguration.php
index bb03e188b..9fb547269 100644
--- a/src/Security/UserClassConfiguration.php
+++ b/src/Security/UserClassConfiguration.php
@@ -18,21 +18,14 @@
*/
final class UserClassConfiguration
{
- private $isEntity;
-
- private $identityPropertyName;
-
- private $hasPassword;
-
- private $useArgon2 = false;
-
- private $userProviderClass;
-
- public function __construct(bool $isEntity, string $identityPropertyName, bool $hasPassword)
- {
- $this->isEntity = $isEntity;
- $this->identityPropertyName = $identityPropertyName;
- $this->hasPassword = $hasPassword;
+ private bool $useArgon2 = false;
+ private string $userProviderClass;
+
+ public function __construct(
+ private bool $isEntity,
+ private string $identityPropertyName,
+ private bool $hasPassword,
+ ) {
}
public function isEntity(): bool
diff --git a/src/Util/AutoloaderUtil.php b/src/Util/AutoloaderUtil.php
index 5338637ce..b006e91b1 100644
--- a/src/Util/AutoloaderUtil.php
+++ b/src/Util/AutoloaderUtil.php
@@ -20,14 +20,9 @@
*/
class AutoloaderUtil
{
- /**
- * @var ComposerAutoloaderFinder
- */
- private $autoloaderFinder;
-
- public function __construct(ComposerAutoloaderFinder $autoloaderFinder)
- {
- $this->autoloaderFinder = $autoloaderFinder;
+ public function __construct(
+ private ComposerAutoloaderFinder $autoloaderFinder
+ ) {
}
/**
diff --git a/src/Util/ClassDetails.php b/src/Util/ClassDetails.php
index 9ee94dda3..8f4b3352c 100644
--- a/src/Util/ClassDetails.php
+++ b/src/Util/ClassDetails.php
@@ -16,11 +16,9 @@
*/
final class ClassDetails
{
- private $fullClassName;
-
- public function __construct(string $fullClassName)
- {
- $this->fullClassName = $fullClassName;
+ public function __construct(
+ private string $fullClassName
+ ) {
}
/**
diff --git a/src/Util/ClassNameDetails.php b/src/Util/ClassNameDetails.php
index e0c282576..e1df74ee0 100644
--- a/src/Util/ClassNameDetails.php
+++ b/src/Util/ClassNameDetails.php
@@ -15,15 +15,12 @@
final class ClassNameDetails
{
- private $fullClassName;
- private $namespacePrefix;
- private $suffix;
-
- public function __construct(string $fullClassName, string $namespacePrefix, string $suffix = null)
- {
- $this->fullClassName = $fullClassName;
+ public function __construct(
+ private string $fullClassName,
+ private string $namespacePrefix,
+ private ?string $suffix = null
+ ) {
$this->namespacePrefix = trim($namespacePrefix, '\\');
- $this->suffix = $suffix;
}
public function getFullName(): string
diff --git a/src/Util/ClassNameValue.php b/src/Util/ClassNameValue.php
index d8c4a8db0..71e7a42ff 100644
--- a/src/Util/ClassNameValue.php
+++ b/src/Util/ClassNameValue.php
@@ -18,13 +18,10 @@
*/
final class ClassNameValue
{
- private $typeHint;
- private $fullClassName;
-
- public function __construct(string $typeHint, string $fullClassName)
- {
- $this->typeHint = $typeHint;
- $this->fullClassName = $fullClassName;
+ public function __construct(
+ private string $typeHint,
+ private string $fullClassName
+ ) {
}
public function getShortName(): string
diff --git a/src/Util/ComposeFileManipulator.php b/src/Util/ComposeFileManipulator.php
index 339899bbd..30dbf9dae 100644
--- a/src/Util/ComposeFileManipulator.php
+++ b/src/Util/ComposeFileManipulator.php
@@ -26,8 +26,7 @@ class ComposeFileManipulator
{
public const COMPOSE_FILE_VERSION = '3.7';
- /** @var YamlSourceManipulator */
- private $manipulator;
+ private YamlSourceManipulator $manipulator;
public function __construct(string $contents)
{
diff --git a/src/Util/TemplateComponentGenerator.php b/src/Util/TemplateComponentGenerator.php
index 0f4e444dd..5b8bbd566 100644
--- a/src/Util/TemplateComponentGenerator.php
+++ b/src/Util/TemplateComponentGenerator.php
@@ -21,13 +21,6 @@
*/
final class TemplateComponentGenerator
{
- private $phpCompatUtil;
-
- public function __construct(PhpCompatUtil $phpCompatUtil)
- {
- $this->phpCompatUtil = $phpCompatUtil;
- }
-
public function generateRouteForControllerMethod(string $routePath, string $routeName, array $methods = [], bool $indent = true, bool $trailingNewLine = true): string
{
$attribute = sprintf('%s#[Route(\'%s\', name: \'%s\'', $indent ? ' ' : null, $routePath, $routeName);
diff --git a/src/Util/UseStatementGenerator.php b/src/Util/UseStatementGenerator.php
index ccc5cbff2..a5d297851 100644
--- a/src/Util/UseStatementGenerator.php
+++ b/src/Util/UseStatementGenerator.php
@@ -20,8 +20,6 @@
*/
final class UseStatementGenerator implements \Stringable
{
- private $classesToBeImported;
-
/**
* For use statements that contain aliases, the $classesToBeImported array
* may contain an array(s) like [\Some\Class::class => 'ZYX']. The generated
@@ -30,9 +28,9 @@ final class UseStatementGenerator implements \Stringable
*
* @param string[]|array $classesToBeImported
*/
- public function __construct(array $classesToBeImported)
- {
- $this->classesToBeImported = $classesToBeImported;
+ public function __construct(
+ private array $classesToBeImported
+ ) {
}
public function __toString(): string
@@ -72,7 +70,7 @@ public function __toString(): string
/**
* @param string|string[]|array $className
*/
- public function addUseStatement($className): void
+ public function addUseStatement(array|string $className): void
{
if (\is_array($className)) {
$this->classesToBeImported = array_merge($this->classesToBeImported, $className);
diff --git a/src/Util/YamlSourceManipulator.php b/src/Util/YamlSourceManipulator.php
index 90b8914ca..f1049ecd7 100644
--- a/src/Util/YamlSourceManipulator.php
+++ b/src/Util/YamlSourceManipulator.php
@@ -38,8 +38,6 @@ class YamlSourceManipulator
* @var LoggerInterface|null
*/
private $logger;
-
- private $contents;
private $currentData;
private $currentPosition = 0;
@@ -50,9 +48,9 @@ class YamlSourceManipulator
private $arrayFormatForDepths = [];
private $arrayTypeForDepths = [];
- public function __construct(string $contents)
- {
- $this->contents = $contents;
+ public function __construct(
+ private string $contents
+ ) {
$this->currentData = Yaml::parse($contents);
if (!\is_array($this->currentData)) {