Conditions | 14 |
Paths | 399 |
Total Lines | 56 |
Code Lines | 30 |
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 |
||
39 | public function loadResourceMetadata(ResourceMetadata $resourceMetadata): bool |
||
40 | { |
||
41 | $class = $resourceMetadata->getClass(); |
||
42 | |||
43 | if (!class_exists($class)) { |
||
44 | return false; |
||
45 | } |
||
46 | |||
47 | $resourceMetadata->getDescription() ?: $resourceMetadata->setDescription($this->getClassDocBlock($class)); |
||
48 | |||
49 | foreach ((array) $this->extractor->getProperties($class) as $name) { |
||
50 | $attributeMetadata = $resourceMetadata->getAttribute($name) ?? new ResourceAttributeMetadata($name); |
||
51 | |||
52 | if (!empty($description = $this->extractor->getLongDescription($class, $name))) { |
||
53 | $attributeMetadata->getDescription() ?: $attributeMetadata->setDescription($description); |
||
54 | } |
||
55 | |||
56 | /** @var Type[] $types */ |
||
57 | $types = $this->extractor->getTypes($class, $name); |
||
58 | |||
59 | if (isset($types[0])) { |
||
60 | $type = $types[0]; |
||
61 | $attributeMetadata->setRequired(!$type->isNullable()); |
||
62 | |||
63 | $phpType = $types[0]->getBuiltinType(); |
||
64 | if ($type->isCollection()) { |
||
65 | $collectionValueType = $type->getCollectionValueType(); |
||
66 | |||
67 | if ($collectionValueType) { |
||
68 | if (Type::BUILTIN_TYPE_OBJECT === $collectionValueType->getBuiltinType()) { |
||
69 | $phpType = $collectionValueType->getClassName(); |
||
70 | } else { |
||
71 | $phpType = $collectionValueType->getBuiltinType(); |
||
72 | } |
||
73 | |||
74 | $phpType .= '[]'; |
||
75 | } |
||
76 | } |
||
77 | |||
78 | if (Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType()) { |
||
79 | $phpType = $type->getClassName(); |
||
80 | } |
||
81 | |||
82 | $attributeMetadata->getOriginalType() ?: $attributeMetadata->setOriginalType($phpType); |
||
83 | $attributeMetadata->getType() ?: $attributeMetadata->setType($phpType); |
||
84 | } |
||
85 | |||
86 | if ($description = $this->extractor->getShortDescription($class, $name)) { |
||
87 | $attributeMetadata->setDescription($description); |
||
88 | } |
||
89 | |||
90 | $resourceMetadata->addAttribute($attributeMetadata); |
||
91 | } |
||
92 | |||
93 | return true; |
||
94 | } |
||
95 | |||
115 |