Code Duplication    Length = 16-17 lines in 2 locations

src/Mapping/Annotation/Listener/ParameterListener.php 1 location

@@ 13-28 (lines=16) @@
10
use AmaTeam\ElasticSearch\Mapping\DocumentMapping;
11
use ReflectionClass;
12
13
class ParameterListener implements AnnotationListenerInterface
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

src/Mapping/Annotation/Property/Listener/ParameterListener.php 1 location

@@ 14-30 (lines=17) @@
11
use AmaTeam\ElasticSearch\Mapping\PropertyMappingView;
12
use ReflectionProperty;
13
14
class ParameterListener implements AnnotationListenerInterface
15
{
16
    public function accept(ReflectionProperty $property, PropertyMapping $descriptor, $annotation)
17
    {
18
        if (!($annotation instanceof ParameterAnnotationInterface)) {
19
            return;
20
        }
21
        /** @var PropertyMappingView[] $views */
22
        $views = [$descriptor->getDefaultView()];
23
        if ($annotation instanceof ViewAwareAnnotationInterface && !empty($annotation->getViews())) {
24
            $views = array_map([$descriptor, 'requestView'], $annotation->getViews());
25
        }
26
        foreach ($views as $view) {
27
            $view->setParameter($annotation->getParameter(), $annotation->getValue());
28
        }
29
    }
30
}
31