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

PlatformSpecificDescRunner::composeConfigOption()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
namespace RMiller\BehatSpec\Extension\PhpSpecExtension\Process\DescRunner;
4
5
use RMiller\BehatSpec\Extension\PhpSpecExtension\Process\CachingExecutableFinder;
6
use RMiller\BehatSpec\Extension\PhpSpecExtension\Process\CommandRunner;
7
use RMiller\BehatSpec\Extension\PhpSpecExtension\Process\DescRunner;
8
9 View Code Duplication
class PlatformSpecificDescRunner implements DescRunner
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    const COMMAND_NAME = 'desc';
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
     */
38
    public function __construct(
39
        CommandRunner $commandRunner,
40
        CachingExecutableFinder $executableFinder,
41
        $phpspecPath,
42
        $phpspecConfig
43
    ) {
44
        $this->commandRunner = $commandRunner;
45
        $this->executableFinder = $executableFinder;
46
        $this->phpspecPath = $phpspecPath;
47
        $this->phpspecConfig = $phpspecConfig;
48
    }
49
50
    /**
51
     * @return boolean
52
     */
53
    public function isSupported()
54
    {
55
        return $this->commandRunner->isSupported();
56
    }
57
58
    public function runDescCommand($className)
59
    {
60
        $this->commandRunner->runCommand(
61
            $this->executableFinder->getExecutablePath(),
62
            $this->getCommandArguments($className)
63
        );
64
    }
65
66
    /**
67
     * @param $className
68
     *
69
     * @return array
70
     */
71
    private function getCommandArguments($className)
72
    {
73
        $commandArguments = [$this->phpspecPath, self::COMMAND_NAME];
74
        $commandArguments = array_merge($commandArguments, $this->composeConfigOption());
75
        array_push($commandArguments, $className);
76
77
        return $commandArguments;
78
    }
79
80
    /**
81
     * @return array
82
     */
83
    private function composeConfigOption()
84
    {
85
        $configOption = [];
86
        if (!is_null($this->phpspecConfig)) {
87
            array_push($configOption, '--config', $this->phpspecConfig);
88
        }
89
90
        return $configOption;
91
    }
92
}
93