Completed
Push — master ( 7fe739...31f356 )
by Alexey
02:13
created

UseStatements::findUseStatement()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
crap 3
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Reflection\ClassUseStatements;
6
7
use \ArrayObject;
8
9
/**
10
 * Class UseStatements
11
 * @package UsesReflection
12
 */
13
class UseStatements extends ArrayObject {
14
15
    /**
16
     * @param UseStatement $useStatement
17
     * @return UseStatements
18
     */
19 1
    public function add(UseStatement $useStatement): UseStatements {
20 1
        $this->append($useStatement);
21
22 1
        return $this;
23
    }
24
25
    /**
26
     * @param string $class
27
     * @return bool
28
     */
29 1
    public function hasClass(string $class): bool {
30
        /** @var UseStatement $useStatement */
31 1
        foreach ($this as $useStatement) {
32 1
            if (in_array($class, $useStatement->toArray())) {
33 1
                return true;
34
            }
35
        }
36
37 1
        return false;
38
    }
39
40
    /**
41
     * @param string $class
42
     * @return UseStatement|null
43
     */
44 1
    public function findUseStatement(string $class): ?UseStatement {
45
        /** @var UseStatement $useStatement */
46 1
        foreach ($this as $useStatement) {
47 1
            if (in_array($class, $useStatement->toArray())) {
48 1
                return $useStatement;
49
            }
50
        }
51
52 1
        return null;
53
    }
54
55
}