ClassUtils   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
dl 0
loc 23
rs 10
c 2
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A containsTrait() 0 21 6
1
<?php
2
3
/*
4
 * (c) Christian Gripp <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Core23\Doctrine\Util;
11
12
use InvalidArgumentException;
13
use ReflectionClass;
14
15
final class ClassUtils
16
{
17
    public static function containsTrait(ReflectionClass $reflection, string $class): bool
18
    {
19
        if (!trait_exists($class)) {
20
            throw new InvalidArgumentException(sprintf('Class "%s" is not a valid trait', $class));
21
        }
22
23
        do {
24
            $traits = $reflection->getTraitNames();
25
26
            if (\in_array($class, $traits, true)) {
27
                return true;
28
            }
29
30
            foreach ($reflection->getTraits() as $reflTraits) {
31
                if (static::containsTrait($reflTraits, $class)) {
32
                    return true;
33
                }
34
            }
35
        } while ($reflection = $reflection->getParentClass());
36
37
        return false;
38
    }
39
}
40