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

DocumentAnnotationListener   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

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

1 Method

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