1 | <?php |
||
8 | class Condition |
||
9 | { |
||
10 | protected $_string; |
||
11 | protected $_values; |
||
12 | protected $_query; |
||
13 | |||
14 | /** |
||
15 | * @param string $string |
||
16 | */ |
||
17 | 6 | public function __construct($string, $values = array()) |
|
22 | |||
23 | 5 | public function __toString() |
|
27 | |||
28 | 5 | public function getString() |
|
32 | |||
33 | /** |
||
34 | * Parses $string and replaces all instances of "?" with corresponding $values |
||
35 | * |
||
36 | * @param string $string |
||
37 | * @param array $values |
||
38 | * @return string |
||
39 | */ |
||
40 | 5 | public function parseString($string, $values) |
|
41 | { |
||
42 | 5 | $positions = []; |
|
43 | 5 | $pos = 0; |
|
|
|||
44 | 5 | $offset = 0; |
|
45 | |||
46 | 5 | while (($pos = strpos($string, "?", $offset)) !== false) { |
|
47 | $positions[] = $pos; |
||
48 | $offset = $pos + 1; |
||
49 | } |
||
50 | |||
51 | 5 | $count = count($positions); |
|
52 | |||
53 | 5 | if ($count == 1) { |
|
54 | $values = array($values); |
||
55 | } |
||
56 | |||
57 | 5 | for ($i = 0; $i < $count; $i++) { |
|
58 | $value = $values[$i]; |
||
59 | if ($value instanceof Query) { |
||
60 | $value = $this->parseValueQuery($value); |
||
61 | } elseif (is_array($value)) { |
||
62 | foreach ($value as $key => $subvalue) { |
||
63 | if (trim($subvalue) != '') { |
||
64 | $value[$key] = is_numeric($subvalue) ? $subvalue : $this->getQuery()->getManager()->getAdapter()->quote($subvalue); |
||
65 | } else { |
||
66 | unset($value[$key]); |
||
67 | } |
||
68 | } |
||
69 | $value = "(" . implode(", ", $value) . ")"; |
||
70 | } elseif (is_numeric($value)) { |
||
71 | } else { |
||
72 | $value = $this->getQuery()->getManager()->getAdapter()->quote($values[$i]); |
||
73 | } |
||
74 | $string = substr_replace($string, $value, strpos($string, '?'), 1); |
||
75 | } |
||
76 | |||
77 | 5 | return $string; |
|
78 | } |
||
79 | |||
80 | /** |
||
81 | * @param Query $value |
||
82 | */ |
||
83 | protected function parseValueQuery($value) |
||
84 | { |
||
85 | return "(" . $value->assemble() . ")"; |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * @return Query |
||
90 | */ |
||
91 | public function getQuery() |
||
92 | { |
||
93 | return $this->_query; |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * @param Query $query |
||
98 | * @return $this |
||
99 | */ |
||
100 | 6 | public function setQuery($query) |
|
106 | |||
107 | /** |
||
108 | * @param Condition $condition |
||
109 | */ |
||
110 | 2 | public function and_($condition) |
|
114 | |||
115 | /** |
||
116 | * @param Condition $condition |
||
117 | */ |
||
118 | 1 | public function or_($condition) |
|
122 | |||
123 | 3 | public function protectCondition($condition) |
|
127 | } |
||
128 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.