Passed
Push — feature/initial-implementation ( 89e787...88960a )
by Fike
02:13
created

EmbeddableAnnotationListener   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 13
rs 10
c 1
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B accept() 0 11 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AmaTeam\ElasticSearch\Entity\Annotation\Listener;
6
7
use AmaTeam\ElasticSearch\API\Annotation\Embeddable;
8
use AmaTeam\ElasticSearch\Entity\Annotation\ClassAnnotationListenerInterface;
9
use AmaTeam\ElasticSearch\Entity\Entity;
10
use ReflectionClass;
11
12
class EmbeddableAnnotationListener implements ClassAnnotationListenerInterface
13
{
14
    public function accept(ReflectionClass $class, Entity $entity, $annotation): void
15
    {
16
        if (!($annotation instanceof Embeddable)) {
17
            return;
18
        }
19
        $parent = $annotation->inherits;
20
        if ($parent === null || $parent === true) {
21
            $parent = $class->getParentClass() ? $class->getParentClass()->getName() : null;
22
        }
23
        if (is_string($parent)) {
24
            $entity->setParentName($parent);
25
        }
26
    }
27
}
28