Passed
Push — master ( e9c651...e1baf6 )
by Christian
02:19
created

AbstractListener::containsTrait()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 17
rs 9.6111
c 0
b 0
f 0
cc 5
nc 4
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) Christian Gripp <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Core23\Doctrine\EventListener\ORM;
13
14
use Doctrine\Common\EventSubscriber;
15
use ReflectionClass;
16
17
abstract class AbstractListener implements EventSubscriber
18
{
19
    /**
20
     * @param ReflectionClass $reflection
21
     * @param string          $class
22
     *
23
     * @return bool
24
     */
25
    final protected function containsTrait(ReflectionClass $reflection, string $class): bool
26
    {
27
        do {
28
            $traits = $reflection->getTraitNames();
29
30
            if (\in_array($class, $traits)) {
31
                return true;
32
            }
33
34
            foreach ($reflection->getTraits() as $reflTraits) {
35
                if ($this->containsTrait($reflTraits, $class)) {
36
                    return true;
37
                }
38
            }
39
        } while ($reflection = $reflection->getParentClass());
40
41
        return false;
42
    }
43
}
44