| Conditions | 13 |
| Paths | 55 |
| Total Lines | 51 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 84 | private function resolveActualType(ResourceAttributeMetadata $attributeMetadata) |
||
| 85 | { |
||
| 86 | $originalTypeClass = ltrim($attributeMetadata->getOriginalType(), '\\'); |
||
| 87 | |||
| 88 | if (in_array($originalTypeClass, [\DateTime::class, \DateTimeImmutable::class, \DateTimeInterface::class], true)) { |
||
| 89 | return [DataTypes::DATETIME, null]; |
||
| 90 | } |
||
| 91 | |||
| 92 | $type = $attributeMetadata->getType(); |
||
| 93 | |||
| 94 | $actualType = null; |
||
| 95 | $subType = null; |
||
| 96 | |||
| 97 | // If it's a collection of models |
||
| 98 | if (false !== strpos($type, '[]')) { |
||
| 99 | $actualType = DataTypes::COLLECTION; |
||
| 100 | } elseif (class_exists($type)) { |
||
| 101 | $actualType = DataTypes::MODEL; |
||
| 102 | } |
||
| 103 | |||
| 104 | $type = str_replace('[]', '', $type, $count); |
||
| 105 | |||
| 106 | switch ($type) { |
||
| 107 | case 'bool': |
||
| 108 | case 'boolean': |
||
| 109 | $type = DataTypes::BOOLEAN; |
||
| 110 | break; |
||
| 111 | case 'int': |
||
| 112 | case 'integer': |
||
| 113 | $type = DataTypes::INTEGER; |
||
| 114 | break; |
||
| 115 | case 'double': |
||
| 116 | case 'float': |
||
| 117 | $type = DataTypes::FLOAT; |
||
| 118 | break; |
||
| 119 | case 'file': |
||
| 120 | $type = DataTypes::FILE; |
||
| 121 | break; |
||
| 122 | case 'string': |
||
| 123 | $type = DataTypes::STRING; |
||
| 124 | break; |
||
| 125 | } |
||
| 126 | |||
| 127 | if (in_array($actualType, [DataTypes::COLLECTION, DataTypes::MODEL])) { |
||
| 128 | $subType = $type; |
||
| 129 | } else { |
||
| 130 | $actualType = $type; |
||
| 131 | } |
||
| 132 | |||
| 133 | return [$actualType, $subType]; |
||
| 134 | } |
||
| 135 | } |
||
| 136 |