Passed
Push — master ( 98205f...6f7a23 )
by Thierry
02:22
created

CallConditionTrait::ifteq()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 2
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Jaxon\Request\Call\Traits;
4
5
use Jaxon\Request\Call\Call;
6
use Jaxon\Request\Call\Parameter;
7
8
use function array_map;
9
use function func_get_args;
10
11
trait CallConditionTrait
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait CallConditionTrait
Loading history...
12
{
13
    /**
14
     * A condition to check before making the call
15
     *
16
     * @var string
17
     */
18
    protected $sCondition = '';
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
19
20
    /**
21
     * The arguments of the confirm() call
22
     *
23
     * @var array
24
     */
25
    protected $aConfirmArgs = [];
26
27
    /**
28
     * Add a condition to the request
29
     *
30
     * The request is sent only if the condition is true.
31
     *
32
     * @param mixed $xCondition    The condition to check
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
33
     *
34
     * @return Call
35
     */
36
    public function when($xCondition): Call
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
37
    {
38
        $this->sCondition = Parameter::make($xCondition)->getScript();
39
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Jaxon\Request\Call\Traits\CallConditionTrait which includes types incompatible with the type-hinted return Jaxon\Request\Call\Call.
Loading history...
40
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
41
42
    /**
43
     * Add a condition to the request
44
     *
45
     * The request is sent only if the condition is false.
46
     *
47
     * @param mixed $xCondition    The condition to check
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
48
     *
49
     * @return Call
50
     */
51
    public function unless($xCondition): Call
52
    {
53
        $this->sCondition = '!(' . Parameter::make($xCondition)->getScript() . ')';
54
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Jaxon\Request\Call\Traits\CallConditionTrait which includes types incompatible with the type-hinted return Jaxon\Request\Call\Call.
Loading history...
55
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
56
57
    /**
58
     * Check if a value is equal to another before sending the request
59
     *
60
     * @param mixed $xValue1    The first value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
61
     * @param mixed $xValue2    The second value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
62
     *
63
     * @return Call
64
     */
65
    public function ifeq($xValue1, $xValue2): Call
66
    {
67
        $this->sCondition = Parameter::make($xValue1) . '==' . Parameter::make($xValue2);
0 ignored issues
show
Bug introduced by
Are you sure Jaxon\Request\Call\Parameter::make($xValue2) of type Jaxon\Request\Call\ParameterInterface can be used in concatenation? Consider adding a __toString()-method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

67
        $this->sCondition = Parameter::make($xValue1) . '==' . /** @scrutinizer ignore-type */ Parameter::make($xValue2);
Loading history...
Bug introduced by
Are you sure Jaxon\Request\Call\Parameter::make($xValue1) of type Jaxon\Request\Call\ParameterInterface can be used in concatenation? Consider adding a __toString()-method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

67
        $this->sCondition = /** @scrutinizer ignore-type */ Parameter::make($xValue1) . '==' . Parameter::make($xValue2);
Loading history...
68
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Jaxon\Request\Call\Traits\CallConditionTrait which includes types incompatible with the type-hinted return Jaxon\Request\Call\Call.
Loading history...
69
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
70
71
    /**
72
     * Check if a value is equal to another before sending the request
73
     *
74
     * @param mixed $xValue1    The first value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
75
     * @param mixed $xValue2    The second value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
76
     *
77
     * @return Call
78
     */
79
    public function ifteq($xValue1, $xValue2): Call
80
    {
81
        $this->sCondition = Parameter::make($xValue1) . '===' . Parameter::make($xValue2);
0 ignored issues
show
Bug introduced by
Are you sure Jaxon\Request\Call\Parameter::make($xValue1) of type Jaxon\Request\Call\ParameterInterface can be used in concatenation? Consider adding a __toString()-method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

81
        $this->sCondition = /** @scrutinizer ignore-type */ Parameter::make($xValue1) . '===' . Parameter::make($xValue2);
Loading history...
Bug introduced by
Are you sure Jaxon\Request\Call\Parameter::make($xValue2) of type Jaxon\Request\Call\ParameterInterface can be used in concatenation? Consider adding a __toString()-method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

81
        $this->sCondition = Parameter::make($xValue1) . '===' . /** @scrutinizer ignore-type */ Parameter::make($xValue2);
Loading history...
82
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Jaxon\Request\Call\Traits\CallConditionTrait which includes types incompatible with the type-hinted return Jaxon\Request\Call\Call.
Loading history...
83
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
84
85
    /**
86
     * Check if a value is not equal to another before sending the request
87
     *
88
     * @param mixed $xValue1    The first value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
89
     * @param mixed $xValue2    The second value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
90
     *
91
     * @return Call
92
     */
93
    public function ifne($xValue1, $xValue2): Call
94
    {
95
        $this->sCondition = Parameter::make($xValue1) . '!=' . Parameter::make($xValue2);
0 ignored issues
show
Bug introduced by
Are you sure Jaxon\Request\Call\Parameter::make($xValue1) of type Jaxon\Request\Call\ParameterInterface can be used in concatenation? Consider adding a __toString()-method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

95
        $this->sCondition = /** @scrutinizer ignore-type */ Parameter::make($xValue1) . '!=' . Parameter::make($xValue2);
Loading history...
Bug introduced by
Are you sure Jaxon\Request\Call\Parameter::make($xValue2) of type Jaxon\Request\Call\ParameterInterface can be used in concatenation? Consider adding a __toString()-method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

95
        $this->sCondition = Parameter::make($xValue1) . '!=' . /** @scrutinizer ignore-type */ Parameter::make($xValue2);
Loading history...
96
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Jaxon\Request\Call\Traits\CallConditionTrait which includes types incompatible with the type-hinted return Jaxon\Request\Call\Call.
Loading history...
97
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
98
99
    /**
100
     * Check if a value is not equal to another before sending the request
101
     *
102
     * @param mixed $xValue1    The first value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
103
     * @param mixed $xValue2    The second value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
104
     *
105
     * @return Call
106
     */
107
    public function ifnte($xValue1, $xValue2): Call
108
    {
109
        $this->sCondition = Parameter::make($xValue1) . '!==' . Parameter::make($xValue2);
0 ignored issues
show
Bug introduced by
Are you sure Jaxon\Request\Call\Parameter::make($xValue2) of type Jaxon\Request\Call\ParameterInterface can be used in concatenation? Consider adding a __toString()-method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

109
        $this->sCondition = Parameter::make($xValue1) . '!==' . /** @scrutinizer ignore-type */ Parameter::make($xValue2);
Loading history...
Bug introduced by
Are you sure Jaxon\Request\Call\Parameter::make($xValue1) of type Jaxon\Request\Call\ParameterInterface can be used in concatenation? Consider adding a __toString()-method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

109
        $this->sCondition = /** @scrutinizer ignore-type */ Parameter::make($xValue1) . '!==' . Parameter::make($xValue2);
Loading history...
110
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Jaxon\Request\Call\Traits\CallConditionTrait which includes types incompatible with the type-hinted return Jaxon\Request\Call\Call.
Loading history...
111
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
112
113
    /**
114
     * Check if a value is greater than another before sending the request
115
     *
116
     * @param mixed $xValue1    The first value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
117
     * @param mixed $xValue2    The second value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
118
     *
119
     * @return Call
120
     */
121
    public function ifgt($xValue1, $xValue2): Call
122
    {
123
        $this->sCondition = Parameter::make($xValue1) . '>' . Parameter::make($xValue2);
0 ignored issues
show
Bug introduced by
Are you sure Jaxon\Request\Call\Parameter::make($xValue1) of type Jaxon\Request\Call\ParameterInterface can be used in concatenation? Consider adding a __toString()-method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

123
        $this->sCondition = /** @scrutinizer ignore-type */ Parameter::make($xValue1) . '>' . Parameter::make($xValue2);
Loading history...
Bug introduced by
Are you sure Jaxon\Request\Call\Parameter::make($xValue2) of type Jaxon\Request\Call\ParameterInterface can be used in concatenation? Consider adding a __toString()-method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

123
        $this->sCondition = Parameter::make($xValue1) . '>' . /** @scrutinizer ignore-type */ Parameter::make($xValue2);
Loading history...
124
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Jaxon\Request\Call\Traits\CallConditionTrait which includes types incompatible with the type-hinted return Jaxon\Request\Call\Call.
Loading history...
125
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
126
127
    /**
128
     * Check if a value is greater or equal to another before sending the request
129
     *
130
     * @param mixed $xValue1    The first value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
131
     * @param mixed $xValue2    The second value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
132
     *
133
     * @return Call
134
     */
135
    public function ifge($xValue1, $xValue2): Call
136
    {
137
        $this->sCondition = Parameter::make($xValue1) . '>=' . Parameter::make($xValue2);
0 ignored issues
show
Bug introduced by
Are you sure Jaxon\Request\Call\Parameter::make($xValue1) of type Jaxon\Request\Call\ParameterInterface can be used in concatenation? Consider adding a __toString()-method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

137
        $this->sCondition = /** @scrutinizer ignore-type */ Parameter::make($xValue1) . '>=' . Parameter::make($xValue2);
Loading history...
Bug introduced by
Are you sure Jaxon\Request\Call\Parameter::make($xValue2) of type Jaxon\Request\Call\ParameterInterface can be used in concatenation? Consider adding a __toString()-method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

137
        $this->sCondition = Parameter::make($xValue1) . '>=' . /** @scrutinizer ignore-type */ Parameter::make($xValue2);
Loading history...
138
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Jaxon\Request\Call\Traits\CallConditionTrait which includes types incompatible with the type-hinted return Jaxon\Request\Call\Call.
Loading history...
139
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
140
141
    /**
142
     * Check if a value is lower than another before sending the request
143
     *
144
     * @param mixed $xValue1    The first value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
145
     * @param mixed $xValue2    The second value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
146
     *
147
     * @return Call
148
     */
149
    public function iflt($xValue1, $xValue2): Call
150
    {
151
        $this->sCondition = Parameter::make($xValue1) . '<' . Parameter::make($xValue2);
0 ignored issues
show
Bug introduced by
Are you sure Jaxon\Request\Call\Parameter::make($xValue1) of type Jaxon\Request\Call\ParameterInterface can be used in concatenation? Consider adding a __toString()-method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

151
        $this->sCondition = /** @scrutinizer ignore-type */ Parameter::make($xValue1) . '<' . Parameter::make($xValue2);
Loading history...
Bug introduced by
Are you sure Jaxon\Request\Call\Parameter::make($xValue2) of type Jaxon\Request\Call\ParameterInterface can be used in concatenation? Consider adding a __toString()-method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

151
        $this->sCondition = Parameter::make($xValue1) . '<' . /** @scrutinizer ignore-type */ Parameter::make($xValue2);
Loading history...
152
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Jaxon\Request\Call\Traits\CallConditionTrait which includes types incompatible with the type-hinted return Jaxon\Request\Call\Call.
Loading history...
153
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
154
155
    /**
156
     * Check if a value is lower or equal to another before sending the request
157
     *
158
     * @param mixed $xValue1    The first value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
159
     * @param mixed $xValue2    The second value to compare
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
160
     *
161
     * @return Call
162
     */
163
    public function ifle($xValue1, $xValue2): Call
164
    {
165
        $this->sCondition = Parameter::make($xValue1) . '<=' . Parameter::make($xValue2);
0 ignored issues
show
Bug introduced by
Are you sure Jaxon\Request\Call\Parameter::make($xValue2) of type Jaxon\Request\Call\ParameterInterface can be used in concatenation? Consider adding a __toString()-method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

165
        $this->sCondition = Parameter::make($xValue1) . '<=' . /** @scrutinizer ignore-type */ Parameter::make($xValue2);
Loading history...
Bug introduced by
Are you sure Jaxon\Request\Call\Parameter::make($xValue1) of type Jaxon\Request\Call\ParameterInterface can be used in concatenation? Consider adding a __toString()-method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

165
        $this->sCondition = /** @scrutinizer ignore-type */ Parameter::make($xValue1) . '<=' . Parameter::make($xValue2);
Loading history...
166
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Jaxon\Request\Call\Traits\CallConditionTrait which includes types incompatible with the type-hinted return Jaxon\Request\Call\Call.
Loading history...
167
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
168
169
    /**
170
     * Add a confirmation question to the request
171
     *
172
     * @param string $sQuestion    The question to ask
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
173
     *
174
     * @return Call
175
     */
176
    public function confirm(string $sQuestion): Call
177
    {
178
        $this->sCondition = '__confirm__';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
179
        $this->aConfirmArgs = array_map(function($xParameter) {
180
            return Parameter::make($xParameter);
181
        }, func_get_args());
182
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Jaxon\Request\Call\Traits\CallConditionTrait which includes types incompatible with the type-hinted return Jaxon\Request\Call\Call.
Loading history...
183
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
184
}
185