| Conditions | 10 |
| Paths | 8 |
| Total Lines | 30 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 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 |
||
| 116 | public final function setAttribute(string $key, $value): MetadataInterface |
||
| 117 | { |
||
| 118 | $timezone = new DateTimeZone('UTC'); |
||
| 119 | |||
| 120 | switch(mb_strtolower($key)) |
||
| 121 | { |
||
| 122 | case 'content-type': |
||
| 123 | $mime = $value ? preg_split('/;\s+/', $value) : []; |
||
| 124 | $this->mime = array_shift($mime); |
||
|
|
|||
| 125 | break; |
||
| 126 | |||
| 127 | case 'creation-date': |
||
| 128 | case 'date': |
||
| 129 | case 'meta:creation-date': |
||
| 130 | $value = preg_replace('/\.\d+/', 'Z', $value); |
||
| 131 | $this->created = new DateTime(is_array($value) ? array_shift($value) : $value, $timezone); |
||
| 132 | break; |
||
| 133 | |||
| 134 | case 'last-modified': |
||
| 135 | case 'modified': |
||
| 136 | $value = preg_replace('/\.\d+/', 'Z', $value); |
||
| 137 | $this->updated = new DateTime(is_array($value) ? array_shift($value) : $value, $timezone); |
||
| 138 | break; |
||
| 139 | |||
| 140 | default: |
||
| 141 | $this->setSpecificAttribute($key, $value); |
||
| 142 | |||
| 143 | } |
||
| 144 | |||
| 145 | return $this; |
||
| 146 | } |
||
| 155 |