| Conditions | 13 |
| Paths | 21 |
| Total Lines | 67 |
| Code Lines | 45 |
| 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 |
||
| 142 | public function cacheSnapshot() |
||
| 143 | { |
||
| 144 | $domain = $this->getDomain(); |
||
| 145 | if ($domain == Domain::Course()) { |
||
| 146 | return $this->history->cacheHistory(); |
||
| 147 | } else { |
||
| 148 | $courseId = $this->getCourseId(); |
||
| 149 | $timestamp = $this->getTimestamp(); |
||
| 150 | if (empty(static::$data[$courseId][$domain][$timestamp])) { |
||
| 151 | $cache->pushKey(($domain == Domain::DEPARTMENT() ? $this->getDepartmentId() : 'school')); |
||
| 152 | static::$data[$courseId][$domain][$timestamp] = $cache->getCache($timestamp); |
||
| 153 | $this->averages = $cache->getCache("$timestamp-averages"); |
||
| 154 | if (empty(static::$data[$courseId][$domain][$timestamp])) { |
||
| 155 | if ($response = $this->mysql_query(" |
||
| 156 | SELECT * FROM `course_statistics` |
||
| 157 | WHERE |
||
| 158 | " . ($domain == Domain::DEPARTMENT() ? |
||
| 159 | "`course[account_id]` = '" . $this->getDepartmentId() . "' AND" : |
||
| 160 | '' |
||
| 161 | ) . " |
||
| 162 | `timestamp` LIKE '$timestamp%' |
||
| 163 | GROUP BY |
||
| 164 | `course[id]` |
||
| 165 | ORDER BY |
||
| 166 | `timestamp` DESC |
||
| 167 | ")) { |
||
| 168 | $total = [ |
||
| 169 | self::AVERAGE_TURN_AROUND => 0, |
||
| 170 | self::AVERAGE_ASSIGNMENT_COUNT => 0 |
||
| 171 | ]; |
||
| 172 | $divisor = [ |
||
| 173 | self::AVERAGE_TURN_AROUND => 0, |
||
| 174 | self::AVERAGE_ASSIGNMENT_COUNT => $response->num_rows |
||
| 175 | ]; |
||
| 176 | |||
| 177 | while ($row = $response->fetch_assoc()) { |
||
| 178 | static::$data[$courseId][$domain][$timestamp][] = $row; |
||
| 179 | |||
| 180 | $total[self::AVERAGE_TURN_AROUND] += |
||
| 181 | $row['average_grading_turn_around'] * |
||
| 182 | $row['student_count'] * |
||
| 183 | $row['graded_assignment_count']; |
||
| 184 | $divisor[self::AVERAGE_TURN_AROUND] += |
||
| 185 | $row['student_count'] * |
||
| 186 | $row['graded_assignment_count']; |
||
| 187 | |||
| 188 | $total[self::AVERAGE_ASSIGNMENT_COUNT] += |
||
| 189 | $row['assignments_due_count'] + |
||
| 190 | $row['dateless_assignment_count']; |
||
| 191 | } |
||
| 192 | |||
| 193 | for ($i = 0; $i < count($total); $i++) { |
||
| 194 | $this->averages[$i] = $total[$i] / $divisor[$i]; |
||
| 195 | } |
||
| 196 | |||
| 197 | $cache->setCache($timestamp, static::$data[$courseId][$domain][$timestamp]); |
||
| 198 | $cache->setCache("$timestamp-averages", $this->averages); |
||
| 199 | } |
||
| 200 | } |
||
| 201 | } |
||
| 202 | return is_array(static::$data) && |
||
| 203 | is_array(static::$data[$courseId]) && |
||
| 204 | is_array(static::$data[$courseId][$domain]) && |
||
| 205 | is_array(static::$data[$courseId][$domain][$timestamp]) && |
||
| 206 | count(static::$data[$courseId][$domain][$timestamp]) > 0; |
||
| 207 | } |
||
| 208 | } |
||
| 209 | } |
||
| 210 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..