From ffd47ce2dd88fc613be7170101a1f9221e648d76 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Thu, 22 Sep 2022 11:24:05 +0200 Subject: [PATCH] Add types to mapping builders (#10052) --- .../Mapping/Builder/AssociationBuilder.php | 85 ++++----- .../Mapping/Builder/ClassMetadataBuilder.php | 168 +++++------------- .../ORM/Mapping/Builder/EmbeddedBuilder.php | 22 +-- .../Mapping/Builder/EntityListenerBuilder.php | 10 +- .../ORM/Mapping/Builder/FieldBuilder.php | 93 +++------- .../Builder/ManyToManyAssociationBuilder.php | 33 ++-- .../Builder/OneToManyAssociationBuilder.php | 13 +- psalm-baseline.xml | 12 -- .../ORM/Mapping/ClassMetadataBuilderTest.php | 4 +- 9 files changed, 131 insertions(+), 309 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Builder/AssociationBuilder.php b/lib/Doctrine/ORM/Mapping/Builder/AssociationBuilder.php index 0b8bc3cdff0..50817b4c39b 100644 --- a/lib/Doctrine/ORM/Mapping/Builder/AssociationBuilder.php +++ b/lib/Doctrine/ORM/Mapping/Builder/AssociationBuilder.php @@ -9,43 +9,27 @@ class AssociationBuilder { - /** @var ClassMetadataBuilder */ - protected $builder; - - /** @var mixed[] */ - protected $mapping; - /** @var mixed[]|null */ - protected $joinColumns; + protected array|null $joinColumns = null; - /** - * @param mixed[] $mapping - * @param int $type - */ - public function __construct(ClassMetadataBuilder $builder, array $mapping, protected $type) - { - $this->builder = $builder; - $this->mapping = $mapping; + /** @param mixed[] $mapping */ + public function __construct( + protected readonly ClassMetadataBuilder $builder, + protected array $mapping, + protected readonly int $type, + ) { } - /** - * @param string $fieldName - * - * @return $this - */ - public function mappedBy($fieldName) + /** @return $this */ + public function mappedBy(string $fieldName): static { $this->mapping['mappedBy'] = $fieldName; return $this; } - /** - * @param string $fieldName - * - * @return $this - */ - public function inversedBy($fieldName) + /** @return $this */ + public function inversedBy(string $fieldName): static { $this->mapping['inversedBy'] = $fieldName; @@ -53,7 +37,7 @@ public function inversedBy($fieldName) } /** @return $this */ - public function cascadeAll() + public function cascadeAll(): static { $this->mapping['cascade'] = ['ALL']; @@ -61,7 +45,7 @@ public function cascadeAll() } /** @return $this */ - public function cascadePersist() + public function cascadePersist(): static { $this->mapping['cascade'][] = 'persist'; @@ -69,7 +53,7 @@ public function cascadePersist() } /** @return $this */ - public function cascadeRemove() + public function cascadeRemove(): static { $this->mapping['cascade'][] = 'remove'; @@ -77,7 +61,7 @@ public function cascadeRemove() } /** @return $this */ - public function cascadeMerge() + public function cascadeMerge(): static { $this->mapping['cascade'][] = 'merge'; @@ -85,7 +69,7 @@ public function cascadeMerge() } /** @return $this */ - public function cascadeDetach() + public function cascadeDetach(): static { $this->mapping['cascade'][] = 'detach'; @@ -93,7 +77,7 @@ public function cascadeDetach() } /** @return $this */ - public function cascadeRefresh() + public function cascadeRefresh(): static { $this->mapping['cascade'][] = 'refresh'; @@ -101,7 +85,7 @@ public function cascadeRefresh() } /** @return $this */ - public function fetchExtraLazy() + public function fetchExtraLazy(): static { $this->mapping['fetch'] = ClassMetadata::FETCH_EXTRA_LAZY; @@ -109,7 +93,7 @@ public function fetchExtraLazy() } /** @return $this */ - public function fetchEager() + public function fetchEager(): static { $this->mapping['fetch'] = ClassMetadata::FETCH_EAGER; @@ -117,7 +101,7 @@ public function fetchEager() } /** @return $this */ - public function fetchLazy() + public function fetchLazy(): static { $this->mapping['fetch'] = ClassMetadata::FETCH_LAZY; @@ -127,17 +111,16 @@ public function fetchLazy() /** * Add Join Columns. * - * @param string $columnName - * @param string $referencedColumnName - * @param bool $nullable - * @param bool $unique - * @param string|null $onDelete - * @param string|null $columnDef - * * @return $this */ - public function addJoinColumn($columnName, $referencedColumnName, $nullable = true, $unique = false, $onDelete = null, $columnDef = null) - { + public function addJoinColumn( + string $columnName, + string $referencedColumnName, + bool $nullable = true, + bool $unique = false, + string|null $onDelete = null, + string|null $columnDef = null, + ): static { $this->joinColumns[] = [ 'name' => $columnName, 'referencedColumnName' => $referencedColumnName, @@ -155,7 +138,7 @@ public function addJoinColumn($columnName, $referencedColumnName, $nullable = tr * * @return $this */ - public function makePrimaryKey() + public function makePrimaryKey(): static { $this->mapping['id'] = true; @@ -167,19 +150,15 @@ public function makePrimaryKey() * * @return $this */ - public function orphanRemoval() + public function orphanRemoval(): static { $this->mapping['orphanRemoval'] = true; return $this; } - /** - * @return ClassMetadataBuilder - * - * @throws InvalidArgumentException - */ - public function build() + /** @throws InvalidArgumentException */ + public function build(): ClassMetadataBuilder { $mapping = $this->mapping; if ($this->joinColumns) { diff --git a/lib/Doctrine/ORM/Mapping/Builder/ClassMetadataBuilder.php b/lib/Doctrine/ORM/Mapping/Builder/ClassMetadataBuilder.php index d023481955e..d3798805aa2 100644 --- a/lib/Doctrine/ORM/Mapping/Builder/ClassMetadataBuilder.php +++ b/lib/Doctrine/ORM/Mapping/Builder/ClassMetadataBuilder.php @@ -13,12 +13,9 @@ */ class ClassMetadataBuilder { - /** @var ClassMetadata */ - private $cm; - - public function __construct(ClassMetadata $cm) - { - $this->cm = $cm; + public function __construct( + private readonly ClassMetadata $cm, + ) { } public function getClassMetadata(): ClassMetadata @@ -31,7 +28,7 @@ public function getClassMetadata(): ClassMetadata * * @return $this */ - public function setMappedSuperClass() + public function setMappedSuperClass(): static { $this->cm->isMappedSuperclass = true; $this->cm->isEmbeddedClass = false; @@ -44,7 +41,7 @@ public function setMappedSuperClass() * * @return $this */ - public function setEmbeddable() + public function setEmbeddable(): static { $this->cm->isEmbeddedClass = true; $this->cm->isMappedSuperclass = false; @@ -55,13 +52,9 @@ public function setEmbeddable() /** * Adds and embedded class * - * @param string $fieldName - * @param string $class - * @param string|false|null $columnPrefix - * * @return $this */ - public function addEmbedded($fieldName, $class, $columnPrefix = null) + public function addEmbedded(string $fieldName, string $class, string|false|null $columnPrefix = null): static { $this->cm->mapEmbedded( [ @@ -77,11 +70,9 @@ public function addEmbedded($fieldName, $class, $columnPrefix = null) /** * Sets custom Repository class name. * - * @param string $repositoryClassName - * * @return $this */ - public function setCustomRepositoryClass($repositoryClassName) + public function setCustomRepositoryClass(string $repositoryClassName): static { $this->cm->setCustomRepositoryClass($repositoryClassName); @@ -93,7 +84,7 @@ public function setCustomRepositoryClass($repositoryClassName) * * @return $this */ - public function setReadOnly() + public function setReadOnly(): static { $this->cm->markReadOnly(); @@ -103,11 +94,9 @@ public function setReadOnly() /** * Sets the table name. * - * @param string $name - * * @return $this */ - public function setTable($name) + public function setTable(string $name): static { $this->cm->setPrimaryTable(['name' => $name]); @@ -117,12 +106,11 @@ public function setTable($name) /** * Adds Index. * - * @param string $name * @psalm-param list $columns * * @return $this */ - public function addIndex(array $columns, $name) + public function addIndex(array $columns, string $name): static { if (! isset($this->cm->table['indexes'])) { $this->cm->table['indexes'] = []; @@ -136,12 +124,11 @@ public function addIndex(array $columns, $name) /** * Adds Unique Constraint. * - * @param string $name * @psalm-param list $columns * * @return $this */ - public function addUniqueConstraint(array $columns, $name) + public function addUniqueConstraint(array $columns, string $name): static { if (! isset($this->cm->table['uniqueConstraints'])) { $this->cm->table['uniqueConstraints'] = []; @@ -157,7 +144,7 @@ public function addUniqueConstraint(array $columns, $name) * * @return $this */ - public function setJoinedTableInheritance() + public function setJoinedTableInheritance(): static { $this->cm->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_JOINED); @@ -169,7 +156,7 @@ public function setJoinedTableInheritance() * * @return $this */ - public function setSingleTableInheritance() + public function setSingleTableInheritance(): static { $this->cm->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_SINGLE_TABLE); @@ -179,13 +166,9 @@ public function setSingleTableInheritance() /** * Sets the discriminator column details. * - * @param string $name - * @param string $type - * @param int $length - * * @return $this */ - public function setDiscriminatorColumn($name, $type = 'string', $length = 255) + public function setDiscriminatorColumn(string $name, string $type = 'string', int $length = 255): static { $this->cm->setDiscriminatorColumn( [ @@ -201,12 +184,9 @@ public function setDiscriminatorColumn($name, $type = 'string', $length = 255) /** * Adds a subclass to this inheritance hierarchy. * - * @param string $name - * @param string $class - * * @return $this */ - public function addDiscriminatorMapClass($name, $class) + public function addDiscriminatorMapClass(string $name, string $class): static { $this->cm->addDiscriminatorMapClass($name, $class); @@ -218,7 +198,7 @@ public function addDiscriminatorMapClass($name, $class) * * @return $this */ - public function setChangeTrackingPolicyDeferredExplicit() + public function setChangeTrackingPolicyDeferredExplicit(): static { $this->cm->setChangeTrackingPolicy(ClassMetadata::CHANGETRACKING_DEFERRED_EXPLICIT); @@ -230,7 +210,7 @@ public function setChangeTrackingPolicyDeferredExplicit() * * @return $this */ - public function setChangeTrackingPolicyNotify() + public function setChangeTrackingPolicyNotify(): static { $this->cm->setChangeTrackingPolicy(ClassMetadata::CHANGETRACKING_NOTIFY); @@ -240,12 +220,9 @@ public function setChangeTrackingPolicyNotify() /** * Adds lifecycle event. * - * @param string $methodName - * @param string $event - * * @return $this */ - public function addLifecycleEvent($methodName, $event) + public function addLifecycleEvent(string $methodName, string $event): static { $this->cm->addLifecycleCallback($methodName, $event); @@ -255,13 +232,11 @@ public function addLifecycleEvent($methodName, $event) /** * Adds Field. * - * @param string $name - * @param string $type * @psalm-param array $mapping * * @return $this */ - public function addField($name, $type, array $mapping = []) + public function addField(string $name, string $type, array $mapping = []): static { $mapping['fieldName'] = $name; $mapping['type'] = $type; @@ -273,13 +248,8 @@ public function addField($name, $type, array $mapping = []) /** * Creates a field builder. - * - * @param string $name - * @param string $type - * - * @return FieldBuilder */ - public function createField($name, $type) + public function createField(string $name, string $type): FieldBuilder { return new FieldBuilder( $this, @@ -292,13 +262,8 @@ public function createField($name, $type) /** * Creates an embedded builder. - * - * @param string $fieldName - * @param string $class - * - * @return EmbeddedBuilder */ - public function createEmbedded($fieldName, $class) + public function createEmbedded(string $fieldName, string $class): EmbeddedBuilder { return new EmbeddedBuilder( $this, @@ -312,15 +277,12 @@ public function createEmbedded($fieldName, $class) /** * Adds a simple many to one association, optionally with the inversed by field. - * - * @param string $name - * @param string $targetEntity - * @param string|null $inversedBy - * - * @return ClassMetadataBuilder */ - public function addManyToOne($name, $targetEntity, $inversedBy = null) - { + public function addManyToOne( + string $name, + string $targetEntity, + string|null $inversedBy = null, + ): ClassMetadataBuilder { $builder = $this->createManyToOne($name, $targetEntity); if ($inversedBy) { @@ -334,13 +296,8 @@ public function addManyToOne($name, $targetEntity, $inversedBy = null) * Creates a ManyToOne Association Builder. * * Note: This method does not add the association, you have to call build() on the AssociationBuilder. - * - * @param string $name - * @param string $targetEntity - * - * @return AssociationBuilder */ - public function createManyToOne($name, $targetEntity) + public function createManyToOne(string $name, string $targetEntity): AssociationBuilder { return new AssociationBuilder( $this, @@ -354,13 +311,8 @@ public function createManyToOne($name, $targetEntity) /** * Creates a OneToOne Association Builder. - * - * @param string $name - * @param string $targetEntity - * - * @return AssociationBuilder */ - public function createOneToOne($name, $targetEntity) + public function createOneToOne(string $name, string $targetEntity): AssociationBuilder { return new AssociationBuilder( $this, @@ -374,14 +326,8 @@ public function createOneToOne($name, $targetEntity) /** * Adds simple inverse one-to-one association. - * - * @param string $name - * @param string $targetEntity - * @param string $mappedBy - * - * @return ClassMetadataBuilder */ - public function addInverseOneToOne($name, $targetEntity, $mappedBy) + public function addInverseOneToOne(string $name, string $targetEntity, string $mappedBy): ClassMetadataBuilder { $builder = $this->createOneToOne($name, $targetEntity); $builder->mappedBy($mappedBy); @@ -391,15 +337,12 @@ public function addInverseOneToOne($name, $targetEntity, $mappedBy) /** * Adds simple owning one-to-one association. - * - * @param string $name - * @param string $targetEntity - * @param string|null $inversedBy - * - * @return ClassMetadataBuilder */ - public function addOwningOneToOne($name, $targetEntity, $inversedBy = null) - { + public function addOwningOneToOne( + string $name, + string $targetEntity, + string|null $inversedBy = null, + ): ClassMetadataBuilder { $builder = $this->createOneToOne($name, $targetEntity); if ($inversedBy) { @@ -411,13 +354,8 @@ public function addOwningOneToOne($name, $targetEntity, $inversedBy = null) /** * Creates a ManyToMany Association Builder. - * - * @param string $name - * @param string $targetEntity - * - * @return ManyToManyAssociationBuilder */ - public function createManyToMany($name, $targetEntity) + public function createManyToMany(string $name, string $targetEntity): ManyToManyAssociationBuilder { return new ManyToManyAssociationBuilder( $this, @@ -431,15 +369,12 @@ public function createManyToMany($name, $targetEntity) /** * Adds a simple owning many to many association. - * - * @param string $name - * @param string $targetEntity - * @param string|null $inversedBy - * - * @return ClassMetadataBuilder */ - public function addOwningManyToMany($name, $targetEntity, $inversedBy = null) - { + public function addOwningManyToMany( + string $name, + string $targetEntity, + string|null $inversedBy = null, + ): ClassMetadataBuilder { $builder = $this->createManyToMany($name, $targetEntity); if ($inversedBy) { @@ -451,14 +386,8 @@ public function addOwningManyToMany($name, $targetEntity, $inversedBy = null) /** * Adds a simple inverse many to many association. - * - * @param string $name - * @param string $targetEntity - * @param string $mappedBy - * - * @return ClassMetadataBuilder */ - public function addInverseManyToMany($name, $targetEntity, $mappedBy) + public function addInverseManyToMany(string $name, string $targetEntity, string $mappedBy): ClassMetadataBuilder { $builder = $this->createManyToMany($name, $targetEntity); $builder->mappedBy($mappedBy); @@ -468,13 +397,8 @@ public function addInverseManyToMany($name, $targetEntity, $mappedBy) /** * Creates a one to many association builder. - * - * @param string $name - * @param string $targetEntity - * - * @return OneToManyAssociationBuilder */ - public function createOneToMany($name, $targetEntity) + public function createOneToMany(string $name, string $targetEntity): OneToManyAssociationBuilder { return new OneToManyAssociationBuilder( $this, @@ -488,14 +412,8 @@ public function createOneToMany($name, $targetEntity) /** * Adds simple OneToMany association. - * - * @param string $name - * @param string $targetEntity - * @param string $mappedBy - * - * @return ClassMetadataBuilder */ - public function addOneToMany($name, $targetEntity, $mappedBy) + public function addOneToMany(string $name, string $targetEntity, string $mappedBy): ClassMetadataBuilder { $builder = $this->createOneToMany($name, $targetEntity); $builder->mappedBy($mappedBy); diff --git a/lib/Doctrine/ORM/Mapping/Builder/EmbeddedBuilder.php b/lib/Doctrine/ORM/Mapping/Builder/EmbeddedBuilder.php index a8508ab3bbe..b9d2127393b 100644 --- a/lib/Doctrine/ORM/Mapping/Builder/EmbeddedBuilder.php +++ b/lib/Doctrine/ORM/Mapping/Builder/EmbeddedBuilder.php @@ -11,27 +11,19 @@ */ class EmbeddedBuilder { - /** @var ClassMetadataBuilder */ - private $builder; - - /** @var mixed[] */ - private $mapping; - /** @param mixed[] $mapping */ - public function __construct(ClassMetadataBuilder $builder, array $mapping) - { - $this->builder = $builder; - $this->mapping = $mapping; + public function __construct( + private readonly ClassMetadataBuilder $builder, + private array $mapping, + ) { } /** * Sets the column prefix for all of the embedded columns. * - * @param string $columnPrefix - * * @return $this */ - public function setColumnPrefix($columnPrefix) + public function setColumnPrefix(string $columnPrefix): static { $this->mapping['columnPrefix'] = $columnPrefix; @@ -42,10 +34,8 @@ public function setColumnPrefix($columnPrefix) * Finalizes this embeddable and attach it to the ClassMetadata. * * Without this call an EmbeddedBuilder has no effect on the ClassMetadata. - * - * @return ClassMetadataBuilder */ - public function build() + public function build(): ClassMetadataBuilder { $cm = $this->builder->getClassMetadata(); diff --git a/lib/Doctrine/ORM/Mapping/Builder/EntityListenerBuilder.php b/lib/Doctrine/ORM/Mapping/Builder/EntityListenerBuilder.php index 1ba8c7a787a..a0b14b954c5 100644 --- a/lib/Doctrine/ORM/Mapping/Builder/EntityListenerBuilder.php +++ b/lib/Doctrine/ORM/Mapping/Builder/EntityListenerBuilder.php @@ -16,8 +16,8 @@ */ class EntityListenerBuilder { - /** @var array Hash-map to handle event names. */ - private static $events = [ + /** Hash-map to handle event names. */ + private const EVENTS = [ Events::preRemove => true, Events::postRemove => true, Events::prePersist => true, @@ -34,11 +34,9 @@ class EntityListenerBuilder * @param ClassMetadata $metadata The entity metadata. * @param string $className The listener class name. * - * @return void - * * @throws MappingException When the listener class not found. */ - public static function bindEntityListener(ClassMetadata $metadata, $className) + public static function bindEntityListener(ClassMetadata $metadata, string $className): void { $class = $metadata->fullyQualifiedClassName($className); @@ -47,7 +45,7 @@ public static function bindEntityListener(ClassMetadata $metadata, $className) } foreach (get_class_methods($class) as $method) { - if (! isset(self::$events[$method])) { + if (! isset(self::EVENTS[$method])) { continue; } diff --git a/lib/Doctrine/ORM/Mapping/Builder/FieldBuilder.php b/lib/Doctrine/ORM/Mapping/Builder/FieldBuilder.php index bdd87788cb9..8326ff5017c 100644 --- a/lib/Doctrine/ORM/Mapping/Builder/FieldBuilder.php +++ b/lib/Doctrine/ORM/Mapping/Builder/FieldBuilder.php @@ -13,39 +13,27 @@ */ class FieldBuilder { - /** @var ClassMetadataBuilder */ - private $builder; + private bool $version = false; + private string|null $generatedValue = null; - /** @var mixed[] */ - private $mapping; + /** @var mixed[]|null */ + private array|null $sequenceDef = null; - /** @var bool */ - private $version; - - /** @var string */ - private $generatedValue; - - /** @var mixed[] */ - private $sequenceDef; - - /** @var string|null */ - private $customIdGenerator; + private string|null $customIdGenerator = null; /** @param mixed[] $mapping */ - public function __construct(ClassMetadataBuilder $builder, array $mapping) - { - $this->builder = $builder; - $this->mapping = $mapping; + public function __construct( + private readonly ClassMetadataBuilder $builder, + private array $mapping, + ) { } /** * Sets length. * - * @param int $length - * * @return $this */ - public function length($length) + public function length(int $length): static { $this->mapping['length'] = $length; @@ -55,13 +43,11 @@ public function length($length) /** * Sets nullable. * - * @param bool $flag - * * @return $this */ - public function nullable($flag = true) + public function nullable(bool $flag = true): static { - $this->mapping['nullable'] = (bool) $flag; + $this->mapping['nullable'] = $flag; return $this; } @@ -69,13 +55,11 @@ public function nullable($flag = true) /** * Sets Unique. * - * @param bool $flag - * * @return $this */ - public function unique($flag = true) + public function unique(bool $flag = true): static { - $this->mapping['unique'] = (bool) $flag; + $this->mapping['unique'] = $flag; return $this; } @@ -83,11 +67,9 @@ public function unique($flag = true) /** * Sets column name. * - * @param string $name - * * @return $this */ - public function columnName($name) + public function columnName(string $name): static { $this->mapping['columnName'] = $name; @@ -97,11 +79,9 @@ public function columnName($name) /** * Sets Precision. * - * @param int $p - * * @return $this */ - public function precision($p) + public function precision(int $p): static { $this->mapping['precision'] = $p; @@ -139,11 +119,9 @@ public function updatable(bool $flag = true): self /** * Sets scale. * - * @param int $s - * * @return $this */ - public function scale($s) + public function scale(int $s): static { $this->mapping['scale'] = $s; @@ -155,7 +133,7 @@ public function scale($s) * * @return $this */ - public function makePrimaryKey() + public function makePrimaryKey(): static { $this->mapping['id'] = true; @@ -165,24 +143,17 @@ public function makePrimaryKey() /** * Sets an option. * - * @param string $name - * @param mixed $value - * * @return $this */ - public function option($name, $value) + public function option(string $name, mixed $value): static { $this->mapping['options'][$name] = $value; return $this; } - /** - * @param string $strategy - * - * @return $this - */ - public function generatedValue($strategy = 'AUTO') + /** @return $this */ + public function generatedValue(string $strategy = 'AUTO'): static { $this->generatedValue = $strategy; @@ -194,7 +165,7 @@ public function generatedValue($strategy = 'AUTO') * * @return $this */ - public function isVersionField() + public function isVersionField(): static { $this->version = true; @@ -204,13 +175,9 @@ public function isVersionField() /** * Sets Sequence Generator. * - * @param string $sequenceName - * @param int $allocationSize - * @param int $initialValue - * * @return $this */ - public function setSequenceGenerator($sequenceName, $allocationSize = 1, $initialValue = 1) + public function setSequenceGenerator(string $sequenceName, int $allocationSize = 1, int $initialValue = 1): static { $this->sequenceDef = [ 'sequenceName' => $sequenceName, @@ -224,11 +191,9 @@ public function setSequenceGenerator($sequenceName, $allocationSize = 1, $initia /** * Sets column definition. * - * @param string $def - * * @return $this */ - public function columnDefinition($def) + public function columnDefinition(string $def): static { $this->mapping['columnDefinition'] = $def; @@ -239,13 +204,11 @@ public function columnDefinition($def) * Set the FQCN of the custom ID generator. * This class must extend \Doctrine\ORM\Id\AbstractIdGenerator. * - * @param string $customIdGenerator - * * @return $this */ - public function setCustomIdGenerator($customIdGenerator) + public function setCustomIdGenerator(string $customIdGenerator): static { - $this->customIdGenerator = (string) $customIdGenerator; + $this->customIdGenerator = $customIdGenerator; return $this; } @@ -254,10 +217,8 @@ public function setCustomIdGenerator($customIdGenerator) * Finalizes this field and attach it to the ClassMetadata. * * Without this call a FieldBuilder has no effect on the ClassMetadata. - * - * @return ClassMetadataBuilder */ - public function build() + public function build(): ClassMetadataBuilder { $cm = $this->builder->getClassMetadata(); if ($this->generatedValue) { diff --git a/lib/Doctrine/ORM/Mapping/Builder/ManyToManyAssociationBuilder.php b/lib/Doctrine/ORM/Mapping/Builder/ManyToManyAssociationBuilder.php index 5da24eb4b90..b83a8baef9b 100644 --- a/lib/Doctrine/ORM/Mapping/Builder/ManyToManyAssociationBuilder.php +++ b/lib/Doctrine/ORM/Mapping/Builder/ManyToManyAssociationBuilder.php @@ -11,18 +11,13 @@ */ class ManyToManyAssociationBuilder extends OneToManyAssociationBuilder { - /** @var string|null */ - private $joinTableName; + private string|null $joinTableName = null; /** @var mixed[] */ - private $inverseJoinColumns = []; + private array $inverseJoinColumns = []; - /** - * @param string $name - * - * @return $this - */ - public function setJoinTable($name) + /** @return $this */ + public function setJoinTable(string $name): static { $this->joinTableName = $name; @@ -32,17 +27,16 @@ public function setJoinTable($name) /** * Adds Inverse Join Columns. * - * @param string $columnName - * @param string $referencedColumnName - * @param bool $nullable - * @param bool $unique - * @param string|null $onDelete - * @param string|null $columnDef - * * @return $this */ - public function addInverseJoinColumn($columnName, $referencedColumnName, $nullable = true, $unique = false, $onDelete = null, $columnDef = null) - { + public function addInverseJoinColumn( + string $columnName, + string $referencedColumnName, + bool $nullable = true, + bool $unique = false, + string|null $onDelete = null, + string|null $columnDef = null, + ): static { $this->inverseJoinColumns[] = [ 'name' => $columnName, 'referencedColumnName' => $referencedColumnName, @@ -55,8 +49,7 @@ public function addInverseJoinColumn($columnName, $referencedColumnName, $nullab return $this; } - /** @return ClassMetadataBuilder */ - public function build() + public function build(): ClassMetadataBuilder { $mapping = $this->mapping; $mapping['joinTable'] = []; diff --git a/lib/Doctrine/ORM/Mapping/Builder/OneToManyAssociationBuilder.php b/lib/Doctrine/ORM/Mapping/Builder/OneToManyAssociationBuilder.php index daf323bc36d..077c558cdd9 100644 --- a/lib/Doctrine/ORM/Mapping/Builder/OneToManyAssociationBuilder.php +++ b/lib/Doctrine/ORM/Mapping/Builder/OneToManyAssociationBuilder.php @@ -16,27 +16,22 @@ class OneToManyAssociationBuilder extends AssociationBuilder * * @return $this */ - public function setOrderBy(array $fieldNames) + public function setOrderBy(array $fieldNames): static { $this->mapping['orderBy'] = $fieldNames; return $this; } - /** - * @param string $fieldName - * - * @return $this - */ - public function setIndexBy($fieldName) + /** @return $this */ + public function setIndexBy(string $fieldName): static { $this->mapping['indexBy'] = $fieldName; return $this; } - /** @return ClassMetadataBuilder */ - public function build() + public function build(): ClassMetadataBuilder { $mapping = $this->mapping; if ($this->joinColumns) { diff --git a/psalm-baseline.xml b/psalm-baseline.xml index fc2fa7fce48..699785cee0d 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -311,18 +311,6 @@ $class - - - $generatedValue - $sequenceDef - $version - - - (bool) $flag - (bool) $flag - (string) $customIdGenerator - - ClassMetadata diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php index e4dd30653e9..cd66b1a78b0 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php @@ -180,8 +180,8 @@ public function testSetInheritanceSingleTable(): void public function testSetDiscriminatorColumn(): void { - $this->assertIsFluent($this->builder->setDiscriminatorColumn('discr', 'string', '124')); - self::assertEquals(['fieldName' => 'discr', 'name' => 'discr', 'type' => 'string', 'length' => '124'], $this->cm->discriminatorColumn); + $this->assertIsFluent($this->builder->setDiscriminatorColumn('discr', 'string', 124)); + self::assertEquals(['fieldName' => 'discr', 'name' => 'discr', 'type' => 'string', 'length' => 124], $this->cm->discriminatorColumn); } public function testAddDiscriminatorMapClass(): void