Passed
Push — feature/initial-implementation ( 3b7c72...40c5a6 )
by Fike
01:49
created

DocumentAnnotationListener::accept()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AmaTeam\ElasticSearch\Entity\Annotation\Listener\Indexing;
6
7
use AmaTeam\ElasticSearch\API\Annotation\Document;
8
use AmaTeam\ElasticSearch\Entity\Annotation\ClassAnnotationListenerInterface;
9
use AmaTeam\ElasticSearch\Entity\Entity;
10
use AmaTeam\ElasticSearch\Entity\Indexing\Indexing;
11
use ReflectionClass;
12
13
class DocumentAnnotationListener implements ClassAnnotationListenerInterface
14
{
15
    public function accept(ReflectionClass $class, Entity $entity, $annotation): void
16
    {
17
        if (!($annotation instanceof Document)) {
18
            return;
19
        }
20
        $target = Indexing::from($entity->getIndexing())
21
            ->setWriteIndices($annotation->writeIndices)
22
            ->setReadIndices($annotation->readIndices)
23
            ->setType($annotation->type);
24
        $entity
25
            ->setIndexing($target)
26
            ->setRootLevelDocument(true);
27
    }
28
}
29