Group::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by solly [18.10.17 4:46]
4
 */
5
6
namespace insolita\codestat\lib\collection;
7
8
class Group
9
{
10
    /**
11
     * @var string
12
     */
13
    private $name;
14
    
15
    /**
16
     * @var string|callable
17
     */
18
    private $rule;
19
    
20
    /**
21
     * @var array
22
     */
23
    private $files = [];
24
    
25
    /**
26
     * @param string          $name
27
     * @param string|callable $rule
28
     *
29
     * @throws \InvalidArgumentException
30
     */
31
    public function __construct($name, $rule)
32
    {
33
        if (!is_string($name) || empty($name)) {
0 ignored issues
show
introduced by
The condition is_string($name) is always true.
Loading history...
34
            throw new \InvalidArgumentException($name . ' should be non-empty string');
35
        }
36
        if (empty($rule) || !(is_string($rule) || is_callable($rule))) {
37
            throw new \InvalidArgumentException($name . ' should be non-empty string or callable');
38
        }
39
        $this->name = $name;
40
        $this->rule = $rule;
41
    }
42
    
43
    /**
44
     * @param string $file
45
     */
46
    public function addFile($file)
47
    {
48
        if (!in_array($file, $this->files)) {
49
            $this->files[] = $file;
50
        }
51
    }
52
    
53
    /**
54
     * @return string
55
     */
56
    public function getName()
57
    {
58
        return $this->name;
59
    }
60
    
61
    /**
62
     * @return array
63
     */
64
    public function getFiles()
65
    {
66
        return $this->files;
67
    }
68
    
69
    /**
70
     * @return int
71
     */
72
    public function getNumberOfClasses()
73
    {
74
        return count($this->files);
75
    }
76
    
77
    /**
78
     * @param \ReflectionClass $reflection
79
     *
80
     * @return boolean
81
     */
82
    public function validate(\ReflectionClass $reflection)
83
    {
84
        if (is_string($this->rule)) {
85
            return $reflection->isSubclassOf($this->rule);
86
        } elseif (is_callable($this->rule)) {
87
            return call_user_func($this->rule, $reflection);
88
        } else {
89
            return false;
90
        }
91
    }
92
}
93