1 | <?php |
||
22 | class FileResult implements CoverageResultNode |
||
23 | { |
||
24 | |||
25 | use CoverageResult; |
||
26 | |||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | private $path; |
||
32 | |||
33 | /** |
||
34 | * @var \cloak\result\ResultFactory |
||
35 | */ |
||
36 | private $factory; |
||
37 | |||
38 | /** |
||
39 | * @var LineRange |
||
40 | */ |
||
41 | private $lineRange; |
||
42 | |||
43 | |||
44 | /** |
||
45 | * @param string $path |
||
46 | * @param LineResultSelectable $selector |
||
47 | */ |
||
48 | public function __construct($path, LineResultSelectable $selector) |
||
49 | { |
||
50 | $this->path = $path; |
||
51 | $this->resolveLineRange($selector); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @return string |
||
56 | */ |
||
57 | public function getPath() |
||
61 | |||
62 | /** |
||
63 | * @return string |
||
64 | */ |
||
65 | public function getName() |
||
69 | |||
70 | /** |
||
71 | * @param string $directoryPath |
||
72 | */ |
||
73 | public function getRelativePath($directoryPath) |
||
74 | { |
||
75 | $directory = realpath($directoryPath) . "/"; |
||
76 | |||
77 | return str_replace($directory, "", $this->getPath()); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @param $value |
||
82 | * @return bool |
||
83 | */ |
||
84 | public function matchPath($value) |
||
85 | { |
||
86 | $pathPattern = preg_quote($value, '/'); |
||
87 | $result = preg_match("/" . $pathPattern . "/", $this->getPath()); |
||
88 | |||
89 | return ($result === 0) ? false : true; |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * @return int |
||
94 | */ |
||
95 | public function getLineCount() |
||
99 | |||
100 | /** |
||
101 | * @return \cloak\result\collection\LineResultCollection |
||
102 | */ |
||
103 | public function getLineResults() |
||
107 | |||
108 | /** |
||
109 | * @param FileResult $file |
||
110 | * @return bool |
||
111 | */ |
||
112 | public function equals(FileResult $file) |
||
116 | |||
117 | /** |
||
118 | * @param LineResultSelectable $selector |
||
119 | */ |
||
120 | protected function resolveLineRange(LineResultSelectable $selector) |
||
121 | { |
||
122 | $reflection = new FileReflection($this->getPath()); |
||
123 | $this->lineRange = $reflection->getLineRange(); |
||
124 | |||
125 | $this->factory = new ResultFactory($reflection); |
||
126 | $this->lineResults = $selector->selectByReflection($reflection); |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * @return CoverageResultNodeCollection |
||
131 | */ |
||
132 | public function getClassResults() |
||
136 | |||
137 | /** |
||
138 | * @return \cloak\result\collection\CoverageResultCollection |
||
139 | */ |
||
140 | public function getTraitResults() |
||
144 | |||
145 | /** |
||
146 | * @return bool |
||
147 | */ |
||
148 | public function hasChildResults() |
||
152 | |||
153 | /** |
||
154 | * @return CoverageResultNodeCollection |
||
155 | */ |
||
156 | public function getChildResults() |
||
161 | |||
162 | } |
||
163 |