|
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
|
|
|
private function reset() |
|
42
|
|
|
{ |
|
43
|
|
|
if ($this->currentShellCommand) { |
|
44
|
|
|
$this->allCommands[] = new ProcessCommand( |
|
45
|
|
|
$this->currentShellCommand, |
|
46
|
|
|
$this->startLine, |
|
47
|
|
|
$this->ignoreError, |
|
48
|
|
|
$this->tty, |
|
49
|
|
|
$this->template |
|
|
|
|
|
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$this->currentShellCommand = null; |
|
54
|
|
|
$this->startLine = null; |
|
55
|
|
|
$this->ignoreError = false; |
|
56
|
|
|
$this->tty = false; |
|
57
|
|
|
$this->template = false; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param string $shellCommand |
|
62
|
|
|
* @param int $startLine |
|
63
|
|
|
* @param bool $ignoreError |
|
64
|
|
|
* @return CommandBuilder |
|
65
|
|
|
*/ |
|
66
|
|
|
public function next(string $shellCommand, int $startLine, bool $ignoreError, bool $tty): CommandBuilder |
|
67
|
|
|
{ |
|
68
|
|
|
$this->reset(); |
|
69
|
|
|
|
|
70
|
|
|
$this->currentShellCommand = $shellCommand; |
|
71
|
|
|
$this->startLine = $startLine; |
|
72
|
|
|
$this->ignoreError = $ignoreError; |
|
73
|
|
|
$this->tty = $tty; |
|
74
|
|
|
|
|
75
|
|
|
return $this; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
public function addTemplateCommand(string $source, string $destination, int $lineNumber) |
|
80
|
|
|
{ |
|
81
|
|
|
$this->reset(); |
|
82
|
|
|
|
|
83
|
|
|
$this->allCommands[] = new TemplateCommand( |
|
84
|
|
|
$source, |
|
85
|
|
|
$destination, |
|
86
|
|
|
$lineNumber |
|
87
|
|
|
); |
|
88
|
|
|
|
|
89
|
|
|
return $this; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param bool $set |
|
94
|
|
|
* @return CommandBuilder |
|
95
|
|
|
*/ |
|
96
|
|
|
public function setIgnoreError(bool $set = true): CommandBuilder |
|
97
|
|
|
{ |
|
98
|
|
|
$this->ignoreError = $set; |
|
99
|
|
|
|
|
100
|
|
|
return $this; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @param string $shellCommand |
|
105
|
|
|
* @return CommandBuilder |
|
106
|
|
|
*/ |
|
107
|
|
|
public function add(string $shellCommand): CommandBuilder |
|
108
|
|
|
{ |
|
109
|
|
|
$this->currentShellCommand .= ' ' . trim($shellCommand); |
|
110
|
|
|
|
|
111
|
|
|
return $this; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param array $commands |
|
116
|
|
|
* @return CommandBuilder |
|
117
|
|
|
*/ |
|
118
|
|
|
public function setCommands(array $commands): CommandBuilder |
|
119
|
|
|
{ |
|
120
|
|
|
$this->allCommands = $commands; |
|
121
|
|
|
|
|
122
|
|
|
return $this; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @return ProcessCommand[] |
|
127
|
|
|
*/ |
|
128
|
|
|
public function getAll(): array |
|
129
|
|
|
{ |
|
130
|
|
|
$this->reset(); |
|
131
|
|
|
$allCommands = $this->allCommands; |
|
132
|
|
|
$this->allCommands = []; |
|
133
|
|
|
|
|
134
|
|
|
return $allCommands; |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.