Skip to content

Commit

Permalink
update Indexes annotation and fix missing types
Browse files Browse the repository at this point in the history
  • Loading branch information
IonBazan committed Aug 5, 2021
1 parent bffbb53 commit b32d49a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ abstract class AbstractIndex implements Annotation
/** @var string[] */
public $keys;

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

/** @var bool|null */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#[Attribute(Attribute::TARGET_PROPERTY)]
final class ChunkSize extends AbstractField
{
public function __construct(?string $name = 'chunkSize')
public function __construct()
{
parent::__construct($name, 'int', false, [], null, true);
parent::__construct('chunkSize', 'int', false, [], null, true);
}
}
17 changes: 15 additions & 2 deletions lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Indexes.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,29 @@
namespace Doctrine\ODM\MongoDB\Mapping\Annotations;

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

use function is_array;

/**
* Specifies a list of indexes for a document
*
* @deprecated class was deprecated in doctrine/mongodb-odm 2.2 and will be removed in 3.0. Specify all Index and UniqueIndex annotations on a class level.
*
* @Annotation
* @NamedArgumentConstructor
*/
#[Attribute(Attribute::TARGET_CLASS)]
final class Indexes extends BaseAnnotation implements Annotation
final class Indexes implements Annotation
{
/** @var Index[] */
public $value;

/**
* @param Index[]|Index $value
*/
public function __construct($value = [])
{
$this->value = is_array($value) ? $value : [$value];
}
}
45 changes: 0 additions & 45 deletions lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Inheritance.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ final class ReferenceMany extends AbstractField
/** @var int|null */
public $skip;

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

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

Expand Down
8 changes: 2 additions & 6 deletions lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ public function loadMetadataForClass($className, \Doctrine\Persistence\Mapping\C
'The "@Indexes" annotation used in class "%s" is deprecated. Specify all "@Index" and "@UniqueIndex" annotations on the class.',
$className
);
$value = $annot->value;
foreach (is_array($value) ? $value : [$value] as $index) {
foreach ($annot->value as $index) {
$this->addIndex($metadata, $index);
}
} elseif ($annot instanceof ODM\InheritanceType) {
Expand Down Expand Up @@ -218,10 +217,7 @@ public function loadMetadataForClass($className, \Doctrine\Persistence\Mapping\C
}

if ($annot instanceof ODM\Indexes) {
// Setting the type to mixed is a workaround until https://github.com/doctrine/annotations/pull/209 is released.
/** @var mixed $value */
$value = $annot->value;
foreach (is_array($value) ? $value : [$value] as $index) {
foreach ($annot->value as $index) {
$indexes[] = $index;
}
} elseif ($annot instanceof ODM\AlsoLoad) {
Expand Down
2 changes: 0 additions & 2 deletions lib/Doctrine/ODM/MongoDB/Mapping/Driver/AttributeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,3 @@ public static function create($paths = [], ?Reader $reader = null): AnnotationDr
return new self($reader, $paths);
}
}

interface_exists(ClassMetadata::class);

0 comments on commit b32d49a

Please sign in to comment.