| Conditions | 19 |
| Paths | 288 |
| Total Lines | 48 |
| Code Lines | 27 |
| 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 |
||
| 40 | public function create(string $resourceClass, string $name, array $options = []): PropertyMetadata |
||
| 41 | { |
||
| 42 | if (null === $this->decorated) { |
||
| 43 | $propertyMetadata = new PropertyMetadata(); |
||
| 44 | } else { |
||
| 45 | try { |
||
| 46 | $propertyMetadata = $this->decorated->create($resourceClass, $name, $options); |
||
| 47 | } catch (PropertyNotFoundException $propertyNotFoundException) { |
||
| 48 | $propertyMetadata = new PropertyMetadata(); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | if (null === $propertyMetadata->getType()) { |
||
| 53 | $types = $this->propertyInfo->getTypes($resourceClass, $name, $options); |
||
| 54 | if (isset($types[0])) { |
||
| 55 | $propertyMetadata = $propertyMetadata->withType($types[0]); |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | if (null === $propertyMetadata->getDescription() && null !== $description = $this->propertyInfo->getShortDescription($resourceClass, $name, $options)) { |
||
| 60 | $propertyMetadata = $propertyMetadata->withDescription($description); |
||
| 61 | } |
||
| 62 | |||
| 63 | if (null === $propertyMetadata->isReadable() && null !== $readable = $this->propertyInfo->isReadable($resourceClass, $name, $options)) { |
||
| 64 | $propertyMetadata = $propertyMetadata->withReadable($readable); |
||
| 65 | } |
||
| 66 | |||
| 67 | if (null === $propertyMetadata->isWritable() && null !== $writable = $this->propertyInfo->isWritable($resourceClass, $name, $options)) { |
||
| 68 | $propertyMetadata = $propertyMetadata->withWritable($writable); |
||
| 69 | } |
||
| 70 | |||
| 71 | if (method_exists($this->propertyInfo, 'isInitializable')) { |
||
| 72 | if (null === $propertyMetadata->isInitializable() && null !== $initializable = $this->propertyInfo->isInitializable($resourceClass, $name, $options)) { |
||
| 73 | $propertyMetadata = $propertyMetadata->withInitializable($initializable); |
||
| 74 | } |
||
| 75 | } else { |
||
| 76 | // BC layer for Symfony < 4.2 |
||
| 77 | $ref = new \ReflectionClass($resourceClass); |
||
| 78 | if ($ref->isInstantiable() && $constructor = $ref->getConstructor()) { |
||
| 79 | foreach ($constructor->getParameters() as $constructorParameter) { |
||
| 80 | if ($constructorParameter->name === $name && null === $propertyMetadata->isInitializable()) { |
||
| 81 | $propertyMetadata = $propertyMetadata->withInitializable(true); |
||
| 82 | } |
||
| 83 | } |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | return $propertyMetadata; |
||
| 88 | } |
||
| 90 |