ShellList::addAnd()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PHPSu\ShellCommandBuilder\Collection;
6
7
use PHPSu\ShellCommandBuilder\Definition\ControlOperator;
8
use PHPSu\ShellCommandBuilder\Exception\ShellBuilderException;
9
use PHPSu\ShellCommandBuilder\ShellInterface;
10
11
/**
12
 * @internal
13
 * @psalm-internal PHPSu\ShellCommandBuilder
14
 */
15
final class ShellList extends AbstractCollection
16
{
17
    /**
18
     * Returns something like: || echo "hello world"
19
     *
20
     * @param string|ShellInterface $command
21
     * @return $this
22
     * @throws ShellBuilderException
23
     */
24
    public static function addOr($command): self
25
    {
26
        $list = new self();
27
        $list->tuple = $list->toTuple($command, ControlOperator::OR_OPERATOR);
28
        return $list;
29
    }
30
31
    /**
32
     * Returns something like: && echo "hello world"
33
     *
34
     * @param string|ShellInterface $command
35
     * @return $this
36
     * @throws ShellBuilderException
37
     */
38
    public static function addAnd($command): self
39
    {
40
        $list = new self();
41
        $list->tuple = $list->toTuple($command, ControlOperator::AND_OPERATOR);
42
        return $list;
43
    }
44
45
    /**
46
     * Returns something like: ; echo "hello world"
47
     *
48
     * @param string|ShellInterface $command
49
     * @return $this
50
     * @throws ShellBuilderException
51
     */
52
    public static function add($command): self
53
    {
54
        $list = new self();
55
        $list->tuple = $list->toTuple($command, ControlOperator::COMMAND_DELIMITER);
56
        return $list;
57
    }
58
59
    /**
60
     * Returns something like: & echo "hello world"
61
     *
62
     * @param string|ShellInterface $command
63
     * @return static
64
     * @throws ShellBuilderException
65
     */
66
    public static function async($command): self
67
    {
68
        $list = new self();
69
        $list->tuple = $list->toTuple($command, ControlOperator::BASH_AMPERSAND);
70
        return $list;
71
    }
72
}
73