Completed
Push — master ( f87faf...b3e46e )
by Pablo
03:15
created

UnitTestPreCommitExecutor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 84.21%

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 5
c 4
b 0
f 1
lcom 1
cbo 4
dl 0
loc 54
ccs 16
cts 19
cp 0.8421
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A run() 0 15 3
A commandName() 0 4 1
1
<?php
2
3
namespace PhpGitHooks\Application\PhpUnit;
4
5
use PhpGitHooks\Application\Config\HookConfigExtraToolInterface;
6
use PhpGitHooks\Application\Config\HookConfigInterface;
7
use PhpGitHooks\Infrastructure\Common\PreCommitExecutor;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class UnitTestPreCommitExecutor extends PreCommitExecutor
11
{
12
    const TOOL = 'phpunit';
13
    const ENABLED_KEY = 'enabled';
14
    const RANDOM_MODE_KEY = 'random-mode';
15
    /** @var PhpUnitHandler */
16
    private $phpunitHandler;
17
    /** @var PhpUnitRandomizerHandler */
18
    private $phpUnitRandomizerHandler;
19
20
    /**
21
     * @param HookConfigInterface      $hookConfigInterface
22
     * @param PhpUnitHandler           $phpUnitHandler
23
     * @param PhpUnitRandomizerHandler $phpUnitRandomizerHandler
24
     */
25 3
    public function __construct(
26
        HookConfigInterface $hookConfigInterface,
27
        PhpUnitHandler $phpUnitHandler,
28
        PhpUnitRandomizerHandler $phpUnitRandomizerHandler
29
    ) {
30 3
        $this->preCommitConfig = $hookConfigInterface;
31 3
        $this->phpunitHandler = $phpUnitHandler;
32 3
        $this->phpUnitRandomizerHandler = $phpUnitRandomizerHandler;
33 3
    }
34
35
    /**
36
     * @param OutputInterface $outputInterface
37
     *
38
     * @throws UnitTestsException
39
     */
40 3
    public function run(OutputInterface $outputInterface)
41
    {
42
        /** @var HookConfigExtraToolInterface $data */
43 3
        $data = $this->preCommitConfig;
44 3
        $extraOptions = $data->extraOptions(PhpUnitConfigData::TOOL);
45 3
        if (true === $extraOptions[self::ENABLED_KEY]) {
46 2
            if (true === $extraOptions[self::RANDOM_MODE_KEY]) {
47 1
                $this->phpUnitRandomizerHandler->setOutput($outputInterface);
48 1
                $this->phpUnitRandomizerHandler->run($this->getMessages());
49
            } else {
50 2
                $this->phpunitHandler->setOutput($outputInterface);
51 2
                $this->phpunitHandler->run($this->getMessages());
52
            }
53 1
        }
54 2
    }
55
56
    /**
57
     * @return string
58
     */
59
    protected function commandName()
60
    {
61
        return self::TOOL;
62
    }
63
}
64