GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — develop (#2377)
by
unknown
06:38
created

Query::getArguments()   D

Complexity

Conditions 21
Paths 17

Size

Total Lines 67

Duplication

Lines 50
Ratio 74.63 %

Importance

Changes 0
Metric Value
cc 21
nc 17
nop 0
dl 50
loc 67
rs 4.1666
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
4
/**
5
 * @author NAVER ([email protected])
6
 * @package /classes/db/queryparts
7
 * @version 0.1
8
 */
9
class Query extends BaseObject
10
{
11
12
	/**
13
	 * Query id, defined in query xml file
14
	 * @var string
15
	 */
16
	var $queryID;
17
18
	/**
19
	 * DML type, ex) INSERT, DELETE, UPDATE, SELECT
20
	 * @var string
21
	 */
22
	var $action;
23
24
	/**
25
	 * priority level ex)LOW_PRIORITY, HIGHT_PRIORITY
26
	 * @var string
27
	 */
28
	var $priority;
29
30
	/**
31
	 * column list
32
	 * @var string|array
33
	 */
34
	var $columns;
35
36
	/**
37
	 * table list
38
	 * @var string|array
39
	 */
40
	var $tables;
41
42
	/**
43
	 * condition list
44
	 * @var string|array
45
	 */
46
	var $conditions;
47
48
	/**
49
	 * group list
50
	 * @var string|array
51
	 */
52
	var $groups;
53
54
	/**
55
	 * order list
56
	 * @var array
57
	 */
58
	var $orderby;
59
60
	/**
61
	 * limit count
62
	 * @var int
63
	 */
64
	var $limit;
65
66
	/**
67
	 * argument list
68
	 * @var array
69
	 */
70
	var $arguments = NULL;
71
72
	/**
73
	 * column list
74
	 * @var array
75
	 */
76
	var $columnList = NULL;
77
78
	/**
79
	 * order by text
80
	 * @var string
81
	 */
82
	var $_orderByString;
83
84
	/**
85
	 * constructor
86
	 * @param string $queryID
87
	 * @param string $action
88
	 * @param string|array $columns
89
	 * @param string|array $tables
90
	 * @param string|array $conditions
91
	 * @param string|array $groups
92
	 * @param string|array $orderby
93
	 * @param int $limit
94
	 * @param string $priority
95
	 * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
96
	 */
97
	function __construct($queryID = NULL
98
	, $action = NULL
99
	, $columns = NULL
100
	, $tables = NULL
101
	, $conditions = NULL
102
	, $groups = NULL
103
	, $orderby = NULL
104
	, $limit = NULL
105
	, $priority = NULL)
106
	{
107
		$this->queryID = $queryID;
108
		$this->action = $action;
109
		$this->priority = $priority;
110
111
		if(!isset($tables))
112
		{
113
			return;
114
		}
115
116
		$this->columns = $this->setColumns($columns);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $this->columns is correct as $this->setColumns($columns) (which targets Query::setColumns()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
117
		$this->tables = $this->setTables($tables);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $this->tables is correct as $this->setTables($tables) (which targets Query::setTables()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
118
		$this->conditions = $this->setConditions($conditions);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $this->conditions is correct as $this->setConditions($conditions) (which targets Query::setConditions()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
119
		$this->groups = $this->setGroups($groups);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $this->groups is correct as $this->setGroups($groups) (which targets Query::setGroups()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
120
		$this->orderby = $this->setOrder($orderby);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->setOrder($orderby) of type null is incompatible with the declared type array of property $orderby.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
Bug introduced by
Are you sure the assignment to $this->orderby is correct as $this->setOrder($orderby) (which targets Query::setOrder()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
121
		$this->limit = $this->setLimit($limit);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $this->limit is correct as $this->setLimit($limit) (which targets Query::setLimit()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
122
	}
123
124
	function show()
125
	{
126
		return TRUE;
127
	}
128
129
	function setQueryId($queryID)
130
	{
131
		$this->queryID = $queryID;
132
	}
133
134
	function setAction($action)
135
	{
136
		$this->action = $action;
137
	}
138
139
	function setPriority($priority)
140
	{
141
		$this->priority = $priority;
142
	}
143
144
	function setColumnList($columnList)
145
	{
146
		$this->columnList = $columnList;
147
		if(is_array($this->columnList) && count($this->columnList) > 0)
148
		{
149
			$selectColumns = array();
150
			$dbParser = DB::getParser();
151
152
			foreach($this->columnList as $columnName)
153
			{
154
				$columnName = $dbParser->escapeColumn($columnName);
155
				$selectColumns[] = new SelectExpression($columnName);
156
			}
157
			unset($this->columns);
158
			$this->columns = $selectColumns;
159
		}
160
	}
161
162
	function setColumns($columns)
163
	{
164
		if(!isset($columns) || (is_array($columns) && count($columns) === 0))
165
		{
166
			$this->columns = array(new StarExpression());
167
			return;
168
		}
169
170
		if(!is_array($columns))
171
		{
172
			$columns = array($columns);
173
		}
174
175
		$this->columns = $columns;
176
	}
177
178
	function setTables($tables)
179
	{
180
		if(!isset($tables) || (is_array($tables) && count($tables) === 0))
181
		{
182
			$this->setError(TRUE);
0 ignored issues
show
Documentation introduced by
TRUE is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
183
			$this->setMessage("You must provide at least one table for the query.");
184
			return;
185
		}
186
187
		if(!is_array($tables))
188
		{
189
			$tables = array($tables);
190
		}
191
192
		$this->tables = $tables;
193
	}
194
195
	function setSubquery($subquery)
196
	{
197
		$this->subquery = $subquery;
0 ignored issues
show
Bug introduced by
The property subquery does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
198
	}
199
200
	function setConditions($conditions)
201
	{
202
		$this->conditions = array();
203
		if(!isset($conditions) || (is_array($conditions) && count($conditions) === 0))
204
		{
205
			return;
206
		}
207
		if(!is_array($conditions))
208
		{
209
			$conditions = array($conditions);
210
		}
211
212
		foreach($conditions as $conditionGroup)
213
		{
214
			if($conditionGroup->show())
215
			{
216
				$this->conditions[] = $conditionGroup;
217
			}
218
		}
219
	}
220
221 View Code Duplication
	function setGroups($groups)
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...
222
	{
223
		if(!isset($groups) || (is_array($groups) && count($groups) === 0))
224
		{
225
			return;
226
		}
227
		if(!is_array($groups))
228
		{
229
			$groups = array($groups);
230
		}
231
232
		$this->groups = $groups;
233
	}
234
235 View Code Duplication
	function setOrder($order)
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...
236
	{
237
		if(!isset($order) || (is_array($order) && count($order) === 0))
238
		{
239
			return;
240
		}
241
		if(!is_array($order))
242
		{
243
			$order = array($order);
244
		}
245
246
		$this->orderby = $order;
247
	}
248
249
	function getOrder()
250
	{
251
		return $this->orderby;
252
	}
253
254
	function setLimit($limit = NULL)
255
	{
256
		if(!isset($limit))
257
		{
258
			return;
259
		}
260
		$this->limit = $limit;
261
	}
262
263
	// START Fluent interface
264
	/**
265
	 * seleect set
266
	 * @param string|array $columns
267
	 * @return Query return Query instance
268
	 */
269
	function select($columns = NULL)
270
	{
271
		$this->action = 'select';
272
		$this->setColumns($columns);
273
		return $this;
274
	}
275
276
	/**
277
	 * from set
278
	 * @param string|array $tables
279
	 * @return Query return Query instance
280
	 */
281
	function from($tables)
282
	{
283
		$this->setTables($tables);
284
		return $this;
285
	}
286
287
	/**
288
	 * where set
289
	 * @param string|array $conditions
290
	 * @return Query return Query instance
291
	 */
292
	function where($conditions)
293
	{
294
		$this->setConditions($conditions);
295
		return $this;
296
	}
297
298
	/**
299
	 * groupBy set
300
	 * @param string|array $groups
301
	 * @return Query return Query instance
302
	 */
303
	function groupBy($groups)
304
	{
305
		$this->setGroups($groups);
306
		return $this;
307
	}
308
309
	/**
310
	 * orderBy set
311
	 * @param string|array $order
312
	 * @return Query return Query instance
313
	 */
314
	function orderBy($order)
315
	{
316
		$this->setOrder($order);
317
		return $this;
318
	}
319
320
	/**
321
	 * limit set
322
	 * @param int $limit
323
	 * @return Query return Query instance
324
	 */
325
	function limit($limit)
326
	{
327
		$this->setLimit($limit);
328
		return $this;
329
	}
330
331
	// END Fluent interface
332
333
	function getAction()
334
	{
335
		return $this->action;
336
	}
337
338
	function getPriority()
339
	{
340
		return $this->priority ? 'LOW_PRIORITY' : '';
341
	}
342
343
	/**
344
	 * Check if current query uses the click count attribute
345
	 * For CUBRID, this statement uses the click count feature.
346
	 * For the other databases, using this attribute causes a query
347
	 * to produce both a select and an update
348
	 */
349
	function usesClickCount()
350
	{
351
		return count($this->getClickCountColumns()) > 0;
352
	}
353
354
	function getClickCountColumns()
355
	{
356
		$click_count_columns = array();
357
		foreach($this->columns as $column)
0 ignored issues
show
Bug introduced by
The expression $this->columns of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
358
		{
359
			if($column->show() && is_a($column, 'ClickCountExpression'))
360
			{
361
				$click_count_columns[] = $column;
362
			}
363
		}
364
		return $click_count_columns;
365
	}
366
367
	/**
368
	 * Return select sql
369
	 * @param boolean $with_values
370
	 * @return string
371
	 */
372
	function getSelectString($with_values = TRUE)
373
	{
374
		foreach($this->columns as $column)
0 ignored issues
show
Bug introduced by
The expression $this->columns of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
375
		{
376
			if($column->show())
377
			{
378
				if($column->isSubquery())
379
				{
380
					$select[] = $column->toString($with_values) . ' as ' . $column->getAlias();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$select was never initialized. Although not strictly required by PHP, it is generally a good practice to add $select = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
381
				}
382
				else
383
				{
384
					$select[] = $column->getExpression($with_values);
0 ignored issues
show
Bug introduced by
The variable $select does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
385
				}
386
			}
387
		}
388
		return trim(implode($select, ', '));
389
	}
390
391
	/**
392
	 * Return update sql
393
	 * @param boolean $with_values
394
	 * @return string
395
	 */
396
	function getUpdateString($with_values = TRUE)
397
	{
398
		foreach($this->columns as $column)
0 ignored issues
show
Bug introduced by
The expression $this->columns of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
399
		{
400
			if($column->show())
401
			{
402
				$update[] = $column->getExpression($with_values);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$update was never initialized. Although not strictly required by PHP, it is generally a good practice to add $update = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
403
			}
404
		}
405
406
		if(!$update) return;
0 ignored issues
show
Bug introduced by
The variable $update does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug Best Practice introduced by
The expression $update of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
407
		return trim(implode($update, ', '));
408
	}
409
410
	/**
411
	 * Return insert sql
412
	 * @param boolean $with_values
413
	 * @return string
414
	 */
415
	function getInsertString($with_values = TRUE)
416
	{
417
		$columnsList = '';
418
		// means we have insert-select
419
		if($this->subquery)
420
		{
421
			foreach($this->columns as $column)
0 ignored issues
show
Bug introduced by
The expression $this->columns of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
422
			{
423
				$columnsList .= $column->getColumnName() . ', ';
424
			}
425
			$columnsList = substr($columnsList, 0, -2);
426
			$selectStatement = $this->subquery->toString($with_values);
427
			$selectStatement = substr($selectStatement, 1, -1);
428
			return "($columnsList) \n $selectStatement";
429
		}
430
431
		$valuesList = '';
432
		foreach($this->columns as $column)
0 ignored issues
show
Bug introduced by
The expression $this->columns of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
433
		{
434
			if($column->show())
435
			{
436
				$columnsList .= $column->getColumnName() . ', ';
437
				$valuesList .= $column->getValue($with_values) . ', ';
438
			}
439
		}
440
		$columnsList = substr($columnsList, 0, -2);
441
		$valuesList = substr($valuesList, 0, -2);
442
443
		return "($columnsList) \n VALUES ($valuesList)";
444
	}
445
446
	function getTables()
447
	{
448
		return $this->tables;
449
	}
450
451
	/**
452
	 * from table_a
453
	 * from table_a inner join table_b on x=y
454
	 * from (select * from table a) as x
455
	 * from (select * from table t) as x inner join table y on y.x
456
	 * @param boolean $with_values
457
	 * @return string
458
	 */
459
	function getFromString($with_values = TRUE)
460
	{
461
		$from = '';
462
		$simple_table_count = 0;
463
		foreach($this->tables as $table)
0 ignored issues
show
Bug introduced by
The expression $this->tables of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
464
		{
465
			if($table->isJoinTable() || !$simple_table_count)
466
			{
467
				$from .= $table->toString($with_values) . ' ';
468
			}
469
			else
470
			{
471
				$from .= ', ' . $table->toString($with_values) . ' ';
472
			}
473
474
			if(is_a($table, 'Subquery'))
475
			{
476
				$from .= $table->getAlias() ? ' as ' . $table->getAlias() . ' ' : ' ';
477
			}
478
479
			$simple_table_count++;
480
		}
481
		if(trim($from) == '')
482
		{
483
			return '';
484
		}
485
		return $from;
486
	}
487
488
	/**
489
	 * Return where sql
490
	 * @param boolean $with_values
491
	 * @param boolean $with_optimization
492
	 * @return string
493
	 */
494
	function getWhereString($with_values = TRUE, $with_optimization = TRUE)
495
	{
496
		$where = '';
497
		$condition_count = 0;
498
499
		foreach($this->conditions as $conditionGroup)
0 ignored issues
show
Bug introduced by
The expression $this->conditions of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
500
		{
501
			if($condition_count === 0)
502
			{
503
				$conditionGroup->setPipe("");
504
			}
505
			$condition_string = $conditionGroup->toString($with_values);
506
			$where .= $condition_string;
507
			$condition_count++;
508
		}
509
510
		if($with_optimization &&
511
				(strstr($this->getOrderByString(), 'list_order') || strstr($this->getOrderByString(), 'update_order')))
512
		{
513
514
			if($condition_count !== 0)
515
			{
516
				$where = '(' . $where . ') ';
517
			}
518
519
			foreach($this->orderby as $order)
520
			{
521
				$colName = $order->getColumnName();
522
				if(strstr($colName, 'list_order') || strstr($colName, 'update_order'))
523
				{
524
					$opt_condition = new ConditionWithoutArgument($colName, 2100000000, 'less', 'and');
525
					if($condition_count === 0)
526
					{
527
						$opt_condition->setPipe("");
528
					}
529
					$where .= $opt_condition->toString($with_values) . ' ';
530
					$condition_count++;
531
				}
532
			}
533
		}
534
535
		return trim($where);
536
	}
537
538
	/**
539
	 * Return groupby sql
540
	 * @return string
541
	 */
542
	function getGroupByString()
543
	{
544
		$groupBy = '';
545
		if($this->groups)
546
		{
547
			if($this->groups[0] !== "")
548
			{
549
				$groupBy = implode(', ', $this->groups);
550
			}
551
		}
552
		return $groupBy;
553
	}
554
555
	/**
556
	 * Return orderby sql
557
	 * @return string
558
	 */
559
	function getOrderByString()
560
	{
561
		if(!$this->_orderByString)
562
		{
563
			if(!is_array($this->orderby) || count($this->orderby) === 0)
564
			{
565
				return '';
566
			}
567
			$orderBy = '';
568
			foreach($this->orderby as $order)
569
			{
570
				$orderBy .= $order->toString() . ', ';
571
			}
572
			$orderBy = substr($orderBy, 0, -2);
573
			$this->_orderByString = $orderBy;
574
		}
575
		return $this->_orderByString;
576
	}
577
578
	function getLimit()
579
	{
580
		return $this->limit;
581
	}
582
583
	/**
584
	 * Return limit sql
585
	 * @return string
586
	 */
587
	function getLimitString()
588
	{
589
		$limit = '';
590
		if($this->limit)
591
		{
592
			$limit = '';
593
			$limit .= $this->limit->toString();
0 ignored issues
show
Bug introduced by
The method toString cannot be called on $this->limit (of type integer).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
594
		}
595
		return $limit;
596
	}
597
598
	function getFirstTableName()
599
	{
600
		return $this->tables[0]->getName();
601
	}
602
603
	/**
604
	 * Return argument list
605
	 * @return array
606
	 */
607
	function getArguments()
608
	{
609
		if(!isset($this->arguments))
610
		{
611
			$this->arguments = array();
612
613
			// Join table arguments
614 View Code Duplication
			if(is_array($this->tables) && count($this->tables) > 0)
615
			{
616
				foreach($this->tables as $table)
617
				{
618
					if($table->isJoinTable() || is_a($table, 'Subquery'))
619
					{
620
						$args = $table->getArguments();
621
						if($args)
622
						{
623
							$this->arguments = array_merge($this->arguments, $args);
624
						}
625
					}
626
				}
627
			}
628
629
			// Column arguments
630
			// The if is for delete statements, all others must have columns
631 View Code Duplication
			if(is_array($this->columns) && count($this->columns) > 0)
632
			{
633
				foreach($this->columns as $column)
634
				{
635
					if($column->show())
636
					{
637
						$args = $column->getArguments();
638
						if($args)
639
						{
640
							$this->arguments = array_merge($this->arguments, $args);
641
						}
642
					}
643
				}
644
			}
645
646
			// Condition arguments
647 View Code Duplication
			if(is_array($this->conditions) && count($this->conditions) > 0)
648
			{
649
				foreach($this->conditions as $conditionGroup)
650
				{
651
					$args = $conditionGroup->getArguments();
652
					if(count($args) > 0)
653
					{
654
						$this->arguments = array_merge($this->arguments, $args);
655
					}
656
				}
657
			}
658
659
			// Navigation arguments
660 View Code Duplication
			if(is_array($this->orderby) && count($this->orderby) > 0)
661
			{
662
				foreach($this->orderby as $order)
663
				{
664
					$args = $order->getArguments();
665
					if(count($args) > 0)
666
					{
667
						$this->arguments = array_merge($this->arguments, $args);
668
					}
669
				}
670
			}
671
		}
672
		return $this->arguments;
673
	}
674
675
}
676
/* End of file Query.class.php */
677
/* Location: ./classes/db/queryparts/Query.class.php */
678