| Conditions | 13 |
| Paths | 14 |
| Total Lines | 59 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | 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 |
||
| 186 | private function calculatePropertiesToBeApplied( |
||
| 187 | \DOMElement $element, |
||
| 188 | array $properties |
||
| 189 | ) { |
||
| 190 | if (empty($properties)) { |
||
| 191 | return $element; |
||
| 192 | } |
||
| 193 | |||
| 194 | $cssProperties = array(); |
||
| 195 | $currentStyles = $element->attributes->getNamedItem('data-css-to-inline-styles'); |
||
| 196 | |||
| 197 | if ($currentStyles !== null) { |
||
| 198 | $currentProperties = unserialize( |
||
| 199 | base64_decode( |
||
| 200 | $currentStyles->value |
||
| 201 | ) |
||
| 202 | ); |
||
| 203 | |||
| 204 | foreach ($currentProperties as $property) { |
||
| 205 | $cssProperties[$property->getName()] = $property; |
||
| 206 | } |
||
| 207 | } |
||
| 208 | |||
| 209 | foreach ($properties as $property) { |
||
| 210 | if (isset($cssProperties[$property->getName()])) { |
||
| 211 | $existingProperty = $cssProperties[$property->getName()]; |
||
| 212 | |||
| 213 | if ( |
||
| 214 | ($existingProperty->isImportant() && $property->isImportant()) && |
||
| 215 | ($existingProperty->getOriginalSpecificity()->compareTo($property->getOriginalSpecificity()) <= 0) |
||
| 216 | ) { |
||
| 217 | // if both the properties are important we should use the specificity |
||
| 218 | $cssProperties[$property->getName()] = $property; |
||
| 219 | } elseif (!$existingProperty->isImportant() && $property->isImportant()) { |
||
| 220 | // if the existing property is not important but the new one is, it should be overruled |
||
| 221 | $cssProperties[$property->getName()] = $property; |
||
| 222 | } elseif ( |
||
| 223 | !$existingProperty->isImportant() && |
||
| 224 | ($existingProperty->getOriginalSpecificity()->compareTo($property->getOriginalSpecificity()) <= 0) |
||
| 225 | ) { |
||
| 226 | // if the existing property is not important we should check the specificity |
||
| 227 | $cssProperties[$property->getName()] = $property; |
||
| 228 | } |
||
| 229 | } else { |
||
| 230 | $cssProperties[$property->getName()] = $property; |
||
| 231 | } |
||
| 232 | } |
||
| 233 | |||
| 234 | $element->setAttribute( |
||
| 235 | 'data-css-to-inline-styles', |
||
| 236 | base64_encode( |
||
| 237 | serialize( |
||
| 238 | array_values($cssProperties) |
||
| 239 | ) |
||
| 240 | ) |
||
| 241 | ); |
||
| 242 | |||
| 243 | return $element; |
||
| 244 | } |
||
| 245 | } |
||
| 246 |