1 | <?php |
||
11 | class GuardCoverageTool |
||
12 | { |
||
13 | const CHECKING_MESSAGE = 'Checking your current coverage'; |
||
14 | /** |
||
15 | * @var OutputInterface |
||
16 | */ |
||
17 | private $output; |
||
18 | /** |
||
19 | * @var StrictCoverageProcessorInterface |
||
20 | */ |
||
21 | private $strictCoverageProcessor; |
||
22 | /** |
||
23 | * @var GuardCoverageFileReaderInterface |
||
24 | */ |
||
25 | private $guardReader; |
||
26 | /** |
||
27 | * @var GuardCoverageFileWriterInterface |
||
28 | */ |
||
29 | private $guardWriter; |
||
30 | /** |
||
31 | * @var float; |
||
32 | */ |
||
33 | private $currentCoverage; |
||
34 | /** |
||
35 | * @var float |
||
36 | */ |
||
37 | private $previousCoverage; |
||
38 | |||
39 | /** |
||
40 | * GuardCoverageTool constructor. |
||
41 | * |
||
42 | * @param OutputInterface $output |
||
43 | * @param StrictCoverageProcessorInterface $strictCoverageProcessor |
||
44 | * @param GuardCoverageFileReaderInterface $guardReader |
||
45 | * @param GuardCoverageFileWriterInterface $guardWriter |
||
46 | */ |
||
47 | 2 | public function __construct( |
|
58 | |||
59 | /** |
||
60 | * @param string $warningMessage |
||
61 | */ |
||
62 | 2 | public function run($warningMessage) |
|
63 | { |
||
64 | 2 | $outputMessage = new PreCommitOutputWriter(self::CHECKING_MESSAGE); |
|
65 | 2 | $this->output->write($outputMessage->getMessage()); |
|
66 | |||
67 | 2 | $this->currentCoverage = $this->strictCoverageProcessor->process(); |
|
68 | 2 | $this->previousCoverage = $this->guardReader->read(); |
|
69 | |||
70 | |||
71 | 2 | true === $this->isLowerCurrentCoverage() ? $this->output->writeln( |
|
72 | 1 | sprintf( |
|
73 | 1 | "\n<bg=yellow;options=bold>%s Previous coverage %s, current coverage %s.</>", |
|
74 | $warningMessage, |
||
75 | 1 | $this->previousCoverage, |
|
76 | 1 | $this->currentCoverage |
|
77 | ) |
||
78 | 1 | ) : $this->output->writeln( |
|
79 | 1 | $outputMessage->getSuccessfulMessage() . $this->printGuardCoverage() |
|
80 | ); |
||
81 | |||
82 | 2 | $this->guardWriter->write($this->currentCoverage); |
|
83 | 2 | } |
|
84 | |||
85 | /** |
||
86 | * @return bool |
||
87 | */ |
||
88 | 2 | private function isLowerCurrentCoverage() |
|
92 | |||
93 | /** |
||
94 | * @return string |
||
95 | */ |
||
96 | 1 | private function printGuardCoverage() |
|
104 | } |
||
105 |