Passed
Pull Request — master (#34)
by Anatoly
02:43
created

AbstractAnnotation::getReferencedObjects()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 19
ccs 12
cts 12
cp 1
rs 9.9
cc 4
nc 1
nop 1
crap 4
1
<?php declare(strict_types=1);
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Fenric <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Fenric
8
 * @license https://github.com/sunrise-php/http-router/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-router
10
 */
11
12
namespace Sunrise\Http\Router\OpenApi;
13
14
/**
15
 * Import classes
16
 */
17
use Doctrine\Common\Annotations\SimpleAnnotationReader;
18
19
/**
20
 * Import functions
21
 */
22
use function array_merge;
23
use function array_walk_recursive;
24
25
/**
26
 * AbstractAnnotation
27
 */
28
abstract class AbstractAnnotation extends AbstractObject
29
{
30
31
    /**
32
     * Recursively collects all annotations referenced by this object or its children
33
     *
34
     * @param SimpleAnnotationReader $annotationReader
35
     *
36
     * @return ComponentObjectInterface[]
37
     */
38 1
    public function getReferencedObjects(SimpleAnnotationReader $annotationReader) : array
39
    {
40 1
        $fields = $this->getFields();
41 1
        $objects = [];
42
43
        array_walk_recursive($fields, function ($value) use ($annotationReader, &$objects) {
44 1
            if ($value instanceof AbstractAnnotation) {
45 1
                $objects = array_merge($objects, $value->getReferencedObjects($annotationReader));
46 1
            } elseif ($value instanceof AbstractAnnotationReference) {
47 1
                $object = $value->getAnnotation($annotationReader);
48 1
                $objects[] = $object;
49
50 1
                if ($object instanceof AbstractAnnotation) {
51 1
                    $objects = array_merge($objects, $object->getReferencedObjects($annotationReader));
52
                }
53
            }
54 1
        });
55
56 1
        return $objects;
57
    }
58
}
59