UnintentionallyCoveredCodeException.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php declare(strict_types=1);
  2. /*
  3. * This file is part of phpunit/php-code-coverage.
  4. *
  5. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace SebastianBergmann\CodeCoverage;
  11. use RuntimeException;
  12. final class UnintentionallyCoveredCodeException extends RuntimeException implements Exception
  13. {
  14. /**
  15. * @var list<string>
  16. */
  17. private readonly array $unintentionallyCoveredUnits;
  18. /**
  19. * @param list<string> $unintentionallyCoveredUnits
  20. */
  21. public function __construct(array $unintentionallyCoveredUnits)
  22. {
  23. $this->unintentionallyCoveredUnits = $unintentionallyCoveredUnits;
  24. parent::__construct($this->toString());
  25. }
  26. /**
  27. * @return list<string>
  28. */
  29. public function getUnintentionallyCoveredUnits(): array
  30. {
  31. return $this->unintentionallyCoveredUnits;
  32. }
  33. private function toString(): string
  34. {
  35. $message = '';
  36. foreach ($this->unintentionallyCoveredUnits as $unit) {
  37. $message .= '- ' . $unit . "\n";
  38. }
  39. return $message;
  40. }
  41. }