Completed
Push — master ( c67234...8b2a99 )
by Pablo
10s
created

StrictCoverageToolExecutor::printCurrentCoverage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace PhpGitHooks\Module\PhpUnit\Service;
4
5
use PhpGitHooks\Module\Configuration\Domain\MinimumStrictCoverage;
6
use PhpGitHooks\Module\Git\Service\PreCommitOutputWriter;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
class StrictCoverageToolExecutor
10
{
11
    const EXECUTE_MESSAGE = 'Checking minimum coverage';
12
    /**
13
     * @var OutputInterface
14
     */
15
    private $output;
16
    /**
17
     * @var StrictCoverageTool
18
     */
19
    private $strictCoverageTool;
20
21
    /**
22
     * StrictCoverageToolExecutor constructor.
23
     * @param OutputInterface $output
24
     * @param StrictCoverageTool $strictCoverageTool
25
     */
26 2
    public function __construct(OutputInterface $output, StrictCoverageTool $strictCoverageTool)
27
    {
28 2
        $this->output = $output;
29 2
        $this->strictCoverageTool = $strictCoverageTool;
30 2
    }
31
32 2
    public function execute(MinimumStrictCoverage $minimumStrictCoverage, $errorMessage)
33
    {
34 2
        $outputMessage = new PreCommitOutputWriter(self::EXECUTE_MESSAGE);
35 2
        $this->output->write($outputMessage->getMessage());
36 2
        $currentCoverage = $this->strictCoverageTool->run($minimumStrictCoverage, $errorMessage);
37 1
        $this->output->writeln($outputMessage->getSuccessfulMessage() . $this->printCurrentCoverage($currentCoverage));
38 1
    }
39
40
    /**
41
     * @param $currentCoverage
42
     * @return string
43
     */
44 1
    private function printCurrentCoverage($currentCoverage)
45
    {
46 1
        return ' <comment>[' . round($currentCoverage, 0) . '%]</comment>';
47
    }
48
}
49