Skip to content

Commit

Permalink
Add native types to annotation classes (doctrine#10151)
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Oct 18, 2022
1 parent eda69c2 commit 8efcaf9
Show file tree
Hide file tree
Showing 29 changed files with 142 additions and 796 deletions.
59 changes: 11 additions & 48 deletions lib/Doctrine/ORM/Mapping/AssociationOverride.php
Expand Up @@ -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<JoinColumn>|null
* @readonly
*/
public $joinColumns;
public readonly array|null $joinColumns;

/**
* The join column that is being mapped to the persistent attribute.
*
* @var array<JoinColumn>|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<JoinColumn> $joinColumns
* @param JoinColumn|array<JoinColumn> $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];
Expand All @@ -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;
}
}
5 changes: 2 additions & 3 deletions lib/Doctrine/ORM/Mapping/AssociationOverrides.php
Expand Up @@ -23,12 +23,11 @@ final class AssociationOverrides implements Annotation
* Mapping overrides of relationship properties.
*
* @var list<AssociationOverride>
* @readonly
*/
public $overrides = [];
public readonly array $overrides;

/** @param array<AssociationOverride>|AssociationOverride $overrides */
public function __construct($overrides)
public function __construct(array|AssociationOverride $overrides)
{
if (! is_array($overrides)) {
$overrides = [$overrides];
Expand Down
24 changes: 4 additions & 20 deletions lib/Doctrine/ORM/Mapping/AttributeOverride.php
Expand Up @@ -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,
) {
}
}
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Mapping/AttributeOverrides.php
Expand Up @@ -25,10 +25,10 @@ final class AttributeOverrides implements Annotation
* @var list<AttributeOverride>
* @readonly
*/
public $overrides = [];
public array $overrides = [];

/** @param array<AttributeOverride>|AttributeOverride $overrides */
public function __construct($overrides)
public function __construct(array|AttributeOverride $overrides)
{
if (! is_array($overrides)) {
$overrides = [$overrides];
Expand Down
20 changes: 4 additions & 16 deletions lib/Doctrine/ORM/Mapping/Cache.php
Expand Up @@ -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,
) {
}
}
16 changes: 3 additions & 13 deletions lib/Doctrine/ORM/Mapping/ChangeTrackingPolicy.php
Expand Up @@ -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,
) {
}
}
125 changes: 15 additions & 110 deletions lib/Doctrine/ORM/Mapping/Column.php
Expand Up @@ -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<BackedEnum>|null
* @readonly
*/
public $enumType = null;

/**
* @var array<string,mixed>
* @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<BackedEnum>|null $enumType
* @param array<string,mixed> $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;
}
}
12 changes: 3 additions & 9 deletions lib/Doctrine/ORM/Mapping/CustomIdGenerator.php
Expand Up @@ -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,
) {
}
}
36 changes: 4 additions & 32 deletions lib/Doctrine/ORM/Mapping/DiscriminatorColumn.php
Expand Up @@ -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;
}
}

0 comments on commit 8efcaf9

Please sign in to comment.