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