Passed
Pull Request — master (#7)
by
unknown
02:04
created

StringExpression::lenghtZero()   A

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\Conditional;
6
7
use PHPSu\ShellCommandBuilder\Definition\ConditionalOperator;
8
use PHPSu\ShellCommandBuilder\ShellInterface;
9
10
final class StringExpression extends BasicExpression
11
{
12
    protected $escapedValue = true;
13
14
    public static function create(bool $useBashBrackets = true, bool $negateExpression = false): StringExpression
15
    {
16
        return new self($useBashBrackets, $negateExpression);
17
    }
18
19
    /**
20
     * @param string|ShellInterface $string
21
     * @return $this
22
     */
23
    public function lenghtZero($string): self
24
    {
25
        $this->operator = ConditionalOperator::STRING_LENGHT_ZERO;
26
        $this->compareWith = $string;
27
        return $this;
28
    }
29
30
    /**
31
     * @param string|ShellInterface $string
32
     * @return $this
33
     */
34
    public function lengthNotZero($string): self
35
    {
36
        $this->operator = ConditionalOperator::STRING_LENGHT_NOT_ZERO;
37
        $this->compareWith = $string;
38
        return $this;
39
    }
40
41
    /**
42
     * @param string|ShellInterface $stringA
43
     * @param string|ShellInterface $stringB
44
     * @return $this
45
     */
46
    public function eq($stringA, $stringB): self
47
    {
48
        $this->operator = ConditionalOperator::STRING_EQUAL;
49
        $this->compareWith = $stringB;
50
        $this->compare = $stringA;
51
        return $this;
52
    }
53
54
    /**
55
     * @param string|ShellInterface $stringA
56
     * @param string|ShellInterface $stringB
57
     * @return $this
58
     */
59
    public function equal($stringA, $stringB): self
60
    {
61
        $this->operator = ConditionalOperator::STRING_EQUAL_BASH;
62
        $this->bashEnhancedBrackets = true;
63
        $this->compareWith = $stringB;
64
        $this->compare = $stringA;
65
        return $this;
66
    }
67
68
    /**
69
     * @param string|ShellInterface $stringA
70
     * @param string|ShellInterface $stringB
71
     * @return $this
72
     */
73
    public function notEqual($stringA, $stringB): self
74
    {
75
        $this->operator = ConditionalOperator::STRING_NOT_EQUAL;
76
        $this->compareWith = $stringB;
77
        $this->compare = $stringA;
78
        return $this;
79
    }
80
81
    /**
82
     * @param string|ShellInterface $stringA
83
     * @param string|ShellInterface $stringB
84
     * @return $this
85
     */
86
    public function sortsBefore($stringA, $stringB): self
87
    {
88
        $this->operator = ConditionalOperator::STRING_SORTS_BEFORE;
89
        $this->compareWith = $stringB;
90
        $this->compare = $stringA;
91
        return $this;
92
    }
93
94
    /**
95
     * @param string|ShellInterface $stringA
96
     * @param string|ShellInterface $stringB
97
     * @return $this
98
     */
99
    public function sortsAfter($stringA, $stringB): self
100
    {
101
        $this->operator = ConditionalOperator::STRING_SORTS_AFTER;
102
        $this->compareWith = $stringB;
103
        $this->compare = $stringA;
104
        return $this;
105
    }
106
}
107