UnintentionallyCoveredCodeException.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /*
  3. * This file is part of the php-code-coverage package.
  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. /**
  12. * Exception that is raised when code is unintentionally covered.
  13. */
  14. final class UnintentionallyCoveredCodeException extends RuntimeException
  15. {
  16. /**
  17. * @var array
  18. */
  19. private $unintentionallyCoveredUnits = [];
  20. public function __construct(array $unintentionallyCoveredUnits)
  21. {
  22. $this->unintentionallyCoveredUnits = $unintentionallyCoveredUnits;
  23. parent::__construct($this->toString());
  24. }
  25. public function getUnintentionallyCoveredUnits(): array
  26. {
  27. return $this->unintentionallyCoveredUnits;
  28. }
  29. private function toString(): string
  30. {
  31. $message = '';
  32. foreach ($this->unintentionallyCoveredUnits as $unit) {
  33. $message .= '- ' . $unit . "\n";
  34. }
  35. return $message;
  36. }
  37. }