Skip to content

Commit cae35e4

Browse files
author
Christian Benthake
committed
add shepherd.dev for psalm coverage
1 parent 9f8ca57 commit cae35e4

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

.github/workflows/shepherd.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Run Shepherd
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v2
11+
12+
- name: Install dependencies
13+
run: composer install --prefer-dist --no-progress --no-suggest
14+
15+
- name: Run Psalm
16+
run: composer psalm -- --output-format=github --shepherd

src/ShellBuilder.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use PHPSu\ShellCommandBuilder\Exception\ShellBuilderException;
1515
use TypeError;
1616

17-
final class ShellBuilder implements ShellInterface
17+
final class ShellBuilder implements ShellInterface, \JsonSerializable
1818
{
1919
/** @var array<ShellInterface|CollectionTuple> */
2020
private $commandList = [];
@@ -32,6 +32,16 @@ public static function new(): self
3232
return new ShellBuilder();
3333
}
3434

35+
/**
36+
* This is a shortcut for quicker fluid access to the command api
37+
* @param string $executable
38+
* @return ShellCommand
39+
*/
40+
public static function command(string $executable): ShellCommand
41+
{
42+
return new ShellCommand($executable, new self());
43+
}
44+
3545
public function __construct(int $groupType = GroupType::NO_GROUP)
3646
{
3747
$this->groupType = $groupType;
@@ -213,6 +223,11 @@ private function validateCommand(ShellInterface $command, bool $allowEmpty): voi
213223
}
214224
}
215225

226+
public function jsonSerialize(): array
227+
{
228+
return $this->__toArray();
229+
}
230+
216231
/**
217232
* @return array<mixed>
218233
*/

tests/ShellBuilderTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,4 +579,13 @@ public function testCommandDebugWithPipeAndCondition(): void
579579
$this->assertEquals('&&', $debug[1][0]);
580580
$this->assertEquals('|', $debug[2][0]);
581581
}
582+
583+
public function testJsonSerializeShellBuilder(): void
584+
{
585+
// command example from documentation
586+
$echo = ShellBuilder::command('echo')->addArgument('hello world');
587+
$grep = ShellBuilder::command('echo')->addShortOption('e', 'world');
588+
$builder = ShellBuilder::new()->add($echo)->pipe($grep);
589+
$this->assertJson(json_encode($builder));
590+
}
582591
}

0 commit comments

Comments
 (0)