Passed
Push — master ( 7c2abd...e1c388 )
by
unknown
03:51 queued 14s
created

Redirection::redirectInput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 2
c 1
b 0
f 1
dl 0
loc 4
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\RedirectOperator;
8
use PHPSu\ShellCommandBuilder\Exception\ShellBuilderException;
9
use PHPSu\ShellCommandBuilder\ShellInterface;
10
11
final class Redirection extends AbstractCollection
12
{
13
    /**
14
     * @param string|ShellInterface $value
15
     * @param bool $append
16
     * @return $this
17
     * @throws ShellBuilderException
18
     */
19
    public function redirectOutput($value, bool $append): self
20
    {
21
        $this->tuple = CollectionTuple::create($value, $append ? RedirectOperator::STDOUT_LEFT_APPEND : RedirectOperator::STDOUT_LEFT_INSERT);
22
        return $this;
23
    }
24
25
    /**
26
     * @param string|ShellInterface $value
27
     * @return $this
28
     * @throws ShellBuilderException
29
     */
30
    public function redirectInput($value): self
31
    {
32
        $this->tuple = CollectionTuple::create($value, RedirectOperator::STDIN_RIGHT);
33
        return $this;
34
    }
35
36
    /**
37
     * @param string|ShellInterface $value
38
     * @return $this
39
     * @throws ShellBuilderException
40
     */
41
    public function redirectError($value): self
42
    {
43
        $this->tuple = CollectionTuple::create($value, RedirectOperator::FILE_DESCRIPTOR_ERR . RedirectOperator::STDOUT_LEFT_INSERT);
44
        return $this;
45
    }
46
47
    /**
48
     * @param string|ShellInterface $value
49
     * @param bool $toLeft
50
     * @return $this
51
     * @throws ShellBuilderException
52
     */
53
    public function redirectBetweenFiles($value, bool $toLeft): self
54
    {
55
        $this->tuple = CollectionTuple::create($value, $toLeft ? RedirectOperator::REDIRECT_LEFT : RedirectOperator::REDIRECT_RIGHT);
56
        return $this;
57
    }
58
59
    public function redirectErrorToOutput(): self
60
    {
61
        $this->tuple = CollectionTuple::create('', RedirectOperator::ERR_TO_OUT_REDIRECT);
62
        return $this;
63
    }
64
}
65