Passed
Push — feature/initial-implementation ( 0c2c6c...79751f )
by Fike
01:54
created

ParameterListener::accept()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 7
nc 5
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AmaTeam\ElasticSearch\Mapping\Annotation\Listener;
6
7
use AmaTeam\ElasticSearch\API\Annotation\Mapping\ParameterAnnotationInterface;
8
use AmaTeam\ElasticSearch\API\Annotation\Mapping\ViewAwareAnnotationInterface;
9
use AmaTeam\ElasticSearch\Mapping\Annotation\AnnotationListenerInterface;
10
use AmaTeam\ElasticSearch\Mapping\DocumentMapping;
11
use ReflectionClass;
12
13 View Code Duplication
class ParameterListener implements AnnotationListenerInterface
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 $reflection, DocumentMapping $descriptor, $annotation): void
16
    {
17
        if (!($annotation instanceof ParameterAnnotationInterface)) {
18
            return;
19
        }
20
        $views = [$descriptor->getDefaultView()];
21
        if ($annotation instanceof ViewAwareAnnotationInterface && !empty($annotation->getViews())) {
22
            $views = $descriptor->requestViews(...$annotation->getViews());
23
        }
24
        foreach ($views as $view) {
25
            $view->setParameter($annotation->getParameter(), $annotation->getValue());
26
        }
27
    }
28
}
29