From 8efcaf97eba3b064ca2fc0e0767494614adda3ed Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Tue, 18 Oct 2022 09:39:12 +0200 Subject: [PATCH] Add native types to annotation classes (#10151) --- .../ORM/Mapping/AssociationOverride.php | 59 ++------- .../ORM/Mapping/AssociationOverrides.php | 5 +- .../ORM/Mapping/AttributeOverride.php | 24 +--- .../ORM/Mapping/AttributeOverrides.php | 4 +- lib/Doctrine/ORM/Mapping/Cache.php | 20 +-- .../ORM/Mapping/ChangeTrackingPolicy.php | 16 +-- lib/Doctrine/ORM/Mapping/Column.php | 125 +++--------------- .../ORM/Mapping/CustomIdGenerator.php | 12 +- .../ORM/Mapping/DiscriminatorColumn.php | 36 +---- lib/Doctrine/ORM/Mapping/DiscriminatorMap.php | 12 +- lib/Doctrine/ORM/Mapping/Embedded.php | 6 +- lib/Doctrine/ORM/Mapping/Entity.php | 21 +-- lib/Doctrine/ORM/Mapping/EntityListeners.php | 14 +- lib/Doctrine/ORM/Mapping/GeneratedValue.php | 16 +-- lib/Doctrine/ORM/Mapping/Index.php | 45 +------ lib/Doctrine/ORM/Mapping/InheritanceType.php | 16 +-- .../ORM/Mapping/JoinColumnProperties.php | 79 ++--------- lib/Doctrine/ORM/Mapping/JoinColumns.php | 8 +- lib/Doctrine/ORM/Mapping/JoinTable.php | 47 ++----- lib/Doctrine/ORM/Mapping/ManyToMany.php | 67 +--------- lib/Doctrine/ORM/Mapping/ManyToOne.php | 40 +----- lib/Doctrine/ORM/Mapping/MappedSuperclass.php | 13 +- lib/Doctrine/ORM/Mapping/OneToMany.php | 58 +------- lib/Doctrine/ORM/Mapping/OneToOne.php | 58 +------- lib/Doctrine/ORM/Mapping/OrderBy.php | 12 +- .../ORM/Mapping/SequenceGenerator.php | 27 +--- lib/Doctrine/ORM/Mapping/Table.php | 45 +------ lib/Doctrine/ORM/Mapping/UniqueConstraint.php | 42 +----- psalm-baseline.xml | 11 -- 29 files changed, 142 insertions(+), 796 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/AssociationOverride.php b/lib/Doctrine/ORM/Mapping/AssociationOverride.php index c1cabbe83c4..885eb964cd5 100644 --- a/lib/Doctrine/ORM/Mapping/AssociationOverride.php +++ b/lib/Doctrine/ORM/Mapping/AssociationOverride.php @@ -13,68 +13,35 @@ */ final class AssociationOverride implements Annotation { - /** - * The name of the relationship property whose mapping is being overridden. - * - * @var string - * @readonly - */ - public $name; - /** * The join column that is being mapped to the persistent attribute. * * @var array|null - * @readonly */ - public $joinColumns; + public readonly array|null $joinColumns; /** * The join column that is being mapped to the persistent attribute. * * @var array|null - * @readonly - */ - public $inverseJoinColumns; - - /** - * The join table that maps the relationship. - * - * @var JoinTable|null - * @readonly - */ - public $joinTable; - - /** - * The name of the association-field on the inverse-side. - * - * @var string|null - * @readonly - */ - public $inversedBy; - - /** - * The fetching strategy to use for the association. - * - * @var string|null - * @psalm-var 'LAZY'|'EAGER'|'EXTRA_LAZY'|null - * @readonly - * @Enum({"LAZY", "EAGER", "EXTRA_LAZY"}) */ - public $fetch; + public readonly array|null $inverseJoinColumns; /** + * @param string $name The name of the relationship property whose mapping is being overridden. * @param JoinColumn|array $joinColumns * @param JoinColumn|array $inverseJoinColumns + * @param JoinTable|null $joinTable The join table that maps the relationship. + * @param string|null $inversedBy The name of the association-field on the inverse-side. * @psalm-param 'LAZY'|'EAGER'|'EXTRA_LAZY'|null $fetch */ public function __construct( - string $name, - $joinColumns = null, - $inverseJoinColumns = null, - JoinTable|null $joinTable = null, - string|null $inversedBy = null, - string|null $fetch = null, + public readonly string $name, + array|JoinColumn|null $joinColumns = null, + array|JoinColumn|null $inverseJoinColumns = null, + public readonly JoinTable|null $joinTable = null, + public readonly string|null $inversedBy = null, + public readonly string|null $fetch = null, ) { if ($joinColumns instanceof JoinColumn) { $joinColumns = [$joinColumns]; @@ -84,11 +51,7 @@ public function __construct( $inverseJoinColumns = [$inverseJoinColumns]; } - $this->name = $name; $this->joinColumns = $joinColumns; $this->inverseJoinColumns = $inverseJoinColumns; - $this->joinTable = $joinTable; - $this->inversedBy = $inversedBy; - $this->fetch = $fetch; } } diff --git a/lib/Doctrine/ORM/Mapping/AssociationOverrides.php b/lib/Doctrine/ORM/Mapping/AssociationOverrides.php index 33f2a8265a2..364a431e416 100644 --- a/lib/Doctrine/ORM/Mapping/AssociationOverrides.php +++ b/lib/Doctrine/ORM/Mapping/AssociationOverrides.php @@ -23,12 +23,11 @@ final class AssociationOverrides implements Annotation * Mapping overrides of relationship properties. * * @var list - * @readonly */ - public $overrides = []; + public readonly array $overrides; /** @param array|AssociationOverride $overrides */ - public function __construct($overrides) + public function __construct(array|AssociationOverride $overrides) { if (! is_array($overrides)) { $overrides = [$overrides]; diff --git a/lib/Doctrine/ORM/Mapping/AttributeOverride.php b/lib/Doctrine/ORM/Mapping/AttributeOverride.php index e18e0cf958d..9db5e63db32 100644 --- a/lib/Doctrine/ORM/Mapping/AttributeOverride.php +++ b/lib/Doctrine/ORM/Mapping/AttributeOverride.php @@ -13,25 +13,9 @@ */ final class AttributeOverride implements Annotation { - /** - * The name of the property whose mapping is being overridden. - * - * @var string - * @readonly - */ - public $name; - - /** - * The column definition. - * - * @var Column - * @readonly - */ - public $column; - - public function __construct(string $name, Column $column) - { - $this->name = $name; - $this->column = $column; + public function __construct( + public string $name, + public Column $column, + ) { } } diff --git a/lib/Doctrine/ORM/Mapping/AttributeOverrides.php b/lib/Doctrine/ORM/Mapping/AttributeOverrides.php index 6f2f9bd962e..ede2c71918b 100644 --- a/lib/Doctrine/ORM/Mapping/AttributeOverrides.php +++ b/lib/Doctrine/ORM/Mapping/AttributeOverrides.php @@ -25,10 +25,10 @@ final class AttributeOverrides implements Annotation * @var list * @readonly */ - public $overrides = []; + public array $overrides = []; /** @param array|AttributeOverride $overrides */ - public function __construct($overrides) + public function __construct(array|AttributeOverride $overrides) { if (! is_array($overrides)) { $overrides = [$overrides]; diff --git a/lib/Doctrine/ORM/Mapping/Cache.php b/lib/Doctrine/ORM/Mapping/Cache.php index 3471e7bf65a..c7572fc481d 100644 --- a/lib/Doctrine/ORM/Mapping/Cache.php +++ b/lib/Doctrine/ORM/Mapping/Cache.php @@ -17,22 +17,10 @@ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY)] final class Cache implements Annotation { - /** - * The concurrency strategy. - * - * @Enum({"READ_ONLY", "NONSTRICT_READ_WRITE", "READ_WRITE"}) - * @var string - * @psalm-var 'READ_ONLY'|'NONSTRICT_READ_WRITE'|'READ_WRITE' - */ - public $usage = 'READ_ONLY'; - - /** @var string|null Cache region name. */ - public $region; - /** @psalm-param 'READ_ONLY'|'NONSTRICT_READ_WRITE'|'READ_WRITE' $usage */ - public function __construct(string $usage = 'READ_ONLY', string|null $region = null) - { - $this->usage = $usage; - $this->region = $region; + public function __construct( + public readonly string $usage = 'READ_ONLY', + public readonly string|null $region = null, + ) { } } diff --git a/lib/Doctrine/ORM/Mapping/ChangeTrackingPolicy.php b/lib/Doctrine/ORM/Mapping/ChangeTrackingPolicy.php index fb23eb0be8e..08032518269 100644 --- a/lib/Doctrine/ORM/Mapping/ChangeTrackingPolicy.php +++ b/lib/Doctrine/ORM/Mapping/ChangeTrackingPolicy.php @@ -15,19 +15,9 @@ #[Attribute(Attribute::TARGET_CLASS)] final class ChangeTrackingPolicy implements Annotation { - /** - * The change tracking policy. - * - * @var string - * @psalm-var 'DEFERRED_IMPLICIT'|'DEFERRED_EXPLICIT'|'NOTIFY' - * @readonly - * @Enum({"DEFERRED_IMPLICIT", "DEFERRED_EXPLICIT", "NOTIFY"}) - */ - public $value; - /** @psalm-param 'DEFERRED_IMPLICIT'|'DEFERRED_EXPLICIT'|'NOTIFY' $value */ - public function __construct(string $value) - { - $this->value = $value; + public function __construct( + public readonly string $value, + ) { } } diff --git a/lib/Doctrine/ORM/Mapping/Column.php b/lib/Doctrine/ORM/Mapping/Column.php index e9bde8d1389..f9c019a2327 100644 --- a/lib/Doctrine/ORM/Mapping/Column.php +++ b/lib/Doctrine/ORM/Mapping/Column.php @@ -17,121 +17,26 @@ final class Column implements Annotation { /** - * @var string|null - * @readonly - */ - public $name; - - /** - * @var mixed - * @readonly - */ - public $type; - - /** - * @var int|null - * @readonly - */ - public $length; - - /** - * The precision for a decimal (exact numeric) column (Applies only for decimal column). - * - * @var int|null - * @readonly - */ - public $precision = 0; - - /** - * The scale for a decimal (exact numeric) column (Applies only for decimal column). - * - * @var int|null - * @readonly - */ - public $scale = 0; - - /** - * @var bool - * @readonly - */ - public $unique = false; - - /** - * @var bool - * @readonly - */ - public $nullable = false; - - /** - * @var bool - * @readonly - */ - public $insertable = true; - - /** - * @var bool - * @readonly - */ - public $updatable = true; - - /** - * @var class-string|null - * @readonly - */ - public $enumType = null; - - /** - * @var array - * @readonly - */ - public $options = []; - - /** - * @var string|null - * @readonly - */ - public $columnDefinition; - - /** - * @var string|null - * @readonly - * @psalm-var 'NEVER'|'INSERT'|'ALWAYS'|null - * @Enum({"NEVER", "INSERT", "ALWAYS"}) - */ - public $generated; - - /** + * @param int|null $precision The precision for a decimal (exact numeric) column (Applies only for decimal column). + * @param int|null $scale The scale for a decimal (exact numeric) column (Applies only for decimal column). * @param class-string|null $enumType * @param array $options * @psalm-param 'NEVER'|'INSERT'|'ALWAYS'|null $generated */ public function __construct( - string|null $name = null, - string|null $type = null, - int|null $length = null, - int|null $precision = null, - int|null $scale = null, - bool $unique = false, - bool $nullable = false, - bool $insertable = true, - bool $updatable = true, - string|null $enumType = null, - array $options = [], - string|null $columnDefinition = null, - string|null $generated = null, + public readonly string|null $name = null, + public readonly string|null $type = null, + public readonly int|null $length = null, + public readonly int|null $precision = null, + public readonly int|null $scale = null, + public readonly bool $unique = false, + public readonly bool $nullable = false, + public readonly bool $insertable = true, + public readonly bool $updatable = true, + public readonly string|null $enumType = null, + public readonly array $options = [], + public readonly string|null $columnDefinition = null, + public readonly string|null $generated = null, ) { - $this->name = $name; - $this->type = $type; - $this->length = $length; - $this->precision = $precision; - $this->scale = $scale; - $this->unique = $unique; - $this->nullable = $nullable; - $this->insertable = $insertable; - $this->updatable = $updatable; - $this->enumType = $enumType; - $this->options = $options; - $this->columnDefinition = $columnDefinition; - $this->generated = $generated; } } diff --git a/lib/Doctrine/ORM/Mapping/CustomIdGenerator.php b/lib/Doctrine/ORM/Mapping/CustomIdGenerator.php index 8530aeaa7b1..ccf1592b528 100644 --- a/lib/Doctrine/ORM/Mapping/CustomIdGenerator.php +++ b/lib/Doctrine/ORM/Mapping/CustomIdGenerator.php @@ -15,14 +15,8 @@ #[Attribute(Attribute::TARGET_PROPERTY)] final class CustomIdGenerator implements Annotation { - /** - * @var string|null - * @readonly - */ - public $class; - - public function __construct(string|null $class = null) - { - $this->class = $class; + public function __construct( + public readonly string|null $class = null, + ) { } } diff --git a/lib/Doctrine/ORM/Mapping/DiscriminatorColumn.php b/lib/Doctrine/ORM/Mapping/DiscriminatorColumn.php index e01c0e8ce32..a8f1f19d90e 100644 --- a/lib/Doctrine/ORM/Mapping/DiscriminatorColumn.php +++ b/lib/Doctrine/ORM/Mapping/DiscriminatorColumn.php @@ -15,39 +15,11 @@ #[Attribute(Attribute::TARGET_CLASS)] final class DiscriminatorColumn implements Annotation { - /** - * @var string|null - * @readonly - */ - public $name; - - /** - * @var string|null - * @readonly - */ - public $type; - - /** - * @var int|null - * @readonly - */ - public $length; - - /** - * @var string|null - * @readonly - */ - public $columnDefinition; - public function __construct( - string|null $name = null, - string|null $type = null, - int|null $length = null, - string|null $columnDefinition = null, + public readonly string|null $name = null, + public readonly string|null $type = null, + public readonly int|null $length = null, + public readonly string|null $columnDefinition = null, ) { - $this->name = $name; - $this->type = $type; - $this->length = $length; - $this->columnDefinition = $columnDefinition; } } diff --git a/lib/Doctrine/ORM/Mapping/DiscriminatorMap.php b/lib/Doctrine/ORM/Mapping/DiscriminatorMap.php index 49d4e5e3b06..2c5ccb0aa37 100644 --- a/lib/Doctrine/ORM/Mapping/DiscriminatorMap.php +++ b/lib/Doctrine/ORM/Mapping/DiscriminatorMap.php @@ -15,15 +15,9 @@ #[Attribute(Attribute::TARGET_CLASS)] final class DiscriminatorMap implements Annotation { - /** - * @var array - * @readonly - */ - public $value; - /** @param array $value */ - public function __construct(array $value) - { - $this->value = $value; + public function __construct( + public readonly array $value, + ) { } } diff --git a/lib/Doctrine/ORM/Mapping/Embedded.php b/lib/Doctrine/ORM/Mapping/Embedded.php index c1be5fb81b3..3a0961dc580 100644 --- a/lib/Doctrine/ORM/Mapping/Embedded.php +++ b/lib/Doctrine/ORM/Mapping/Embedded.php @@ -16,10 +16,8 @@ final class Embedded implements Annotation { public function __construct( - /** @readonly */ - public string|null $class = null, - /** @readonly */ - public string|bool|null $columnPrefix = null, + public readonly string|null $class = null, + public readonly string|bool|null $columnPrefix = null, ) { } } diff --git a/lib/Doctrine/ORM/Mapping/Entity.php b/lib/Doctrine/ORM/Mapping/Entity.php index c90878a60b3..ffdaf38748d 100644 --- a/lib/Doctrine/ORM/Mapping/Entity.php +++ b/lib/Doctrine/ORM/Mapping/Entity.php @@ -17,23 +17,10 @@ #[Attribute(Attribute::TARGET_CLASS)] final class Entity implements Annotation { - /** - * @var string|null - * @psalm-var class-string>|null - * @readonly - */ - public $repositoryClass; - - /** - * @var bool - * @readonly - */ - public $readOnly = false; - /** @psalm-param class-string>|null $repositoryClass */ - public function __construct(string|null $repositoryClass = null, bool $readOnly = false) - { - $this->repositoryClass = $repositoryClass; - $this->readOnly = $readOnly; + public function __construct( + public readonly string|null $repositoryClass = null, + public readonly bool $readOnly = false, + ) { } } diff --git a/lib/Doctrine/ORM/Mapping/EntityListeners.php b/lib/Doctrine/ORM/Mapping/EntityListeners.php index f1a80aeeea1..aacf11c5044 100644 --- a/lib/Doctrine/ORM/Mapping/EntityListeners.php +++ b/lib/Doctrine/ORM/Mapping/EntityListeners.php @@ -18,17 +18,9 @@ #[Attribute(Attribute::TARGET_CLASS)] final class EntityListeners implements Annotation { - /** - * Specifies the names of the entity listeners. - * - * @var array - * @readonly - */ - public $value = []; - /** @param array $value */ - public function __construct(array $value = []) - { - $this->value = $value; + public function __construct( + public readonly array $value = [], + ) { } } diff --git a/lib/Doctrine/ORM/Mapping/GeneratedValue.php b/lib/Doctrine/ORM/Mapping/GeneratedValue.php index 5bc9dbc93a0..9acb4228ffe 100644 --- a/lib/Doctrine/ORM/Mapping/GeneratedValue.php +++ b/lib/Doctrine/ORM/Mapping/GeneratedValue.php @@ -15,19 +15,9 @@ #[Attribute(Attribute::TARGET_PROPERTY)] final class GeneratedValue implements Annotation { - /** - * The type of ID generator. - * - * @var string - * @psalm-var 'AUTO'|'SEQUENCE'|'IDENTITY'|'NONE'|'CUSTOM' - * @readonly - * @Enum({"AUTO", "SEQUENCE", "TABLE", "IDENTITY", "NONE", "CUSTOM"}) - */ - public $strategy = 'AUTO'; - /** @psalm-param 'AUTO'|'SEQUENCE'|'IDENTITY'|'NONE'|'CUSTOM' $strategy */ - public function __construct(string $strategy = 'AUTO') - { - $this->strategy = $strategy; + public function __construct( + public readonly string $strategy = 'AUTO', + ) { } } diff --git a/lib/Doctrine/ORM/Mapping/Index.php b/lib/Doctrine/ORM/Mapping/Index.php index 8dfc564c8a3..b2f7fdae778 100644 --- a/lib/Doctrine/ORM/Mapping/Index.php +++ b/lib/Doctrine/ORM/Mapping/Index.php @@ -15,36 +15,6 @@ #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] final class Index implements Annotation { - /** - * @var string|null - * @readonly - */ - public $name; - - /** - * @var array|null - * @readonly - */ - public $columns; - - /** - * @var array|null - * @readonly - */ - public $fields; - - /** - * @var array|null - * @readonly - */ - public $flags; - - /** - * @var array|null - * @readonly - */ - public $options; - /** * @param array|null $columns * @param array|null $fields @@ -52,16 +22,11 @@ final class Index implements Annotation * @param array|null $options */ public function __construct( - array|null $columns = null, - array|null $fields = null, - string|null $name = null, - array|null $flags = null, - array|null $options = null, + public readonly array|null $columns = null, + public readonly array|null $fields = null, + public readonly string|null $name = null, + public readonly array|null $flags = null, + public readonly array|null $options = null, ) { - $this->columns = $columns; - $this->fields = $fields; - $this->name = $name; - $this->flags = $flags; - $this->options = $options; } } diff --git a/lib/Doctrine/ORM/Mapping/InheritanceType.php b/lib/Doctrine/ORM/Mapping/InheritanceType.php index 33db6a95aae..bfad4349f33 100644 --- a/lib/Doctrine/ORM/Mapping/InheritanceType.php +++ b/lib/Doctrine/ORM/Mapping/InheritanceType.php @@ -15,19 +15,9 @@ #[Attribute(Attribute::TARGET_CLASS)] final class InheritanceType implements Annotation { - /** - * The inheritance type used by the class and its subclasses. - * - * @var string - * @psalm-var 'NONE'|'JOINED'|'SINGLE_TABLE'|'TABLE_PER_CLASS' - * @readonly - * @Enum({"NONE", "JOINED", "SINGLE_TABLE", "TABLE_PER_CLASS"}) - */ - public $value; - /** @psalm-param 'NONE'|'JOINED'|'SINGLE_TABLE'|'TABLE_PER_CLASS' $value */ - public function __construct(string $value) - { - $this->value = $value; + public function __construct( + public readonly string $value, + ) { } } diff --git a/lib/Doctrine/ORM/Mapping/JoinColumnProperties.php b/lib/Doctrine/ORM/Mapping/JoinColumnProperties.php index 0963e1e1534..7d132952b31 100644 --- a/lib/Doctrine/ORM/Mapping/JoinColumnProperties.php +++ b/lib/Doctrine/ORM/Mapping/JoinColumnProperties.php @@ -6,77 +6,16 @@ trait JoinColumnProperties { - /** - * @var string|null - * @readonly - */ - public $name; - - /** - * @var string - * @readonly - */ - public $referencedColumnName = 'id'; - - /** - * @var bool - * @readonly - */ - public $unique = false; - - /** - * @var bool - * @readonly - */ - public $nullable = true; - - /** - * @var mixed - * @readonly - */ - public $onDelete; - - /** - * @var string|null - * @readonly - */ - public $columnDefinition; - - /** - * Field name used in non-object hydration (array/scalar). - * - * @var string|null - * @readonly - */ - public $fieldName; - - /** - * @var array - * @readonly - */ - public $options = []; - - /** - * @param mixed $onDelete - * @param array $options - */ + /** @param array $options */ public function __construct( - string|null $name = null, - string $referencedColumnName = 'id', - bool $unique = false, - bool $nullable = true, - $onDelete = null, - string|null $columnDefinition = null, - string|null $fieldName = null, - array $options = [], + public readonly string|null $name = null, + public readonly string $referencedColumnName = 'id', + public readonly bool $unique = false, + public readonly bool $nullable = true, + public readonly mixed $onDelete = null, + public readonly string|null $columnDefinition = null, + public readonly string|null $fieldName = null, + public readonly array $options = [], ) { - $this->name = $name; - $this->referencedColumnName = $referencedColumnName; - $this->unique = $unique; - $this->nullable = $nullable; - $this->onDelete = $onDelete; - $this->columnDefinition = $columnDefinition; - $this->fieldName = $fieldName; - $this->options = $options; } } diff --git a/lib/Doctrine/ORM/Mapping/JoinColumns.php b/lib/Doctrine/ORM/Mapping/JoinColumns.php index d00bdcc5834..30388931780 100644 --- a/lib/Doctrine/ORM/Mapping/JoinColumns.php +++ b/lib/Doctrine/ORM/Mapping/JoinColumns.php @@ -6,10 +6,14 @@ /** * @Annotation + * @NamedArgumentConstructor * @Target("PROPERTY") */ final class JoinColumns implements Annotation { - /** @var array<\Doctrine\ORM\Mapping\JoinColumn> */ - public $value; + /** @param array $value */ + public function __construct( + public readonly array $value, + ) { + } } diff --git a/lib/Doctrine/ORM/Mapping/JoinTable.php b/lib/Doctrine/ORM/Mapping/JoinTable.php index 5e44e147652..ca10bac706a 100644 --- a/lib/Doctrine/ORM/Mapping/JoinTable.php +++ b/lib/Doctrine/ORM/Mapping/JoinTable.php @@ -15,50 +15,27 @@ #[Attribute(Attribute::TARGET_PROPERTY)] final class JoinTable implements Annotation { - /** - * @var string|null - * @readonly - */ - public $name; + /** @var array */ + public readonly array $joinColumns; - /** - * @var string|null - * @readonly - */ - public $schema; + /** @var array */ + public readonly array $inverseJoinColumns; /** - * @var array - * @readonly + * @param array|JoinColumn $joinColumns + * @param array|JoinColumn $inverseJoinColumns + * @param array $options */ - public $joinColumns = []; - - /** - * @var array - * @readonly - */ - public $inverseJoinColumns = []; - - /** - * @var array - * @readonly - */ - public $options = []; - - /** @param array $options */ public function __construct( - string|null $name = null, - string|null $schema = null, - $joinColumns = [], - $inverseJoinColumns = [], - array $options = [], + public readonly string|null $name = null, + public readonly string|null $schema = null, + array|JoinColumn $joinColumns = [], + array|JoinColumn $inverseJoinColumns = [], + public readonly array $options = [], ) { - $this->name = $name; - $this->schema = $schema; $this->joinColumns = $joinColumns instanceof JoinColumn ? [$joinColumns] : $joinColumns; $this->inverseJoinColumns = $inverseJoinColumns instanceof JoinColumn ? [$inverseJoinColumns] : $inverseJoinColumns; - $this->options = $options; } } diff --git a/lib/Doctrine/ORM/Mapping/ManyToMany.php b/lib/Doctrine/ORM/Mapping/ManyToMany.php index 0f5f2de5a86..abc11265f05 100644 --- a/lib/Doctrine/ORM/Mapping/ManyToMany.php +++ b/lib/Doctrine/ORM/Mapping/ManyToMany.php @@ -15,72 +15,19 @@ #[Attribute(Attribute::TARGET_PROPERTY)] final class ManyToMany implements Annotation { - /** - * @var class-string|null - * @readonly - */ - public $targetEntity; - - /** - * @var string|null - * @readonly - */ - public $mappedBy; - - /** - * @var string|null - * @readonly - */ - public $inversedBy; - - /** - * @var string[]|null - * @readonly - */ - public $cascade; - - /** - * The fetching strategy to use for the association. - * - * @var string - * @psalm-var 'LAZY'|'EAGER'|'EXTRA_LAZY' - * @readonly - * @Enum({"LAZY", "EAGER", "EXTRA_LAZY"}) - */ - public $fetch = 'LAZY'; - - /** - * @var bool - * @readonly - */ - public $orphanRemoval = false; - - /** - * @var string|null - * @readonly - */ - public $indexBy; - /** * @param class-string $targetEntity * @param string[]|null $cascade * @psalm-param 'LAZY'|'EAGER'|'EXTRA_LAZY' $fetch */ public function __construct( - string $targetEntity, - string|null $mappedBy = null, - string|null $inversedBy = null, - array|null $cascade = null, - string $fetch = 'LAZY', - bool $orphanRemoval = false, - string|null $indexBy = null, + public readonly string $targetEntity, + public readonly string|null $mappedBy = null, + public readonly string|null $inversedBy = null, + public readonly array|null $cascade = null, + public readonly string $fetch = 'LAZY', + public readonly bool $orphanRemoval = false, + public readonly string|null $indexBy = null, ) { - $this->targetEntity = $targetEntity; - $this->mappedBy = $mappedBy; - $this->inversedBy = $inversedBy; - $this->cascade = $cascade; - $this->fetch = $fetch; - $this->orphanRemoval = $orphanRemoval; - $this->indexBy = $indexBy; } } diff --git a/lib/Doctrine/ORM/Mapping/ManyToOne.php b/lib/Doctrine/ORM/Mapping/ManyToOne.php index 412db2948b1..b573a93e2e6 100644 --- a/lib/Doctrine/ORM/Mapping/ManyToOne.php +++ b/lib/Doctrine/ORM/Mapping/ManyToOne.php @@ -15,48 +15,16 @@ #[Attribute(Attribute::TARGET_PROPERTY)] final class ManyToOne implements Annotation { - /** - * @var class-string|null - * @readonly - */ - public $targetEntity; - - /** - * @var string[]|null - * @readonly - */ - public $cascade; - - /** - * The fetching strategy to use for the association. - * - * @var string - * @psalm-var 'LAZY'|'EAGER'|'EXTRA_LAZY' - * @readonly - * @Enum({"LAZY", "EAGER", "EXTRA_LAZY"}) - */ - public $fetch = 'LAZY'; - - /** - * @var string|null - * @readonly - */ - public $inversedBy; - /** * @param class-string|null $targetEntity * @param string[]|null $cascade * @psalm-param 'LAZY'|'EAGER'|'EXTRA_LAZY' $fetch */ public function __construct( - string|null $targetEntity = null, - array|null $cascade = null, - string $fetch = 'LAZY', - string|null $inversedBy = null, + public readonly string|null $targetEntity = null, + public readonly array|null $cascade = null, + public readonly string $fetch = 'LAZY', + public readonly string|null $inversedBy = null, ) { - $this->targetEntity = $targetEntity; - $this->cascade = $cascade; - $this->fetch = $fetch; - $this->inversedBy = $inversedBy; } } diff --git a/lib/Doctrine/ORM/Mapping/MappedSuperclass.php b/lib/Doctrine/ORM/Mapping/MappedSuperclass.php index 09a6d889b3b..519f82d4034 100644 --- a/lib/Doctrine/ORM/Mapping/MappedSuperclass.php +++ b/lib/Doctrine/ORM/Mapping/MappedSuperclass.php @@ -16,16 +16,9 @@ #[Attribute(Attribute::TARGET_CLASS)] final class MappedSuperclass implements Annotation { - /** - * @var string|null - * @psalm-var class-string|null - * @readonly - */ - public $repositoryClass; - /** @psalm-param class-string|null $repositoryClass */ - public function __construct(string|null $repositoryClass = null) - { - $this->repositoryClass = $repositoryClass; + public function __construct( + public readonly string|null $repositoryClass = null, + ) { } } diff --git a/lib/Doctrine/ORM/Mapping/OneToMany.php b/lib/Doctrine/ORM/Mapping/OneToMany.php index 027fd9c8ad9..8f088533756 100644 --- a/lib/Doctrine/ORM/Mapping/OneToMany.php +++ b/lib/Doctrine/ORM/Mapping/OneToMany.php @@ -15,64 +15,18 @@ #[Attribute(Attribute::TARGET_PROPERTY)] final class OneToMany implements Annotation { - /** - * @var string|null - * @readonly - */ - public $mappedBy; - - /** - * @var class-string|null - * @readonly - */ - public $targetEntity; - - /** - * @var array|null - * @readonly - */ - public $cascade; - - /** - * The fetching strategy to use for the association. - * - * @var string - * @psalm-var 'LAZY'|'EAGER'|'EXTRA_LAZY' - * @readonly - * @Enum({"LAZY", "EAGER", "EXTRA_LAZY"}) - */ - public $fetch = 'LAZY'; - - /** - * @var bool - * @readonly - */ - public $orphanRemoval = false; - - /** - * @var string|null - * @readonly - */ - public $indexBy; - /** * @param class-string|null $targetEntity * @param string[]|null $cascade * @psalm-param 'LAZY'|'EAGER'|'EXTRA_LAZY' $fetch */ public function __construct( - string|null $mappedBy = null, - string|null $targetEntity = null, - array|null $cascade = null, - string $fetch = 'LAZY', - bool $orphanRemoval = false, - string|null $indexBy = null, + public readonly string|null $mappedBy = null, + public readonly string|null $targetEntity = null, + public readonly array|null $cascade = null, + public readonly string $fetch = 'LAZY', + public readonly bool $orphanRemoval = false, + public readonly string|null $indexBy = null, ) { - $this->mappedBy = $mappedBy; - $this->targetEntity = $targetEntity; - $this->cascade = $cascade; - $this->fetch = $fetch; - $this->orphanRemoval = $orphanRemoval; - $this->indexBy = $indexBy; } } diff --git a/lib/Doctrine/ORM/Mapping/OneToOne.php b/lib/Doctrine/ORM/Mapping/OneToOne.php index 0f3961dadc6..ede066982fc 100644 --- a/lib/Doctrine/ORM/Mapping/OneToOne.php +++ b/lib/Doctrine/ORM/Mapping/OneToOne.php @@ -15,64 +15,18 @@ #[Attribute(Attribute::TARGET_PROPERTY)] final class OneToOne implements Annotation { - /** - * @var class-string|null - * @readonly - */ - public $targetEntity; - - /** - * @var string|null - * @readonly - */ - public $mappedBy; - - /** - * @var string|null - * @readonly - */ - public $inversedBy; - - /** - * @var array|null - * @readonly - */ - public $cascade; - - /** - * The fetching strategy to use for the association. - * - * @var string - * @psalm-var 'LAZY'|'EAGER'|'EXTRA_LAZY' - * @readonly - * @Enum({"LAZY", "EAGER", "EXTRA_LAZY"}) - */ - public $fetch = 'LAZY'; - - /** - * @var bool - * @readonly - */ - public $orphanRemoval = false; - /** * @param class-string|null $targetEntity * @param array|null $cascade * @psalm-param 'LAZY'|'EAGER'|'EXTRA_LAZY' $fetch */ public function __construct( - string|null $mappedBy = null, - string|null $inversedBy = null, - string|null $targetEntity = null, - array|null $cascade = null, - string $fetch = 'LAZY', - bool $orphanRemoval = false, + public readonly string|null $mappedBy = null, + public readonly string|null $inversedBy = null, + public readonly string|null $targetEntity = null, + public readonly array|null $cascade = null, + public readonly string $fetch = 'LAZY', + public readonly bool $orphanRemoval = false, ) { - $this->mappedBy = $mappedBy; - $this->inversedBy = $inversedBy; - $this->targetEntity = $targetEntity; - $this->cascade = $cascade; - $this->fetch = $fetch; - $this->orphanRemoval = $orphanRemoval; } } diff --git a/lib/Doctrine/ORM/Mapping/OrderBy.php b/lib/Doctrine/ORM/Mapping/OrderBy.php index fa8c33bbaaa..3287d644af9 100644 --- a/lib/Doctrine/ORM/Mapping/OrderBy.php +++ b/lib/Doctrine/ORM/Mapping/OrderBy.php @@ -15,15 +15,9 @@ #[Attribute(Attribute::TARGET_PROPERTY)] final class OrderBy implements Annotation { - /** - * @var array - * @readonly - */ - public $value; - /** @param array $value */ - public function __construct(array $value) - { - $this->value = $value; + public function __construct( + public readonly array $value, + ) { } } diff --git a/lib/Doctrine/ORM/Mapping/SequenceGenerator.php b/lib/Doctrine/ORM/Mapping/SequenceGenerator.php index 67fb916e5a5..5564a8463d9 100644 --- a/lib/Doctrine/ORM/Mapping/SequenceGenerator.php +++ b/lib/Doctrine/ORM/Mapping/SequenceGenerator.php @@ -15,31 +15,10 @@ #[Attribute(Attribute::TARGET_PROPERTY)] final class SequenceGenerator implements Annotation { - /** - * @var string|null - * @readonly - */ - public $sequenceName; - - /** - * @var int - * @readonly - */ - public $allocationSize = 1; - - /** - * @var int - * @readonly - */ - public $initialValue = 1; - public function __construct( - string|null $sequenceName = null, - int $allocationSize = 1, - int $initialValue = 1, + public readonly string|null $sequenceName = null, + public readonly int $allocationSize = 1, + public readonly int $initialValue = 1, ) { - $this->sequenceName = $sequenceName; - $this->allocationSize = $allocationSize; - $this->initialValue = $initialValue; } } diff --git a/lib/Doctrine/ORM/Mapping/Table.php b/lib/Doctrine/ORM/Mapping/Table.php index 9860ed1a36f..2ba38d78b1e 100644 --- a/lib/Doctrine/ORM/Mapping/Table.php +++ b/lib/Doctrine/ORM/Mapping/Table.php @@ -15,52 +15,17 @@ #[Attribute(Attribute::TARGET_CLASS)] final class Table implements Annotation { - /** - * @var string|null - * @readonly - */ - public $name; - - /** - * @var string|null - * @readonly - */ - public $schema; - - /** - * @var array|null - * @readonly - */ - public $indexes; - - /** - * @var array|null - * @readonly - */ - public $uniqueConstraints; - - /** - * @var array - * @readonly - */ - public $options = []; - /** * @param array $indexes * @param array $uniqueConstraints * @param array $options */ public function __construct( - string|null $name = null, - string|null $schema = null, - array|null $indexes = null, - array|null $uniqueConstraints = null, - array $options = [], + public readonly string|null $name = null, + public readonly string|null $schema = null, + public readonly array|null $indexes = null, + public readonly array|null $uniqueConstraints = null, + public readonly array $options = [], ) { - $this->name = $name; - $this->schema = $schema; - $this->indexes = $indexes; - $this->uniqueConstraints = $uniqueConstraints; - $this->options = $options; } } diff --git a/lib/Doctrine/ORM/Mapping/UniqueConstraint.php b/lib/Doctrine/ORM/Mapping/UniqueConstraint.php index 341673d8b43..fdb8cb3db94 100644 --- a/lib/Doctrine/ORM/Mapping/UniqueConstraint.php +++ b/lib/Doctrine/ORM/Mapping/UniqueConstraint.php @@ -16,43 +16,15 @@ final class UniqueConstraint implements Annotation { /** - * @var string|null - * @readonly - */ - public $name; - - /** - * @var array|null - * @readonly - */ - public $columns; - - /** - * @var array|null - * @readonly - */ - public $fields; - - /** - * @var array|null - * @readonly - */ - public $options; - - /** - * @param array $columns - * @param array $fields - * @param array $options + * @param array|null $columns + * @param array|null $fields + * @param array|null $options */ public function __construct( - string|null $name = null, - array|null $columns = null, - array|null $fields = null, - array|null $options = null, + public readonly string|null $name = null, + public readonly array|null $columns = null, + public readonly array|null $fields = null, + public readonly array|null $options = null, ) { - $this->name = $name; - $this->columns = $columns; - $this->fields = $fields; - $this->options = $options; } } diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 00e90de8308..9ef47050196 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -626,17 +626,6 @@ isset($xmlRoot->{'unique-constraints'}) - - - $value - - - - - $inverseJoinColumns - $joinColumns - - $className