| Conditions | 5 |
| Paths | 4 |
| Total Lines | 69 |
| Code Lines | 41 |
| 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 |
||
| 113 | public function getNonautomatedEdits($project, $username, $namespace, $offset = 0) |
||
| 114 | { |
||
| 115 | $project = ProjectRepository::getProject($project, $this->container); |
||
| 116 | $namespaces = $project->getNamespaces(); |
||
| 117 | |||
| 118 | $conn = $this->container->get('doctrine')->getManager('replicas')->getConnection(); |
||
| 119 | |||
| 120 | $lh = $this->container->get('app.labs_helper'); |
||
| 121 | $revTable = $lh->getTable('revision', $project->getDatabaseName()); |
||
| 122 | $pageTable = $lh->getTable('page', $project->getDatabaseName()); |
||
| 123 | |||
| 124 | $AEBTypes = $this->container->getParameter('automated_tools'); |
||
| 125 | $allAETools = $conn->quote(implode('|', $AEBTypes), \PDO::PARAM_STR); |
||
| 126 | |||
| 127 | $namespaceClause = $namespace === 'all' ? '' : "AND rev_namespace = $namespace"; |
||
| 128 | |||
| 129 | // First get the non-automated contribs |
||
| 130 | $query = "SELECT page_title, page_namespace, rev_id, rev_len, rev_parent_id, |
||
| 131 | rev_timestamp, rev_minor_edit, rev_comment |
||
| 132 | FROM $pageTable JOIN $revTable ON page_id = rev_page |
||
| 133 | WHERE rev_user_text = :username |
||
| 134 | AND rev_timestamp > 0 |
||
| 135 | AND rev_comment NOT RLIKE $allAETools |
||
| 136 | ORDER BY rev_id DESC |
||
| 137 | LIMIT 50 |
||
| 138 | OFFSET $offset"; |
||
| 139 | $editData = $conn->executeQuery($query, ['username' => $username])->fetchAll(); |
||
| 140 | |||
| 141 | // Get diff sizes, based on length of each parent revision |
||
| 142 | $parentRevIds = array_map(function ($edit) { |
||
| 143 | return $edit['rev_parent_id']; |
||
| 144 | }, $editData); |
||
| 145 | $query = "SELECT rev_len, rev_id |
||
| 146 | FROM revision |
||
| 147 | WHERE rev_id IN (" . implode(',', $parentRevIds) . ")"; |
||
| 148 | $diffSizeData = $conn->executeQuery($query)->fetchAll(); |
||
| 149 | |||
| 150 | // reformat with rev_id as the key, rev_len as the value |
||
| 151 | $diffSizes = []; |
||
| 152 | foreach ($diffSizeData as $diff) { |
||
| 153 | $diffSizes[$diff['rev_id']] = $diff['rev_len']; |
||
| 154 | } |
||
| 155 | |||
| 156 | // Build our array of nonautomated edits |
||
| 157 | $editData = array_map(function ($edit) use ($namespaces, $diffSizes) { |
||
| 158 | $pageTitle = $edit['page_title']; |
||
| 159 | |||
| 160 | if ($edit['page_namespace'] !== '0') { |
||
| 161 | $pageTitle = $namespaces[$edit['page_namespace']] . ":$pageTitle"; |
||
| 162 | } |
||
| 163 | |||
| 164 | $diffSize = $edit['rev_len']; |
||
| 165 | if ($edit['rev_parent_id'] > 0) { |
||
| 166 | $diffSize = $edit['rev_len'] - $diffSizes[$edit['rev_parent_id']]; |
||
| 167 | } |
||
| 168 | |||
| 169 | return [ |
||
| 170 | 'page_title' => $pageTitle, |
||
| 171 | 'namespace' => (int) $edit['page_namespace'], |
||
| 172 | 'rev_id' => (int) $edit['rev_id'], |
||
| 173 | 'timestamp' => DateTime::createFromFormat('YmdHis', $edit['rev_timestamp']), |
||
| 174 | 'minor_edit' => (bool) $edit['rev_minor_edit'], |
||
| 175 | 'summary' => $edit['rev_comment'], |
||
| 176 | 'size' => $diffSize |
||
| 177 | ]; |
||
| 178 | }, $editData); |
||
| 179 | |||
| 180 | return $editData; |
||
| 181 | } |
||
| 182 | } |
||
| 183 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.