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