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

ClassParameterAnnotationListener::accept()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 12
Code Lines 8

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 8
nc 5
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AmaTeam\ElasticSearch\Entity\Annotation\Listener\Mapping\Clazz;
6
7
use AmaTeam\ElasticSearch\API\Annotation\Mapping\ParameterAnnotationInterface;
8
use AmaTeam\ElasticSearch\API\Annotation\Mapping\ViewAwareAnnotationInterface;
9
use AmaTeam\ElasticSearch\Entity\Annotation\ClassAnnotationListenerInterface;
10
use AmaTeam\ElasticSearch\Entity\Entity;
11
use ReflectionClass;
12
13 View Code Duplication
class ClassParameterAnnotationListener implements ClassAnnotationListenerInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    public function accept(ReflectionClass $class, Entity $entity, $annotation): void
16
    {
17
        if (!($annotation instanceof ParameterAnnotationInterface)) {
18
            return;
19
        }
20
        $mapping = $entity->getMapping();
21
        $views = [$mapping->getDefaultView()];
22
        if ($annotation instanceof ViewAwareAnnotationInterface && !empty($annotation->getViews())) {
23
            $views = $mapping->requestViews(...$annotation->getViews());
24
        }
25
        foreach ($views as $view) {
26
            $view->setParameter($annotation->getParameter(), $annotation->getValue());
27
        }
28
    }
29
}
30