| Conditions | 18 |
| Paths | 360 |
| Total Lines | 87 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 14 | ||
| Bugs | 2 | Features | 10 |
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 |
||
| 68 | public function read(QueryObject $queryObject) |
||
| 69 | { |
||
| 70 | $query = $this->newQuery(); |
||
| 71 | |||
| 72 | // Setup select statements |
||
| 73 | if (! empty($queryObject->getSelects())) { |
||
| 74 | $query->cols($queryObject->getSelects()); |
||
| 75 | } else { |
||
| 76 | $query->cols(['*']); |
||
| 77 | } |
||
| 78 | |||
| 79 | // Workarounds :-/ |
||
| 80 | if (! empty($queryObject->getFlags())) { |
||
| 81 | if ($queryObject->getFlags() === 'outfitIDs') { |
||
| 82 | // Prevent the VS, NC and TR "no outfit" workaround |
||
| 83 | $queryObject->addWhere([ |
||
| 84 | 'col' => 'outfitID', |
||
| 85 | 'op' => '>', |
||
| 86 | 'value' => 0 |
||
| 87 | ]); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | // Setup where statements |
||
| 92 | if (! empty($queryObject->getWheres())) { |
||
| 93 | foreach ($queryObject->getWheres() as $where) { |
||
| 94 | $col = $where['col']; |
||
| 95 | |||
| 96 | if ($where['col'] === 'primary') { |
||
| 97 | $col = $this->getPrimaryKey(); |
||
| 98 | } |
||
| 99 | if ($where['col'] === 'result') { |
||
| 100 | $col = $this->getResultKey(); |
||
| 101 | } |
||
| 102 | |||
| 103 | // Generate a UUID so that any columns that are used multiple |
||
| 104 | // times always have unique values. Tiny overhead for the benefit |
||
| 105 | $uuid = $this->getUuidDriver()->uuid4()->toString(); |
||
| 106 | $bind = str_replace('-', '', $col.$uuid); |
||
| 107 | |||
| 108 | $op = (isset($where['op']) ? $where['op'] : '='); |
||
| 109 | |||
| 110 | $query->where("{$col} {$op} :$bind"); |
||
| 111 | $query->bindValue($bind, $where['value']); |
||
| 112 | } |
||
| 113 | } |
||
| 114 | |||
| 115 | // Setup where statements |
||
| 116 | if (! empty($queryObject->getWhereIns())) { |
||
| 117 | foreach ($queryObject->getWhereIns() as $whereIn) { |
||
| 118 | $col = $whereIn['col']; |
||
| 119 | |||
| 120 | if ($whereIn['col'] === 'primary') { |
||
| 121 | $col = $this->getPrimaryKey(); |
||
| 122 | } |
||
| 123 | if ($whereIn['col'] === 'result') { |
||
| 124 | $col = $this->getResultKey(); |
||
| 125 | } |
||
| 126 | |||
| 127 | $query->where("{$col} IN ({$whereIn['value']})"); |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | // Set up order statement |
||
| 132 | if (! empty($queryObject->getOrderBy())) { |
||
| 133 | $orderBy = $queryObject->getOrderBy(); |
||
| 134 | if ($orderBy === 'primary') { |
||
| 135 | $orderBy = $this->getPrimaryKey(); |
||
| 136 | } |
||
| 137 | if ($orderBy === 'result') { |
||
| 138 | $orderBy = $this->getResultKey(); |
||
| 139 | } |
||
| 140 | |||
| 141 | $query->orderBy([ |
||
|
1 ignored issue
–
show
|
|||
| 142 | "`{$orderBy}` {$queryObject->getOrderByDirection()}" |
||
| 143 | ]); |
||
| 144 | } |
||
| 145 | |||
| 146 | if (! empty($queryObject->getLimit())) { |
||
| 147 | // Only set a limit if it's required |
||
| 148 | if ($queryObject->getLimit() !== 'unlimited') { |
||
| 149 | $query->limit($queryObject->getLimit()); |
||
| 150 | } |
||
| 151 | } |
||
| 152 | |||
| 153 | return $this->prepareAndExecuteQuery($query, $queryObject); |
||
| 154 | } |
||
| 155 | |||
| 177 |
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.