Skip to content

Commit 8d139be

Browse files
committed
Fix coding style and docs
1 parent 3488d78 commit 8d139be

File tree

1 file changed

+40
-24
lines changed

1 file changed

+40
-24
lines changed

src/Command.php

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@
66
*
77
* This class represents a shell command.
88
*
9+
* Its meant for exuting a single command and capturing stdout and stderr.
10+
*
11+
* Example:
12+
*
13+
* ```
14+
* $command = new Command('/usr/local/bin/mycommand -a -b');
15+
* $command->addArg('--name=', "d'Artagnan");
16+
* if ($command->execute()) {
17+
* echo $command->getOutput();
18+
* } else {
19+
* echo $command->getError();
20+
* $exitCode = $command->getExitCode();
21+
* }
22+
* ```
23+
*
924
* @author Michael Härtl <[email protected]>
1025
* @license http://www.opensource.org/licenses/MIT
1126
*/
@@ -136,11 +151,11 @@ public function __construct($options = null)
136151
}
137152

138153
/**
139-
* @param array $options array of name => value options that should be
140-
* applied to the object You can also pass options that use a setter, e.g.
141-
* you can pass a `fileName` option which will be passed to
142-
* `setFileName()`.
143-
* @throws \Exception
154+
* @param array $options array of name => value options (i.e. public
155+
* properties) that should be applied to this object. You can also pass
156+
* options that use a setter, e.g. you can pass a `fileName` option which
157+
* will be passed to `setFileName()`.
158+
* @throws \Exception on unknown option keys
144159
* @return static for method chaining
145160
*/
146161
public function setOptions($options)
@@ -163,8 +178,8 @@ public function setOptions($options)
163178
/**
164179
* @param string $command the command or full command string to execute,
165180
* like 'gzip' or 'gzip -d'. You can still call addArg() to add more
166-
* arguments to the command. If $escapeCommand was set to true, the command
167-
* gets escaped with escapeshellcmd().
181+
* arguments to the command. If `$escapeCommand` was set to true, the command
182+
* gets escaped with `escapeshellcmd()`.
168183
* @return static for method chaining
169184
*/
170185
public function setCommand($command)
@@ -175,11 +190,11 @@ public function setCommand($command)
175190
if ($this->getIsWindows()) {
176191
// Make sure to switch to correct drive like "E:" first if we have
177192
// a full path in command
178-
if (isset($command[1]) && $command[1]===':') {
193+
if (isset($command[1]) && $command[1] === ':') {
179194
$position = 1;
180195
// Could be a quoted absolute path because of spaces.
181196
// i.e. "C:\Program Files (x86)\file.exe"
182-
} elseif (isset($command[2]) && $command[2]===':') {
197+
} elseif (isset($command[2]) && $command[2] === ':') {
183198
$position = 2;
184199
} else {
185200
$position = false;
@@ -212,7 +227,7 @@ public function setStdIn($stdIn) {
212227
}
213228

214229
/**
215-
* @return string|null the command that was set through setCommand() or
230+
* @return string|null the command that was set through `setCommand()` or
216231
* passed to the constructor. `null` if none.
217232
*/
218233
public function getCommand()
@@ -222,7 +237,7 @@ public function getCommand()
222237

223238
/**
224239
* @return string|bool the full command string to execute. If no command
225-
* was set with setCommand() or passed to the constructor it will return
240+
* was set with `setCommand()` or passed to the constructor it will return
226241
* `false`.
227242
*/
228243
public function getExecCommand()
@@ -238,8 +253,9 @@ public function getExecCommand()
238253
}
239254

240255
/**
241-
* @param string $args the command arguments as string. Note that these
242-
* will not get escaped!
256+
* @param string $args the command arguments as string like `'--arg1=value1
257+
* --arg2=value2'`. Note that this string will not get escaped. This will
258+
* overwrite the args added with `addArgs()`.
243259
* @return static for method chaining
244260
*/
245261
public function setArgs($args)
@@ -249,8 +265,8 @@ public function setArgs($args)
249265
}
250266

251267
/**
252-
* @return string the command args that where set with setArgs() or added
253-
* with addArg() separated by spaces
268+
* @return string the command args that where set with `setArgs()` or added
269+
* with `addArg()` separated by spaces.
254270
*/
255271
public function getArgs()
256272
{
@@ -259,16 +275,16 @@ public function getArgs()
259275

260276
/**
261277
* @param string $key the argument key to add e.g. `--feature` or
262-
* `--name=`. If the key does not end with and `=`, the $value will be
263-
* separated by a space, if any. Keys are not escaped unless $value is null
264-
* and $escape is `true`.
278+
* `--name=`. If the key does not end with `=`, the (optional) $value will
279+
* be separated by a space.
265280
* @param string|array|null $value the optional argument value which will
266281
* get escaped if $escapeArgs is true. An array can be passed to add more
267-
* than one value for a key, e.g. `addArg('--exclude',
268-
* array('val1','val2'))` which will create the option `'--exclude' 'val1'
269-
* 'val2'`.
270-
* @param bool|null $escape if set, this overrides the $escapeArgs setting
271-
* and enforces escaping/no escaping
282+
* than one value for a key, e.g.
283+
* `addArg('--exclude', array('val1','val2'))`
284+
* which will create the option
285+
* `'--exclude' 'val1' 'val2'`.
286+
* @param bool|null $escape if set, this overrides the `$escapeArgs` setting
287+
* and enforces escaping/no escaping of keys and values
272288
* @return static for method chaining
273289
*/
274290
public function addArg($key, $value = null, $escape = null)
@@ -358,7 +374,7 @@ public function getExecuted()
358374
* Execute the command
359375
*
360376
* @return bool whether execution was successful. If `false`, error details
361-
* can be obtained from getError(), getStdErr() and getExitCode().
377+
* can be obtained from `getError()`, `getStdErr()` and `getExitCode()`.
362378
*/
363379
public function execute()
364380
{

0 commit comments

Comments
 (0)