PlatformSpecificExemplifyRunner   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 85
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 1
A isSupported() 4 4 1
A runExemplifyCommand() 7 7 1
A getCommandArguments() 8 8 1
A composeConfigOption() 9 9 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace RMiller\BehatSpec\Extension\PhpSpecExtension\Process\ExemplifyRunner;
4
5
use RMiller\BehatSpec\Extension\PhpSpecExtension\Process\CachingExecutableFinder;
6
use RMiller\BehatSpec\Extension\PhpSpecExtension\Process\CommandRunner;
7
use RMiller\BehatSpec\Extension\PhpSpecExtension\Process\ExemplifyRunner;
8
9 View Code Duplication
class PlatformSpecificExemplifyRunner implements ExemplifyRunner
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 = 'exemplify';
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 runExemplifyCommand($className, $methodName)
59
    {
60
        $this->commandRunner->runCommand(
61
            $this->executableFinder->getExecutablePath(),
62
            $this->getCommandArguments($className, $methodName)
63
        );
64
    }
65
66
    /**
67
     * @param $className
68
     * @param $methodName
69
     *
70
     * @return array
71
     */
72
    private function getCommandArguments($className, $methodName)
73
    {
74
        $commandArguments = [$this->phpspecPath, self::COMMAND_NAME];
75
        $commandArguments = array_merge($commandArguments, $this->composeConfigOption());
76
        array_push($commandArguments, $className, $methodName);
77
78
        return $commandArguments;
79
    }
80
81
    /**
82
     * @return array
83
     */
84
    private function composeConfigOption()
85
    {
86
        $configOption = [];
87
        if (!is_null($this->phpspecConfig)) {
88
            array_push($configOption, '--config', $this->phpspecConfig);
89
        }
90
91
        return $configOption;
92
    }
93
}
94