Completed
Push — master ( 5f4179...916f6e )
by Richard
11s
created

PlatformSpecificRunRunner   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 82
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A isSupported() 0 4 1
A runRunCommand() 0 7 1
A getCommandArguments() 0 7 1
A composeConfigOption() 0 9 2
1
<?php
2
3
namespace RMiller\BehatSpec\Extension\PhpSpecRunExtension\Process\RunRunner;
4
5
use RMiller\BehatSpec\Extension\PhpSpecRunExtension\Process\CachingExecutableFinder;
6
use RMiller\BehatSpec\Extension\PhpSpecRunExtension\Process\CommandRunner;
7
use RMiller\BehatSpec\Extension\PhpSpecRunExtension\Process\RunRunner;
8
9
class PlatformSpecificRunRunner implements RunRunner
10
{
11
    const COMMAND_NAME = 'run';
12
13
    /**
14
     * @var string
15
     */
16
    private $phpspecPath;
17
18
    /**
19
     * @var string
20
     */
21
    private $phpspecConfig;
22
23
    /**
24
     * @var CommandRunner
25
     */
26
    private $commandRunner;
27
28
    /**
29
     * @var CachingExecutableFinder
30
     */
31
    private $executableFinder;
32
33
    /**
34
     * @param CommandRunner $commandRunner
35
     * @param CachingExecutableFinder $executableFinder
36
     * @param string $phpspecPath
37
     * @param string $phpspecConfig
38
     */
39
    public function __construct(
40
        CommandRunner $commandRunner,
41
        CachingExecutableFinder $executableFinder,
42
        $phpspecPath,
43
        $phpspecConfig
44
    ) {
45
        $this->commandRunner = $commandRunner;
46
        $this->executableFinder = $executableFinder;
47
        $this->phpspecPath = $phpspecPath;
48
        $this->phpspecConfig = $phpspecConfig;
49
    }
50
51
    /**
52
     * @return boolean
53
     */
54
    public function isSupported()
55
    {
56
        return $this->commandRunner->isSupported();
57
    }
58
59
    public function runRunCommand()
60
    {
61
        $this->commandRunner->runCommand(
62
            $this->executableFinder->getExecutablePath(),
63
            $this->getCommandArguments()
64
        );
65
    }
66
67
    /**
68
     * @return array
69
     */
70
    private function getCommandArguments()
71
    {
72
        $commandArguments = [$this->phpspecPath, self::COMMAND_NAME];
73
        $commandArguments = array_merge($commandArguments, $this->composeConfigOption());
74
75
        return $commandArguments;
76
    }
77
78
    /**
79
     * @return array
80
     */
81
    private function composeConfigOption()
82
    {
83
        $configOption = [];
84
        if (!is_null($this->phpspecConfig)) {
85
            array_push($configOption, '--config', $this->phpspecConfig);
86
        }
87
88
        return $configOption;
89
    }
90
}
91