Passed
Push — master ( 1d459e...f70c41 )
by Mr
02:10
created

InheritanceReader::flatMapTraits()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/interop project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Daikon\Interop;
10
11
use ReflectionClass;
12
13
trait InheritanceReader
14
{
15 7
    private static function getInheritance(ReflectionClass $classReflection, bool $includeTraits = false): array
16
    {
17 7
        $parent = $classReflection;
18 7
        $classes = $includeTraits
19 7
            ? array_merge([$classReflection], static::flatMapTraits($classReflection))
20 7
            : [$classReflection];
21
22 7
        while ($parent = $parent->getParentClass()) {
23
            $classes = $includeTraits
24
                ? array_merge($classes, [$parent], static::flatMapTraits($parent))
25
                : array_merge($classes, [$classReflection]);
26
        }
27
28 7
        return $classes;
29
    }
30
31 7
    private static function flatMapTraits(ReflectionClass $classReflection): array
32
    {
33 7
        $traits = [];
34 7
        $currentTrait = $classReflection;
35 7
        foreach ($currentTrait->getTraits() as $trait) {
36 7
            $traits = array_merge($traits, [$trait], static::flatMapTraits($trait));
37
        }
38
39 7
        return $traits;
40
    }
41
}
42