Completed
Pull Request — master (#204)
by
unknown
04:13
created

ParsedClass::getMethods()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5

Importance

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