Completed
Pull Request — master (#76)
by Jan Philipp
01:42
created

CommandBuilder   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 129
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A finishLast() 0 19 2
A setExecutable() 0 7 1
A addTemplateCommand() 0 10 1
A setIgnoreError() 0 6 1
A setTty() 0 6 1
A setCommands() 0 6 1
A getAll() 0 7 1
1
<?php declare(strict_types=1);
2
3
4
namespace Shopware\Psh\ScriptRuntime;
5
6
/**
7
 * Again, a statefull builder to ease the parsing
8
 */
9
class CommandBuilder
10
{
11
    /**
12
     * @var ProcessCommand[]
13
     */
14
    private $allCommands = [];
15
16
    /**
17
     * @var string
18
     */
19
    private $currentShellCommand;
20
21
    /**
22
     * @var int
23
     */
24
    private $startLine;
25
26
    /**
27
     * @var bool
28
     */
29
    private $ignoreError;
30
31
    /**
32
     * @var bool
33
     */
34
    private $tty;
35
36
    /**
37
     * @var bool
38
     */
39
    private $template;
40
41
    public function __construct()
42
    {
43
        $this->finishLast();
44
    }
45
46
47
    public function finishLast(): CommandBuilder
48
    {
49
        if ($this->currentShellCommand) {
50
            $this->allCommands[] = new ProcessCommand(
51
                $this->currentShellCommand,
52
                $this->startLine,
53
                $this->ignoreError,
54
                $this->tty
55
            );
56
        }
57
58
        $this->currentShellCommand = null;
59
        $this->startLine = null;
60
        $this->ignoreError = false;
61
        $this->tty = false;
62
        $this->template = false;
63
64
        return $this;
65
    }
66
67
    /**
68
     * @param string $shellCommand
69
     * @param int $startLine
70
     * @param bool $ignoreError
0 ignored issues
show
Bug introduced by
There is no parameter named $ignoreError. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
71
     * @return CommandBuilder
72
     */
73
    public function setExecutable(string $shellCommand, int $startLine): CommandBuilder
74
    {
75
        $this->currentShellCommand = $shellCommand;
76
        $this->startLine = $startLine;
77
78
        return $this;
79
    }
80
81
    /**
82
     * @param string $source
83
     * @param string $destination
84
     * @param int $lineNumber
85
     * @return CommandBuilder
86
     */
87
    public function addTemplateCommand(string $source, string $destination, int $lineNumber): CommandBuilder
88
    {
89
        $this->allCommands[] = new TemplateCommand(
90
            $source,
91
            $destination,
92
            $lineNumber
93
        );
94
95
        return $this;
96
    }
97
98
    /**
99
     * @param bool $set
100
     * @return CommandBuilder
101
     */
102
    public function setIgnoreError(bool $set = true): CommandBuilder
103
    {
104
        $this->ignoreError = $set;
105
106
        return $this;
107
    }
108
109
    public function setTty(bool $set = true): CommandBuilder
110
    {
111
        $this->tty = $set;
112
113
        return $this;
114
    }
115
116
    /**
117
     * @param array $commands
118
     * @return CommandBuilder
119
     */
120
    public function setCommands(array $commands): CommandBuilder
121
    {
122
        $this->allCommands = $commands;
123
124
        return $this;
125
    }
126
127
    /**
128
     * @return ProcessCommand[]
129
     */
130
    public function getAll(): array
131
    {
132
        $allCommands = $this->allCommands;
133
        $this->allCommands = [];
134
135
        return $allCommands;
136
    }
137
}
138