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 11namespace SebastianBergmann\CodeCoverage; 12 13/** 14 * Exception that is raised when code is unintentionally covered. 15 */ 16class UnintentionallyCoveredCodeException extends RuntimeException 17{ 18 /** 19 * @var array 20 */ 21 private $unintentionallyCoveredUnits = []; 22 23 /** 24 * @param array $unintentionallyCoveredUnits 25 */ 26 public function __construct(array $unintentionallyCoveredUnits) 27 { 28 $this->unintentionallyCoveredUnits = $unintentionallyCoveredUnits; 29 30 parent::__construct($this->toString()); 31 } 32 33 /** 34 * @return array 35 */ 36 public function getUnintentionallyCoveredUnits() 37 { 38 return $this->unintentionallyCoveredUnits; 39 } 40 41 /** 42 * @return string 43 */ 44 private function toString() 45 { 46 $message = ''; 47 48 foreach ($this->unintentionallyCoveredUnits as $unit) { 49 $message .= '- ' . $unit . "\n"; 50 } 51 52 return $message; 53 } 54} 55