WordPressDSExpressionProvider::onUnaryExpression()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 10

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 10
nc 3
nop 2
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 11 and the first side effect is on line 9.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
use POData\UriProcessor\QueryProcessor\ExpressionParser\Expressions\ExpressionType;
4
use POData\Providers\Metadata\Type\IType;
5
use POData\Common\NotImplementedException;
6
use POData\Common\ODataConstants;
7
use POData\Providers\Expression\IExpressionProvider;
8
use POData\Providers\Metadata\ResourceType;
9
require_once 'WordPressMetadata.php';
10
11
class WordPressDSExpressionProvider implements IExpressionProvider
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
12
{
13
    const ADD                  = '+';
14
    const CLOSE_BRACKET        = ')';
15
    const COMMA                = ',';
16
    const DIVIDE               = '/';
17
    const SUBTRACT             = '-';
18
    const EQUAL                = '=';
19
    const GREATERTHAN          = '>';
20
    const GREATERTHAN_OR_EQUAL = '>=';
21
    const LESSTHAN             = '<';
22
    const LESSTHAN_OR_EQUAL    = '<=';
23
    const LOGICAL_AND          = '&&';
24
    const LOGICAL_NOT          = '!';
25
    const LOGICAL_OR           = '||';
26
    const MEMBERACCESS         = '';
27
    const MODULO               = '%';
28
    const MULTIPLY             = '*';
29
    const NEGATE               = '-';
30
    const NOTEQUAL             = '!=';
31
    const OPEN_BRAKET          = '(';
32
    
33
    /**
34
     * The type of the resource pointed by the resource path segement
35
     *
36
     * @var ResourceType
37
     */
38
    private $_resourceType;
39
40
    /**
41
     * 
42
     * @var array(string, array(string, string))
43
     */
44
    private $_entityMapping;
45
46
    /**
47
     * Constructs new instance of WordPressDSExpressionProvider
48
     *    
49
     */
50
    public function __construct()
51
    {
52
      $this->_entityMapping = CreateWordPressMetadata::getEntityMapping();
53
    }
54
55
    /**
56
     * Get the name of the iterator
57
     * 
58
     * @return string
59
     */
60
    public function getIteratorName()
61
    {
62
        return null;
63
    }
64
65
    /**
66
     * call-back for setting the resource type.
67
     *
68
     * @param ResourceType $resourceType The resource type on which the filter
69
     *                                   is going to be applied.
70
     */
71
    public function setResourceType(ResourceType $resourceType)
72
    {
73
      $this->_resourceType = $resourceType;
74
    }
75
76
    /**
77
     * Call-back for logical expression
78
     * 
79
     * @param ExpressionType $expressionType The type of logical expression.
80
     * @param string         $left           The left expression.
81
     * @param string         $right          The left expression.
82
     * 
83
     * @return string
84
     */
85 View Code Duplication
    public function onLogicalExpression($expressionType, $left, $right)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
86
    {
87
        switch($expressionType) {
88
        case ExpressionType::AND_LOGICAL:
89
            return $this->_prepareBinaryExpression(self::LOGICAL_AND, $left, $right);
90
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
91
        case ExpressionType::OR_LOGICAL:
92
            return $this->_prepareBinaryExpression(self::LOGICAL_OR, $left, $right);
93
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
94
        default:
95
            throw new \InvalidArgumentException('onLogicalExpression');
96
        }
97
    }
98
99
    /**
100
     * Call-back for arithmetic expression
101
     * 
102
     * @param ExpressionType $expressionType The type of arithmetic expression.
103
     * @param string         $left           The left expression.
104
     * @param string         $right          The left expression.
105
     * 
106
     * @return string
107
     */
108 View Code Duplication
    public function onArithmeticExpression($expressionType, $left, $right)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
109
    {
110
        switch($expressionType) {
111
        case ExpressionType::MULTIPLY:
112
            return $this->_prepareBinaryExpression(self::MULTIPLY, $left, $right);
113
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
114
        case ExpressionType::DIVIDE:
115
            return $this->_prepareBinaryExpression(self::DIVIDE, $left, $right);
116
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
117
        case ExpressionType::MODULO:
118
            return $this->_prepareBinaryExpression(self::MODULO, $left, $right);
119
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
120
        case ExpressionType::ADD:
121
            return $this->_prepareBinaryExpression(self::ADD, $left, $right);
122
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
123
        case ExpressionType::SUBTRACT:
124
            return $this->_prepareBinaryExpression(self::SUBTRACT, $left, $right);
125
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
126
        default:
127
            throw new \InvalidArgumentException('onArithmeticExpression');
128
        }
129
    }
130
131
    /**
132
     * Call-back for relational expression
133
     * 
134
     * @param ExpressionType $expressionType The type of relation expression
135
     * @param string         $left           The left expression
136
     * @param string         $right          The left expression
137
     * 
138
     * @return string
139
     */
140 View Code Duplication
    public function onRelationalExpression($expressionType, $left, $right)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
141
    {
142
        switch($expressionType) {
143
        case ExpressionType::GREATERTHAN:
144
            return $this->_prepareBinaryExpression(self::GREATERTHAN, $left, $right);
145
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
146
        case ExpressionType::GREATERTHAN_OR_EQUAL:
147
            return $this->_prepareBinaryExpression(
148
                self::GREATERTHAN_OR_EQUAL, $left, $right
149
            );
150
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
151
        case ExpressionType::LESSTHAN:
152
            return $this->_prepareBinaryExpression(self::LESSTHAN, $left, $right);
153
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
154
        case ExpressionType::LESSTHAN_OR_EQUAL:
155
            return $this->_prepareBinaryExpression(
156
                self::LESSTHAN_OR_EQUAL, $left, $right
157
            );
158
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
159
        case ExpressionType::EQUAL:
160
            return $this->_prepareBinaryExpression(self::EQUAL, $left, $right);
161
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
162
        case ExpressionType::NOTEQUAL:
163
            return $this->_prepareBinaryExpression(self::NOTEQUAL, $left, $right);
164
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
165
        default:
166
            throw new \InvalidArgumentException('onArithmeticExpression');
167
        }
168
    }
169
170
    /**
171
     * Call-back for unary expression
172
     * 
173
     * @param ExpressionType $expressionType The type of unary expression
174
     * @param string         $child          The child expression
175
     * 
176
     * @return string
177
     */
178 View Code Duplication
    public function onUnaryExpression($expressionType, $child)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
179
    {
180
        switch($expressionType) {
181
        case ExpressionType::NEGATE:
182
            return $this->_prepareUnaryExpression(self::NEGATE, $child);
183
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
184
        case ExpressionType::NOT_LOGICAL:
185
            return $this->_prepareUnaryExpression(self::LOGICAL_NOT, $child);
186
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
187
        default:
188
            throw new \InvalidArgumentException('onUnaryExpression');
189
        }
190
    }
191
192
    /**
193
     * Call-back for constant expression
194
     * 
195
     * @param IType  $type  The type of constant
196
     * @param objetc $value The value of the constant
197
     * 
198
     * @return string
199
     */
200 View Code Duplication
    public function onConstantExpression(IType $type, $value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
201
    {
202
        if (is_bool($value)) {
203
            return var_export($value, true);
204
        } else if (is_null($value)) {
205
            return var_export(null, true);
206
        }
207
208
        return $value;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $value; (objetc) is incompatible with the return type declared by the interface POData\Providers\Express...r::onConstantExpression of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
209
    }
210
211
    /**
212
     * Call-back for property access expression
213
     * 
214
     * @param PropertyAccessExpression $expression The property access expression
215
     * 
216
     * @return string
217
     */
218
219 View Code Duplication
    public function onPropertyAccessExpression($expression)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
220
    {
221
        $parent = $expression;
222
        $variable = null;
0 ignored issues
show
Unused Code introduced by
$variable is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
223
        $entityTypeName = $this->_resourceType->getName();
224
        $propertyName = $parent->getResourceProperty()->getName();
225
        if (is_array($this->_entityMapping)) {
226
          if (array_key_exists($entityTypeName, $this->_entityMapping)) {
227
            if (array_key_exists($propertyName, $this->_entityMapping[$entityTypeName])) {
228
              return $this->_entityMapping[$entityTypeName][$propertyName];
229
            }
230
          }
231
        }
232
     
233
        return $propertyName;
234
    }
235
236
    /**
237
     * Call-back for function call expression
238
     * 
239
     * @param FunctionDescription $functionDescription Description of the function.
240
     * @param array<string>       $params              Paameters to the function.
241
     * 
242
     * @return string
243
     */
244
    public function onFunctionCallExpression($functionDescription, $params)
245
    {
246
        switch($functionDescription->functionName) {
247
        case ODataConstants::STRFUN_COMPARE:
248
            return "STRCMP($params[0], $params[1])";
249
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
250
        case ODataConstants::STRFUN_ENDSWITH:
251
          return "(STRCMP($params[1],RIGHT($params[0],LENGTH($params[1]))) = 0)";
252
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
253
        case ODataConstants::STRFUN_INDEXOF:
254
            return "INSTR($params[0], $params[1]) - 1";
255
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
256
        case ODataConstants::STRFUN_REPLACE:
257
          return "REPLACE($params[0],$params[1],$params[2])";
258
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
259
        case ODataConstants::STRFUN_STARTSWITH:
260
          return "(STRCMP($params[1],LEFT($params[0],LENGTH($params[1]))) = 0)";
261
            break; 
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
262
        case ODataConstants::STRFUN_TOLOWER:
263
          return "LOWER($params[0])";
264
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
265
        case ODataConstants::STRFUN_TOUPPER:
266
          return "UPPER($params[0])";
267
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
268
        case ODataConstants::STRFUN_TRIM:
269
          return "TRIM($params[0])";
270
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
271 View Code Duplication
        case ODataConstants::STRFUN_SUBSTRING:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
272
            return count($params) == 3 ?
273
                "SUBSTRING($params[0], $params[1] + 1, $params[2])" :
274
                "SUBSTRING($params[0], $params[1] + 1)";
275
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
276
        case ODataConstants::STRFUN_SUBSTRINGOF:
277
            return "(LOCATE($params[0], $params[1]) > 0)";
278
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
279
        case ODataConstants::STRFUN_CONCAT:
280
            return "CONCAT($params[0],$params[1])";
281
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
282
        case ODataConstants::STRFUN_LENGTH:
283
            return "LENGTH($params[0])";
284
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
285
        case ODataConstants::GUIDFUN_EQUAL:
286
        	return "STRCMP($params[0], $params[1])";
287
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
288
        case ODataConstants::DATETIME_COMPARE:
289
            return "DATETIMECMP($params[0]; $params[1])";
290
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
291
        case ODataConstants::DATETIME_YEAR:
292
            return "EXTRACT(YEAR from ".$params[0].")";
293
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
294
        case ODataConstants::DATETIME_MONTH:
295
            return "EXTRACT(MONTH from ".$params[0].")";
296
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
297
        case ODataConstants::DATETIME_DAY:
298
            return "EXTRACT(DAY from ".$params[0].")";
299
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
300
        case ODataConstants::DATETIME_HOUR:
301
            return "EXTRACT(HOUR from ".$params[0].")";
302
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
303
        case ODataConstants::DATETIME_MINUTE:
304
            return "EXTRACT(MINUTE from ".$params[0].")";
305
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
306
        case ODataConstants::DATETIME_SECOND:
307
            return "EXTRACT(SECOND from ".$params[0].")";
308
            break;                
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
309
        case ODataConstants::MATHFUN_ROUND:
310
            return "ROUND($params[0])";
311
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
312
        case ODataConstants::MATHFUN_CEILING:
313
            return "CEIL($params[0])";
314
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
315
        case ODataConstants::MATHFUN_FLOOR:
316
            return "FLOOR($params[0])";
317
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
318
        case ODataConstants::BINFUL_EQUAL:
319
            return "($params[0] = $params[1])";
320
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
321
        case 'is_null':
322
            return "is_null($params[0])";
323
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
324
            
325
        default:
326
            throw new \InvalidArgumentException('onFunctionCallExpression');
327
        }
328
    }
329
330
    /**
331
     * To format binary expression
332
     * 
333
     * @param string $operator The binary operator.
334
     * @param string $left     The left operand.
335
     * @param string $right    The right operand.
336
     * 
337
     * @return string
338
     */
339 View Code Duplication
    private function _prepareBinaryExpression($operator, $left, $right)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
340
    {
341
      // Special handling for DATETIMECMP
342
      if (!substr_compare($left, "DATETIMECMP", 0, 11)) {
343
        $str = explode(';', $left, 2);
344
        $str[0] = str_replace('DATETIMECMP', '', $str[0]);
345
        return self::OPEN_BRAKET
346
          . $str[0] . ' ' . $operator
347
          . ' ' . $str[1] . self::CLOSE_BRACKET;
348
      }
349
350
        return 
351
            self::OPEN_BRAKET 
352
            . $left . ' ' . $operator 
353
            . ' ' . $right . self::CLOSE_BRACKET;
354
    }
355
356
    /**
357
     * To format unary expression
358
     * 
359
     * @param string $operator The unary operator.
360
     * @param string $child    The operand.
361
     * 
362
     * @return string
363
     */
364
    private function _prepareUnaryExpression($operator, $child)
365
    {
366
        return $operator . self::OPEN_BRAKET . $child . self::CLOSE_BRACKET;
367
    }
368
}
369