1 | <?php declare(strict_types=1); |
||
5 | final class GitCommand |
||
6 | { |
||
7 | /** |
||
8 | * Path to the directory containing the working copy. If this variable is |
||
9 | * set, then the process will change into this directory while the Git |
||
10 | * command is being run. |
||
11 | * |
||
12 | * @var string|null |
||
13 | */ |
||
14 | private $directory; |
||
15 | |||
16 | /** |
||
17 | * The command being run, e.g. "clone", "commit", etc. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | private $command = ''; |
||
22 | |||
23 | /** |
||
24 | * Whether command execution should be bypassed. |
||
25 | * |
||
26 | * @var bool |
||
27 | */ |
||
28 | private $bypass = false; |
||
29 | |||
30 | /** |
||
31 | * Whether to execute the raw command without escaping it. This is useful |
||
32 | * for executing arbitrary commands, e.g. "status -s". If this is true, |
||
33 | * any options and arguments are ignored. |
||
34 | * |
||
35 | * @var bool |
||
36 | */ |
||
37 | private $executeRaw = false; |
||
38 | |||
39 | /** |
||
40 | * @var mixed[] |
||
41 | */ |
||
42 | private $options = []; |
||
43 | |||
44 | /** |
||
45 | * @var mixed[] |
||
46 | */ |
||
47 | private $args = []; |
||
48 | |||
49 | /** |
||
50 | * @param mixed ...$argsAndOptions |
||
51 | */ |
||
52 | public function __construct(string $command = '', ...$argsAndOptions) |
||
66 | |||
67 | /** |
||
68 | * Returns Git command being run, e.g. "clone", "commit", etc. |
||
69 | */ |
||
70 | public function getCommand(): string |
||
74 | |||
75 | public function setDirectory(?string $directory): void |
||
79 | |||
80 | public function getDirectory(): ?string |
||
84 | |||
85 | /** |
||
86 | * A bool flagging whether to skip running the command. |
||
87 | */ |
||
88 | public function bypass(bool $bypass = true): void |
||
92 | |||
93 | /** |
||
94 | * Set whether to execute the command as-is without escaping it. |
||
95 | */ |
||
96 | public function executeRaw(bool $executeRaw = true): void |
||
100 | |||
101 | /** |
||
102 | * Returns true if the Git command should be run. |
||
103 | */ |
||
104 | public function notBypassed(): bool |
||
108 | |||
109 | /** |
||
110 | * Builds the command line options for use in the Git command. |
||
111 | * |
||
112 | * @return mixed[] |
||
113 | */ |
||
114 | public function buildOptions(): array |
||
127 | |||
128 | /** |
||
129 | * @param mixed[]|string|true $value The option's value, pass true if the options is a flag. |
||
130 | */ |
||
131 | public function setOption(string $option, $value): void |
||
135 | |||
136 | /** |
||
137 | * @param mixed[] $options |
||
138 | */ |
||
139 | public function setOptions(array $options): void |
||
145 | |||
146 | public function setFlag(string $option): void |
||
150 | |||
151 | /** |
||
152 | * @param mixed $default |
||
153 | * @return mixed |
||
154 | */ |
||
155 | public function getOption(string $option, $default = null) |
||
159 | |||
160 | public function unsetOption(string $option): void |
||
164 | |||
165 | public function addArgument(string $arg): void |
||
169 | |||
170 | /** |
||
171 | * Renders the arguments and options for the Git command. |
||
172 | * |
||
173 | * @return string|mixed[] |
||
174 | */ |
||
175 | public function getCommandLine() |
||
185 | |||
186 | /** |
||
187 | * Render the option. |
||
188 | * |
||
189 | * @param string[] $options |
||
190 | * @param string $option |
||
191 | * @param mixed $value |
||
192 | * @return string[] |
||
193 | */ |
||
194 | private function renderOption(array $options, string $option, $value): array |
||
207 | } |
||
208 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: