Skip to content

Commit

Permalink
revise annotations and attributes constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
IonBazan committed Jul 29, 2021
1 parent 7cf95f6 commit 9edc694
Show file tree
Hide file tree
Showing 24 changed files with 101 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ abstract class AbstractField implements Annotation
public $name;

/** @var string */
public $type = 'string';
public $type;

/** @var bool */
public $nullable = false;
public $nullable;

/** @var mixed[] */
public $options = [];
public $options;

/** @var string|null */
public $strategy;

/** @var bool */
public $notSaved = false;
public $notSaved;

public function __construct(
?string $name = null,
Expand Down
10 changes: 5 additions & 5 deletions lib/Doctrine/ODM/MongoDB/Mapping/Annotations/AbstractIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
abstract class AbstractIndex implements Annotation
{
/** @var string[] */
public $keys = [];
public $keys;

/** @var string */
public $name;
Expand All @@ -22,16 +22,16 @@ abstract class AbstractIndex implements Annotation
public $order;

/** @var bool */
public $unique = false;
public $unique;

/** @var bool */
public $sparse = false;
public $sparse;

/** @var mixed[] */
public $options = [];
public $options;

/** @var array */
public $partialFilterExpression = [];
public $partialFilterExpression;

public function __construct(
array $keys = [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@
namespace Doctrine\ODM\MongoDB\Mapping\Annotations;

use Attribute;
use Doctrine\Common\Annotations\Annotation;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;

/**
* Specifies the change tracking policy for a document
*
* @Annotation
* @NamedArgumentConstructor
*/
#[Attribute(Attribute::TARGET_CLASS)]
final class ChangeTrackingPolicy extends Annotation
final class ChangeTrackingPolicy implements Annotation
{
/** @var string */
public $value;

public function __construct(string $value)
{
$this->value = $value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
#[Attribute(Attribute::TARGET_CLASS)]
final class DiscriminatorField implements Annotation
{
/** @var string|null */
/** @var string */
public $value;

public function __construct(?string $value = null)
public function __construct(string $value)
{
$this->value = $value;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ final class Document extends AbstractDocument
public $repositoryClass;

/** @var Index[] */
public $indexes = [];
public $indexes;

/** @var bool */
public $readOnly = false;
public $readOnly;

/** @var string|null */
public $shardKey;
Expand Down
13 changes: 2 additions & 11 deletions lib/Doctrine/ODM/MongoDB/Mapping/Annotations/EmbedMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
#[Attribute(Attribute::TARGET_PROPERTY)]
final class EmbedMany extends AbstractField
{
/** @var string */
public $type = ClassMetadata::MANY;

/** @var bool */
public $embedded = true;

Expand All @@ -36,29 +33,23 @@ final class EmbedMany extends AbstractField
/** @var string|null */
public $defaultDiscriminatorValue;

/** @var string */
public $strategy = CollectionHelper::DEFAULT_STRATEGY;

/** @var string|null */
public $collectionClass;

public function __construct(
?string $name = null,
bool $nullable = false,
array $options = [],
?string $strategy = null,
string $strategy = CollectionHelper::DEFAULT_STRATEGY,
bool $notSaved = false,
string $type = ClassMetadata::MANY,
bool $embedded = true,
?string $targetDocument = null,
?string $discriminatorField = null,
?array $discriminatorMap = null,
?string $defaultDiscriminatorValue = null,
?string $collectionClass = null
) {
parent::__construct($name, $type, $nullable, $options, $strategy, $notSaved);
parent::__construct($name, ClassMetadata::MANY, $nullable, $options, $strategy, $notSaved);

$this->embedded = $embedded;
$this->targetDocument = $targetDocument;
$this->discriminatorField = $discriminatorField;
$this->discriminatorMap = $discriminatorMap;
Expand Down
8 changes: 1 addition & 7 deletions lib/Doctrine/ODM/MongoDB/Mapping/Annotations/EmbedOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
#[Attribute(Attribute::TARGET_PROPERTY)]
final class EmbedOne extends AbstractField
{
/** @var string */
public $type = ClassMetadata::ONE;

/** @var bool */
public $embedded = true;

Expand All @@ -41,16 +38,13 @@ public function __construct(
array $options = [],
?string $strategy = null,
bool $notSaved = false,
string $type = ClassMetadata::ONE,
bool $embedded = true,
?string $targetDocument = null,
?string $discriminatorField = null,
?array $discriminatorMap = null,
?string $defaultDiscriminatorValue = null
) {
parent::__construct($name, $type, $nullable, $options, $strategy, $notSaved);
parent::__construct($name, ClassMetadata::ONE, $nullable, $options, $strategy, $notSaved);

$this->embedded = $embedded;
$this->targetDocument = $targetDocument;
$this->discriminatorField = $discriminatorField;
$this->discriminatorMap = $discriminatorMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@
namespace Doctrine\ODM\MongoDB\Mapping\Annotations;

use Attribute;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;

/**
* Identifies a class as a document that can be embedded but not stored by itself
*
* @Annotation
* @NamedArgumentConstructor
*/
#[Attribute(Attribute::TARGET_CLASS)]
final class EmbeddedDocument extends AbstractDocument
{
/** @var Index[] */
public $indexes = [];
public $indexes;

public function __construct(array $indexes = [])
{
$this->indexes = $indexes;
}
}
4 changes: 2 additions & 2 deletions lib/Doctrine/ODM/MongoDB/Mapping/Annotations/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ final class File extends AbstractDocument
public $repositoryClass;

/** @var Index[] */
public $indexes = [];
public $indexes;

/** @var bool bool */
public $readOnly = false;
public $readOnly;

/** @var string|null */
public $shardKey;
Expand Down
21 changes: 3 additions & 18 deletions lib/Doctrine/ODM/MongoDB/Mapping/Annotations/File/ChunkSize.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,8 @@
#[Attribute(Attribute::TARGET_PROPERTY)]
final class ChunkSize extends AbstractField
{
/** @var string */
public $name = 'chunkSize';

/** @var string */
public $type = 'int';

/** @var bool */
public $notSaved = true;

public function __construct(
?string $name = 'chunkSize',
string $type = 'int',
bool $nullable = false,
array $options = [],
?string $strategy = null,
bool $notSaved = true
) {
parent::__construct($name, $type, $nullable, $options, $strategy, $notSaved);
public function __construct(?string $name = 'chunkSize')
{
parent::__construct($name, 'int', false, [], null, true);
}
}
21 changes: 3 additions & 18 deletions lib/Doctrine/ODM/MongoDB/Mapping/Annotations/File/Filename.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,8 @@
#[Attribute(Attribute::TARGET_PROPERTY)]
final class Filename extends AbstractField
{
/** @var string */
public $name = 'filename';

/** @var string */
public $type = 'string';

/** @var bool */
public $notSaved = true;

public function __construct(
?string $name = 'filename',
string $type = 'string',
bool $nullable = false,
array $options = [],
?string $strategy = null,
bool $notSaved = true
) {
parent::__construct($name, $type, $nullable, $options, $strategy, $notSaved);
public function __construct(?string $name = 'filename')
{
parent::__construct($name, 'string', false, [], null, true);
}
}
21 changes: 3 additions & 18 deletions lib/Doctrine/ODM/MongoDB/Mapping/Annotations/File/Length.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,8 @@
#[Attribute(Attribute::TARGET_PROPERTY)]
final class Length extends AbstractField
{
/** @var string */
public $name = 'length';

/** @var string */
public $type = 'int';

/** @var bool */
public $notSaved = true;

public function __construct(
?string $name = 'length',
string $type = 'int',
bool $nullable = false,
array $options = [],
?string $strategy = null,
bool $notSaved = true
) {
parent::__construct($name, $type, $nullable, $options, $strategy, $notSaved);
public function __construct(?string $name = 'length')
{
parent::__construct($name, 'int', false, [], null, true);
}
}
11 changes: 1 addition & 10 deletions lib/Doctrine/ODM/MongoDB/Mapping/Annotations/File/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@
#[Attribute(Attribute::TARGET_PROPERTY)]
final class Metadata extends AbstractField
{
/** @var string */
public $name = 'metadata';

/** @var string */
public $type = ClassMetadata::ONE;

/** @var bool */
public $embedded = true;

Expand All @@ -39,20 +33,17 @@ final class Metadata extends AbstractField

public function __construct(
?string $name = 'metadata',
string $type = ClassMetadata::ONE,
bool $nullable = false,
array $options = [],
?string $strategy = null,
bool $notSaved = false,
bool $embedded = true,
?string $targetDocument = null,
?string $discriminatorField = null,
?array $discriminatorMap = null,
?string $defaultDiscriminatorValue = null
) {
parent::__construct($name, $type, $nullable, $options, $strategy, $notSaved);
parent::__construct($name, ClassMetadata::ONE, $nullable, $options, $strategy, $notSaved);

$this->embedded = $embedded;
$this->targetDocument = $targetDocument;
$this->discriminatorField = $discriminatorField;
$this->discriminatorMap = $discriminatorMap;
Expand Down
21 changes: 3 additions & 18 deletions lib/Doctrine/ODM/MongoDB/Mapping/Annotations/File/UploadDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,8 @@
#[Attribute(Attribute::TARGET_PROPERTY)]
final class UploadDate extends AbstractField
{
/** @var string */
public $name = 'uploadDate';

/** @var string */
public $type = 'date';

/** @var bool */
public $notSaved = true;

public function __construct(
?string $name = 'uploadDate',
string $type = 'date',
bool $nullable = false,
array $options = [],
?string $strategy = null,
bool $notSaved = true
) {
parent::__construct($name, $type, $nullable, $options, $strategy, $notSaved);
public function __construct(?string $name = 'uploadDate', string $type = 'date')
{
parent::__construct($name, $type, false, [], null, true);
}
}
13 changes: 1 addition & 12 deletions lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Id.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ final class Id extends AbstractField
/** @var bool */
public $id = true;

/** @var string|null */
public $type;

/** @var string */
public $strategy = 'auto';

public function __construct(
?string $name = null,
?string $type = null,
Expand All @@ -33,11 +27,6 @@ public function __construct(
?string $strategy = 'auto',
bool $notSaved = false
) {
$this->name = $name;
$this->type = $type;
$this->nullable = $nullable;
$this->options = $options;
$this->strategy = $strategy;
$this->notSaved = $notSaved;
parent::__construct($name, $type, $nullable, $options, $strategy, $notSaved);
}
}
Loading

0 comments on commit 9edc694

Please sign in to comment.