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

DocumentAnnotationListener   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 14
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A accept() 0 11 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