Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/Doctrine/DoctrineHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 4 additions & 7 deletions src/Doctrine/EntityClassGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 3 additions & 8 deletions src/Doctrine/EntityDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: we may be able to remove the LegacyClassMetedata - depends on doctrine version constraints...

) {
}

public function getRepositoryClass(): ?string
Expand Down
22 changes: 8 additions & 14 deletions src/Doctrine/EntityRegenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
});
Expand Down
161 changes: 66 additions & 95 deletions src/Doctrine/EntityRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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
Expand All @@ -178,7 +149,7 @@ public function getInverseClass(): string
return $this->inverseClass;
}

public function getOwningProperty()
public function getOwningProperty(): string
{
return $this->owningProperty;
}
Expand All @@ -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.');
Expand Down
1 change: 0 additions & 1 deletion src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
</service>

<service id="maker.template_component_generator" class="Symfony\Bundle\MakerBundle\Util\TemplateComponentGenerator">
<argument type="service" id="maker.php_compat_util" />
</service>
</services>
</container>
10 changes: 4 additions & 6 deletions src/Security/InteractiveSecurityHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
);
Expand Down Expand Up @@ -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. <fg=yellow>App\\Entity\\User</>)',
$this->guessUserClassDefault(),
[Validator::class, 'classIsUserInterface']
);

return $userClass;
}

private function guessUserClassDefault(): string
Expand Down Expand Up @@ -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);
});
}
Expand All @@ -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);
});
}
Expand Down
12 changes: 4 additions & 8 deletions src/Security/SecurityConfigUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
}

/**
Expand Down
8 changes: 3 additions & 5 deletions src/Security/SecurityControllerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
*/
final class SecurityControllerBuilder
{
private $phpCompatUtil;

public function __construct(PhpCompatUtil $phpCompatUtil)
{
$this->phpCompatUtil = $phpCompatUtil;
public function __construct(
private PhpCompatUtil $phpCompatUtil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should always end with a ,, it makes future diffs easier to read, also there is a PHP-CS-Fixer rule

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! thanks Oskar. Done in #1127

) {
}

public function addLoginMethod(ClassSourceManipulator $manipulator): void
Expand Down
23 changes: 8 additions & 15 deletions src/Security/UserClassConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading