|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Code Coverage Text Report |
| 4 | + * |
| 5 | + * @copyright 2013 Anthon Pang |
| 6 | + * @license BSD-3-Clause |
| 7 | + */ |
| 8 | + |
| 9 | +namespace VIPSoft\CodeCoverageCommon\Report; |
| 10 | + |
| 11 | +use VIPSoft\CodeCoverageCommon\ReportInterface; |
| 12 | + |
| 13 | +/** |
| 14 | + * Text report |
| 15 | + * |
| 16 | + * @author Anthon Pang <apang@softwaredevelopment.ca> |
| 17 | + */ |
| 18 | +class Text implements ReportInterface |
| 19 | +{ |
| 20 | + /** |
| 21 | + * @var \PHP_CodeCoverage_Report_Text |
| 22 | + */ |
| 23 | + private $report; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var array |
| 27 | + */ |
| 28 | + private $options; |
| 29 | + |
| 30 | + /** |
| 31 | + * {@inheritdoc} |
| 32 | + */ |
| 33 | + public function __construct(array $options) |
| 34 | + { |
| 35 | + if ( ! isset($options['showColors'])) { |
| 36 | + $options['showColors'] = false; |
| 37 | + } |
| 38 | + |
| 39 | + if ( ! isset($options['printer'])) { |
| 40 | + $options['printer'] = null; |
| 41 | + } |
| 42 | + |
| 43 | + if ( ! isset($options['lowUpperBound'])) { |
| 44 | + $options['lowUpperBound'] = 35; |
| 45 | + } |
| 46 | + |
| 47 | + if ( ! isset($options['highUpperBound'])) { |
| 48 | + $options['highUpperBound'] = 70; |
| 49 | + } |
| 50 | + |
| 51 | + if ( ! isset($options['showUncoveredFiles'])) { |
| 52 | + $options['showUncoveredFiles'] = false; |
| 53 | + } |
| 54 | + |
| 55 | + if ($this->getVersion() === '1.2') { |
| 56 | + $outputStream = new \PHPUnit_Util_Printer($options['printer']); |
| 57 | + |
| 58 | + $this->report = new \PHP_CodeCoverage_Report_Text( |
| 59 | + $outputStream, |
| 60 | + $options['lowUpperBound'], |
| 61 | + $options['highUpperBound'], |
| 62 | + $options['showUncoveredFiles'] |
| 63 | + ); |
| 64 | + } else { |
| 65 | + if ( ! isset($options['showOnlySummary'])) { |
| 66 | + $options['showOnlySummary'] = false; |
| 67 | + } |
| 68 | + |
| 69 | + $this->report = new \PHP_CodeCoverage_Report_Text( |
| 70 | + $options['lowUpperBound'], |
| 71 | + $options['highUpperBound'], |
| 72 | + $options['showUncoveredFiles'], |
| 73 | + $options['showOnlySummary'] |
| 74 | + ); |
| 75 | + } |
| 76 | + |
| 77 | + $this->options = $options; |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * {@inheritdoc} |
| 82 | + */ |
| 83 | + public function process(\PHP_CodeCoverage $coverage) |
| 84 | + { |
| 85 | + return $this->report( |
| 86 | + $coverage, |
| 87 | + $options['showColors'] |
| 88 | + ); |
| 89 | + } |
| 90 | + |
| 91 | + private function getVersion() |
| 92 | + { |
| 93 | + $reflectionMethod = new \ReflectionMethod('PHP_CodeCoverage_Report_Text', '__construct'); |
| 94 | + $parameters = $reflectionMethod->getParameters(); |
| 95 | + |
| 96 | + if (reset($parameters)->name === 'outputStream') { |
| 97 | + return '1.2'; |
| 98 | + } |
| 99 | + |
| 100 | + return '1.3'; |
| 101 | + } |
| 102 | +} |
0 commit comments