| Conditions | 7 |
| Paths | 7 |
| Total Lines | 61 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 24 | public function setConsole(Console $console) |
||
| 25 | { |
||
| 26 | $console_data = array( |
||
| 27 | 'messages' => array(), |
||
| 28 | 'count' => array( |
||
| 29 | 'log' => 0, |
||
| 30 | 'memory' => 0, |
||
| 31 | 'error' => 0, |
||
| 32 | 'speed' => 0 |
||
| 33 | ) |
||
| 34 | ); |
||
| 35 | foreach ($console->getLogs() as $log) { |
||
| 36 | switch($log['type']) { |
||
| 37 | case 'log': |
||
| 38 | $message = array( |
||
| 39 | 'data' => print_r($log['data'], true), |
||
| 40 | 'type' => 'log' |
||
| 41 | ); |
||
| 42 | $console_data['count']['log']++; |
||
| 43 | break; |
||
| 44 | case 'memory': |
||
| 45 | $message = array( |
||
| 46 | 'name' => $log['name'], |
||
| 47 | 'data' => self::getReadableMemory($log['data']), |
||
| 48 | 'type' => 'memory' |
||
| 49 | ); |
||
| 50 | if (!empty($log['data_type'])) { |
||
| 51 | $message['data_type'] = $log['data_type']; |
||
| 52 | } |
||
| 53 | $console_data['count']['memory']++; |
||
| 54 | break; |
||
| 55 | case 'error': |
||
| 56 | $message = array( |
||
| 57 | 'data' => $log['data'], |
||
| 58 | 'file' => $log['file'], |
||
| 59 | 'line' => $log['line'], |
||
| 60 | 'type' => 'error' |
||
| 61 | ); |
||
| 62 | $console_data['count']['error']++; |
||
| 63 | break; |
||
| 64 | case 'speed': |
||
| 65 | $elapsedTime = $log['data'] - $this->startTime; |
||
|
|
|||
| 66 | $message = array( |
||
| 67 | 'name' => $log['name'], |
||
| 68 | 'data' => self::getReadableTime($elapsedTime), |
||
| 69 | 'type' => 'speed' |
||
| 70 | ); |
||
| 71 | $console_data['count']['speed']++; |
||
| 72 | break; |
||
| 73 | default: |
||
| 74 | $message = array( |
||
| 75 | 'data' => "Unrecognized console log type: {$log['type']}", |
||
| 76 | 'type' => 'error' |
||
| 77 | ); |
||
| 78 | $console_data['count']['error']++; |
||
| 79 | break; |
||
| 80 | } |
||
| 81 | array_push($console_data['messages'], $message); |
||
| 82 | } |
||
| 83 | $this->output['console'] = $console_data; |
||
| 84 | } |
||
| 85 | |||
| 218 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: