Passed
Push — feature/initial-implementation ( 79751f...3b7c72 )
by Fike
01:53
created

DocumentAnnotationListener::accept()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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