| Conditions | 23 |
| Paths | 4656 |
| Total Lines | 127 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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 |
||
| 65 | protected function getQuery(\Xhgui_Storage_Filter $filter, $count = false) |
||
| 66 | { |
||
| 67 | $params = []; |
||
| 68 | |||
| 69 | if ($count === true) { |
||
| 70 | $columns = ' count(*) as c '; |
||
| 71 | } else { |
||
| 72 | $columns = ' p.*, i.*, m.*, p.profile_id as _id, main_wt as duration '; |
||
| 73 | } |
||
| 74 | |||
| 75 | $sql = " |
||
| 76 | select |
||
| 77 | $columns |
||
| 78 | from |
||
| 79 | profiles as p left join |
||
| 80 | profiles_info as i on (p.profile_id = i.id) LEFT JOIN |
||
| 81 | profiles_meta as m on (p.profile_id = m.profile_id) |
||
| 82 | "; |
||
| 83 | |||
| 84 | $where = []; |
||
| 85 | |||
| 86 | foreach ([ |
||
| 87 | 'url' => 'url', |
||
| 88 | 'method' => 'method', |
||
| 89 | 'application' => 'application', |
||
| 90 | 'version' => 'version', |
||
| 91 | 'branch' => 'branch', |
||
| 92 | 'controller' => 'controller', |
||
| 93 | 'action' => 'action', |
||
| 94 | ] as $dbField => $field) { |
||
| 95 | $method = 'get'.ucfirst($field); |
||
| 96 | |||
| 97 | if ($filter->{$method}()) { |
||
| 98 | $where[] = ' '.$dbField.' = :'.$field.' '; |
||
| 99 | $params[$field] = $filter->{$method}(); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | if ($filter->getStartDate()) { |
||
| 104 | $where[] = ' request_time >= :startDate'; |
||
| 105 | $params['startDate'] = $this->getDateTimeFromString($filter->getStartDate(), 'start') |
||
|
|
|||
| 106 | ->format('Y-m-d H:i:s'); |
||
| 107 | } |
||
| 108 | |||
| 109 | if ($filter->getEndDate()) { |
||
| 110 | $where[] = ' request_time <= :endDate'; |
||
| 111 | $params['endDate'] = $this->getDateTimeFromString($filter->getEndDate(), 'end') |
||
| 112 | ->format('Y-m-d H:i:s'); |
||
| 113 | } |
||
| 114 | |||
| 115 | if (!empty($where)) { |
||
| 116 | $sql .= ' WHERE '.join(' AND ', $where); |
||
| 117 | } |
||
| 118 | |||
| 119 | if ($count === true) { |
||
| 120 | return [$sql, $params]; |
||
| 121 | } |
||
| 122 | |||
| 123 | switch ($filter->getSort()) { |
||
| 124 | case 'ct': |
||
| 125 | $sql .= ' order by main_ct'; |
||
| 126 | break; |
||
| 127 | |||
| 128 | case 'wt': |
||
| 129 | $sql .= ' order by main_wt'; |
||
| 130 | break; |
||
| 131 | |||
| 132 | case 'cpu': |
||
| 133 | $sql .= ' order by main_cpu'; |
||
| 134 | break; |
||
| 135 | |||
| 136 | case 'mu': |
||
| 137 | $sql .= ' order by main_mu'; |
||
| 138 | break; |
||
| 139 | |||
| 140 | case 'pmu': |
||
| 141 | $sql .= ' order by main_pmu'; |
||
| 142 | break; |
||
| 143 | |||
| 144 | case 'controller': |
||
| 145 | $sql .= ' order by controller'; |
||
| 146 | break; |
||
| 147 | |||
| 148 | case 'action': |
||
| 149 | $sql .= ' order by action'; |
||
| 150 | break; |
||
| 151 | |||
| 152 | case 'application': |
||
| 153 | $sql .= ' order by application'; |
||
| 154 | break; |
||
| 155 | |||
| 156 | case 'branch': |
||
| 157 | $sql .= ' order by branch'; |
||
| 158 | break; |
||
| 159 | |||
| 160 | case 'version': |
||
| 161 | $sql .= ' order by version'; |
||
| 162 | break; |
||
| 163 | |||
| 164 | case 'time': |
||
| 165 | default: |
||
| 166 | $sql .= ' order by request_time'; |
||
| 167 | break; |
||
| 168 | } |
||
| 169 | |||
| 170 | switch ($filter->getDirection()) { |
||
| 171 | case 'asc': |
||
| 172 | $sql .= ' asc '; |
||
| 173 | break; |
||
| 174 | |||
| 175 | default: |
||
| 176 | case 'desc': |
||
| 177 | $sql .= ' desc '; |
||
| 178 | break; |
||
| 179 | } |
||
| 180 | |||
| 181 | if ($filter->getPerPage()) { |
||
| 182 | $sql .= ' LIMIT :limit '; |
||
| 183 | $params['limit'] = (int)$filter->getPerPage(); |
||
| 184 | } |
||
| 185 | |||
| 186 | if ($filter->getPage()) { |
||
| 187 | $sql .= ' OFFSET :offset '; |
||
| 188 | $params['offset'] = (int)($filter->getPerPage()*($filter->getPage()-1)); |
||
| 189 | } |
||
| 190 | return [$sql, $params]; |
||
| 191 | } |
||
| 192 | |||
| 393 |
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: