Passed
Branch release/v2.0.0 (52e4c5)
by Anatoly
05:40 queued 01:36
created

AbstractAnnotation::toArray()   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 20
ccs 0
cts 16
cp 0
rs 8.8333
cc 7
nc 5
nop 0
crap 56
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\Annotation\OpenApi;
13
14
/**
15
 * Import functions
16
 */
17
use function is_array;
18
19
/**
20
 * AbstractAnnotation
21
 */
22
abstract class AbstractAnnotation implements AnnotationInterface
23
{
24
25
    /**
26
     * {@inheritDoc}
27
     */
28
    public function toArray() : array
29
    {
30
        $result = [];
31
32
        foreach ($this as $field => $value) {
33
            if (null === $value) {
34
                continue;
35
            }
36
37
            if (!is_array($value)) {
38
                $result[$field] = ($value instanceof AnnotationInterface) ? $value->toArray() : $value;
39
                continue;
40
            }
41
42
            foreach ($value as $key => $item) {
43
                $result[$field][$key] = ($item instanceof AnnotationInterface) ? $item->toArray() : $item;
44
            }
45
        }
46
47
        return $result;
48
    }
49
}
50