Conditions | 17 |
Paths | 240 |
Total Lines | 79 |
Code Lines | 41 |
Lines | 0 |
Ratio | 0 % |
Changes | 12 | ||
Bugs | 2 | Features | 8 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
64 | public function read(QueryObject $queryObject) |
||
65 | { |
||
66 | $query = $this->newQuery(); |
||
67 | |||
68 | // Setup select statements |
||
69 | if (! empty($queryObject->getSelects())) { |
||
70 | $query->cols($queryObject->getSelects()); |
||
71 | } else { |
||
72 | $query->cols(['*']); |
||
73 | } |
||
74 | |||
75 | // Workarounds :-/ |
||
76 | if (! empty($queryObject->getFlags())) { |
||
77 | if ($queryObject->getFlags() === 'outfitIDs') { |
||
78 | // Prevent the VS, NC and TR "no outfit" workaround |
||
79 | $queryObject->addWhere([ |
||
80 | 'col' => 'outfitID', |
||
81 | 'op' => '>', |
||
82 | 'value' => 0 |
||
83 | ]); |
||
84 | } |
||
85 | } |
||
86 | |||
87 | // Setup where statements |
||
88 | if (! empty($queryObject->getWheres())) { |
||
89 | foreach ($queryObject->getWheres() as $where) { |
||
90 | $col = $where['col']; |
||
91 | |||
92 | if ($where['col'] === 'primary') { |
||
93 | $col = $this->getPrimaryKey(); |
||
94 | } |
||
95 | if ($where['col'] === 'result') { |
||
96 | $col = $this->getResultKey(); |
||
97 | } |
||
98 | |||
99 | $op = (isset($where['op']) ? $where['op'] : '='); |
||
100 | |||
101 | $query->where("{$col} {$op} :{$col}"); |
||
102 | $query->bindValue($col, $where['value']); |
||
103 | } |
||
104 | } |
||
105 | |||
106 | // Setup where statements |
||
107 | if (! empty($queryObject->getWhereIns())) { |
||
108 | foreach ($queryObject->getWhereIns() as $whereIn) { |
||
109 | $col = $whereIn['col']; |
||
110 | |||
111 | if ($whereIn['col'] === 'primary') { |
||
112 | $col = $this->getPrimaryKey(); |
||
113 | } |
||
114 | if ($whereIn['col'] === 'result') { |
||
115 | $col = $this->getResultKey(); |
||
116 | } |
||
117 | |||
118 | $query->where("{$col} IN ({$whereIn['value']})"); |
||
119 | } |
||
120 | } |
||
121 | |||
122 | // Set up order statement |
||
123 | if (! empty($queryObject->getOrderBy())) { |
||
124 | $orderBy = $queryObject->getOrderBy(); |
||
125 | if ($orderBy === 'primary') { |
||
126 | $orderBy = $this->getPrimaryKey(); |
||
127 | } |
||
128 | if ($orderBy === 'result') { |
||
129 | $orderBy = $this->getResultKey(); |
||
130 | } |
||
131 | |||
132 | $query->orderBy([ |
||
1 ignored issue
–
show
|
|||
133 | "`{$orderBy}` {$queryObject->getOrderByDirection()}" |
||
134 | ]); |
||
135 | } |
||
136 | |||
137 | if (! empty($queryObject->getLimit())) { |
||
138 | $query->limit($queryObject->getLimit()); |
||
139 | } |
||
140 | |||
141 | return $this->prepareAndExecuteQuery($query, $queryObject); |
||
142 | } |
||
143 | |||
162 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.