ParsedClass::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 4
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ParaTest\Parser;
6
7
class ParsedClass extends ParsedObject
8
{
9
    /**
10
     * @var string
11
     */
12
    private $namespace;
13
14
    /**
15
     * A collection of methods belonging
16
     * to the parsed class.
17
     *
18
     * @var array
19
     */
20
    private $methods;
21
22 35
    public function __construct(string $doc, string $name, string $namespace, array $methods = [])
23
    {
24 35
        parent::__construct($doc, $name);
25 35
        $this->namespace = $namespace;
26 35
        $this->methods = $methods;
27 35
    }
28
29
    /**
30
     * Return the methods of this parsed class
31
     * optionally filtering on annotations present
32
     * on a method.
33
     *
34
     * @param array $annotations
35
     *
36
     * @return array
37
     */
38
    public function getMethods(array $annotations = []): array
39
    {
40 24
        $methods = array_filter($this->methods, function (ParsedFunction $method) use ($annotations): bool {
41 24
            foreach ($annotations as $a => $v) {
42 3
                foreach (explode(',', $v) as $subValue) {
43 3
                    if ($method->hasAnnotation($a, $subValue)) {
44 3
                        return true;
45
                    }
46
                }
47
            }
48
49 24
            return false;
50 24
        });
51
52 24
        return $methods ? $methods : $this->methods;
53
    }
54
55
    /**
56
     * Return the namespace of the parsed class.
57
     *
58
     * @return string
59
     */
60 1
    public function getNamespace(): string
61
    {
62 1
        return $this->namespace;
63
    }
64
}
65