Completed
Pull Request — master (#546)
by Greg
03:06
created

ProcessExecutor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 26.83 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 2
cbo 5
dl 11
loc 41
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 11 11 1
A getCommandDescription() 0 4 1
A run() 0 4 1

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 Robo\Common;
4
5
use Psr\Log\LoggerAwareInterface;
6
use Robo\Contract\ConfigAwareInterface;
7
use Robo\Contract\OutputAwareInterface;
8
use Robo\Contract\VerbosityThresholdInterface;
9
use Symfony\Component\Process\Process;
10
11
class ProcessExecutor implements ConfigAwareInterface, LoggerAwareInterface, OutputAwareInterface, VerbosityThresholdInterface
12
{
13
    use ExecTrait;
14
    use TaskIO; // uses LoggerAwareTrait and ConfigAwareTrait
15
    use ProgressIndicatorAwareTrait;
16
    use OutputAwareTrait;
17
18
    /**
19
     * @param Process $process
20
     * @return type
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
21
     */
22
    public function __construct(Process $process)
23
    {
24
        $this->process = $process;
25
    }
26
27 View Code Duplication
    public static function create($container)
0 ignored issues
show
Duplication introduced by
This method 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...
28
    {
29
        $processExecutor = new self($commandFile);
0 ignored issues
show
Bug introduced by
The variable $commandFile does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
30
31
        $processExecutor->setLogger($container->get('logger'));
32
        $processExecutor->setProgressIndicator($container->get('progressIndicator'));
33
        $processExecutor->setConfig($container->get('config'));
34
        $processExecutor->setOutputAdapter($container->get('outputAdapter'));
35
36
        return $processExecutor;
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    protected function getCommandDescription()
43
    {
44
        return $this->process->getCommandLine();
45
    }
46
47
    public function run()
48
    {
49
        return $this->execute($this->process);
50
    }
51
}
52