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

StrictCoverageToolExecutor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 1
cbo 3
dl 0
loc 40
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A execute() 0 7 1
A printCurrentCoverage() 0 4 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