1
1
<?php
2
2
namespace exussum12 \CoverageChecker \Loaders ;
3
3
4
+ use Exception ;
4
5
use exussum12 \CoverageChecker \FileChecker ;
5
6
use ReflectionFunction ;
6
7
use ReflectionFunctionAbstract ;
@@ -144,12 +145,16 @@ protected function handleRelatedError($filename, $line, $error)
144
145
$ line
145
146
);
146
147
147
- $ reflection = $ this ->getReflector ($ matches );
148
- if ($ reflection && ($ filename = $ reflection ->getFileName ())) {
148
+ try {
149
+ $ reflection = $ this ->getReflector ($ matches );
150
+ $ filename = $ reflection ->getFileName ();
149
151
$ currentLine = $ reflection ->getStartLine ();
152
+
150
153
while ($ currentLine < $ reflection ->getEndLine ()) {
151
154
$ this ->addError ($ filename , $ currentLine ++, $ error );
152
155
}
156
+ } catch (Exception $ exception ) {
157
+ // can't find any more info about this method, so just carry on
153
158
}
154
159
}
155
160
}
@@ -167,7 +172,7 @@ protected function addError($filename, $lineNumber, $error)
167
172
$ this ->invalidLines [$ filename ][$ lineNumber ][] = $ error ;
168
173
}
169
174
170
- protected function getReflector (array $ matches ): ReflectionFunctionAbstract
175
+ protected function getReflector (array $ matches ): ReflectionFunctionAbstract
171
176
{
172
177
if ($ matches ['class ' ]) {
173
178
return $ this ->getClassReflector ($ matches );
@@ -176,31 +181,28 @@ protected function getReflector(array $matches): ReflectionFunctionAbstract
176
181
return $ this ->getFunctionReflector ($ matches );
177
182
}
178
183
179
- private function appendError ($ filename , $ lineNumber , $ error )
184
+ private function appendError (string $ filename , int $ lineNumber , string $ error )
180
185
{
181
186
end ($ this ->invalidLines [$ filename ][$ lineNumber ]);
182
187
$ key = key ($ this ->invalidLines [$ filename ][$ lineNumber ]);
183
188
$ this ->invalidLines [$ filename ][$ lineNumber ][$ key ] .= ' ' . $ error ;
184
189
}
185
190
186
- protected function getClassReflector (array $ matches )
191
+ protected function getClassReflector (array $ matches ): ReflectionMethod
187
192
{
188
193
if (!method_exists ($ matches ['class ' ], $ matches ['function ' ])) {
189
- return false ;
194
+ throw new Exception ( " Missing class function " ) ;
190
195
}
191
196
return new ReflectionMethod (
192
197
$ matches ['class ' ],
193
198
$ matches ['function ' ]
194
199
);
195
200
}
196
201
197
- /**
198
- * @return bool|ReflectionFunction
199
- */
200
- protected function getFunctionReflector (array $ matches )
202
+ protected function getFunctionReflector (array $ matches ): ReflectionFunction
201
203
{
202
204
if (!function_exists ($ matches ['function ' ])) {
203
- return false ;
205
+ throw new Exception ( " Missing function reflector " ) ;
204
206
}
205
207
return new ReflectionFunction (
206
208
$ matches ['function ' ]
0 commit comments