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

EmbeddableAnnotationListener::accept()   B

Complexity

Conditions 6
Paths 7

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 7
nc 7
nop 3
dl 0
loc 11
rs 8.8571
c 1
b 0
f 0
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