Conditions | 14 |
Paths | 12 |
Total Lines | 36 |
Code Lines | 23 |
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 'dcterms:created': |
||
136 | case 'meta:creation-date': |
||
137 | $value = preg_replace('/\.\d+/', 'Z', $value); |
||
138 | $this->created = new DateTime(is_array($value) ? array_shift($value) : $value, $timezone); |
||
139 | break; |
||
140 | |||
141 | case 'dcterms:modified': |
||
142 | case 'last-modified': |
||
143 | case 'modified': |
||
144 | $value = preg_replace('/\.\d+/', 'Z', $value); |
||
145 | $this->updated = new DateTime(is_array($value) ? array_shift($value) : $value, $timezone); |
||
146 | break; |
||
147 | |||
148 | default: |
||
149 | $this->setSpecificAttribute($key, $value); |
||
150 | |||
151 | } |
||
152 | |||
153 | return $this; |
||
154 | } |
||
164 |