1414use PHPUnit \Util \Test ;
1515use SebastianBergmann \CodeCoverage \Driver \Driver ;
1616use SebastianBergmann \CodeCoverage \Driver \PcovDriver ;
17+ use SebastianBergmann \CodeCoverage \Driver \PcovNotAvailableException ;
1718use SebastianBergmann \CodeCoverage \Driver \PhpdbgDriver ;
19+ use SebastianBergmann \CodeCoverage \Driver \PhpdbgNotAvailableException ;
1820use SebastianBergmann \CodeCoverage \Driver \XdebugDriver ;
21+ use SebastianBergmann \CodeCoverage \Driver \XdebugNotAvailableException ;
22+ use SebastianBergmann \CodeCoverage \Driver \XdebugNotEnabledException ;
1923use SebastianBergmann \CodeCoverage \Node \Builder ;
2024use SebastianBergmann \CodeCoverage \Node \Directory ;
2125use SebastianBergmann \CodeUnitReverseLookup \Wizard ;
@@ -129,9 +133,6 @@ final class CodeCoverage
129133 */
130134 private $ report ;
131135
132- /**
133- * @throws RuntimeException
134- */
135136 public function __construct (Driver $ driver = null , Filter $ filter = null )
136137 {
137138 if ($ filter === null ) {
@@ -221,8 +222,6 @@ public function setTests(array $tests): void
221222 * Start collection of code coverage information.
222223 *
223224 * @param PhptTestCase|string|TestCase $id
224- *
225- * @throws RuntimeException
226225 */
227226 public function start ($ id , bool $ clear = false ): void
228227 {
@@ -246,8 +245,6 @@ public function start($id, bool $clear = false): void
246245 *
247246 * @throws MissingCoversAnnotationException
248247 * @throws CoveredCodeNotExecutedException
249- * @throws RuntimeException
250- * @throws \ReflectionException
251248 */
252249 public function stop (bool $ append = true , $ linesToBeCovered = [], array $ linesToBeUsed = [], bool $ ignoreForceCoversAnnotation = false ): RawCodeCoverageData
253250 {
@@ -271,11 +268,11 @@ public function stop(bool $append = true, $linesToBeCovered = [], array $linesTo
271268 * @param PhptTestCase|string|TestCase $id
272269 * @param array|false $linesToBeCovered
273270 *
274- * @throws \SebastianBergmann\CodeCoverage\ UnintentionallyCoveredCodeException
275- * @throws \SebastianBergmann\CodeCoverage\ MissingCoversAnnotationException
276- * @throws \SebastianBergmann\CodeCoverage\ CoveredCodeNotExecutedException
277- * @throws \ReflectionException
278- * @throws RuntimeException
271+ * @throws UnintentionallyCoveredCodeException
272+ * @throws MissingCoversAnnotationException
273+ * @throws CoveredCodeNotExecutedException
274+ * @throws TestIdMissingException
275+ * @throws ReflectionException
279276 */
280277 public function append (RawCodeCoverageData $ rawData , $ id = null , bool $ append = true , $ linesToBeCovered = [], array $ linesToBeUsed = [], bool $ ignoreForceCoversAnnotation = false ): void
281278 {
@@ -284,7 +281,7 @@ public function append(RawCodeCoverageData $rawData, $id = null, bool $append =
284281 }
285282
286283 if ($ id === null ) {
287- throw new RuntimeException ;
284+ throw new TestIdMissingException ;
288285 }
289286
290287 $ this ->applyWhitelistFilter ($ rawData );
@@ -434,10 +431,10 @@ public function detectsDeadCode(): bool
434431 *
435432 * @param array|false $linesToBeCovered
436433 *
437- * @throws \SebastianBergmann\CodeCoverage\CoveredCodeNotExecutedException
438- * @throws \ReflectionException
434+ * @throws CoveredCodeNotExecutedException
439435 * @throws MissingCoversAnnotationException
440436 * @throws UnintentionallyCoveredCodeException
437+ * @throws ReflectionException
441438 */
442439 private function applyCoversAnnotationFilter (RawCodeCoverageData $ rawData , $ linesToBeCovered , array $ linesToBeUsed , bool $ ignoreForceCoversAnnotation ): void
443440 {
@@ -507,9 +504,7 @@ private function applyIgnoredLinesFilter(RawCodeCoverageData $data): void
507504 /**
508505 * @throws CoveredCodeNotExecutedException
509506 * @throws MissingCoversAnnotationException
510- * @throws RuntimeException
511507 * @throws UnintentionallyCoveredCodeException
512- * @throws \ReflectionException
513508 */
514509 private function addUncoveredFilesFromWhitelist (): void
515510 {
@@ -631,8 +626,8 @@ private function getLinesToBeIgnoredInner(string $fileName): array
631626 }
632627
633628 /**
634- * @throws \ReflectionException
635629 * @throws UnintentionallyCoveredCodeException
630+ * @throws ReflectionException
636631 */
637632 private function performUnintentionallyCoveredCodeCheck (RawCodeCoverageData $ data , array $ linesToBeCovered , array $ linesToBeUsed ): void
638633 {
@@ -727,7 +722,11 @@ private function getAllowedLines(array $linesToBeCovered, array $linesToBeUsed):
727722 }
728723
729724 /**
730- * @throws RuntimeException
725+ * @throws NoCodeCoverageDriverAvailableException
726+ * @throws PcovNotAvailableException
727+ * @throws PhpdbgNotAvailableException
728+ * @throws XdebugNotAvailableException
729+ * @throws XdebugNotEnabledException
731730 */
732731 private function selectDriver (Filter $ filter ): Driver
733732 {
@@ -745,9 +744,12 @@ private function selectDriver(Filter $filter): Driver
745744 return new XdebugDriver ($ filter );
746745 }
747746
748- throw new RuntimeException ( ' No code coverage driver available ' ) ;
747+ throw new NoCodeCoverageDriverAvailableException ;
749748 }
750749
750+ /**
751+ * @throws ReflectionException
752+ */
751753 private function processUnintentionallyCoveredUnits (array $ unintentionallyCoveredUnits ): array
752754 {
753755 $ unintentionallyCoveredUnits = \array_unique ($ unintentionallyCoveredUnits );
@@ -760,14 +762,22 @@ private function processUnintentionallyCoveredUnits(array $unintentionallyCovere
760762 continue ;
761763 }
762764
763- $ class = new \ReflectionClass ($ unit [0 ]);
765+ try {
766+ $ class = new \ReflectionClass ($ unit [0 ]);
764767
765- foreach ($ this ->unintentionallyCoveredSubclassesWhitelist as $ whitelisted ) {
766- if ($ class ->isSubclassOf ($ whitelisted )) {
767- unset($ unintentionallyCoveredUnits [$ k ]);
768+ foreach ($ this ->unintentionallyCoveredSubclassesWhitelist as $ whitelisted ) {
769+ if ($ class ->isSubclassOf ($ whitelisted )) {
770+ unset($ unintentionallyCoveredUnits [$ k ]);
768771
769- break ;
772+ break ;
773+ }
770774 }
775+ } catch (\ReflectionException $ e ) {
776+ throw new ReflectionException (
777+ $ e ->getMessage (),
778+ (int ) $ e ->getCode (),
779+ $ e
780+ );
771781 }
772782 }
773783
@@ -777,9 +787,7 @@ private function processUnintentionallyCoveredUnits(array $unintentionallyCovere
777787 /**
778788 * @throws CoveredCodeNotExecutedException
779789 * @throws MissingCoversAnnotationException
780- * @throws RuntimeException
781790 * @throws UnintentionallyCoveredCodeException
782- * @throws \ReflectionException
783791 */
784792 private function initializeData (): void
785793 {
0 commit comments