| Conditions | 14 |
| Paths | 178 |
| Total Lines | 52 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 18 |
| CRAP Score | 24.6955 |
| Changes | 1 | ||
| 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 |
||
| 28 | 12 | protected function loadMetadataFromFile(\ReflectionClass $class, $file) |
|
| 29 | { |
||
| 30 | /** @var ClassMetadata $ddrRestClassMetadata */ |
||
| 31 | 12 | $classMetadata = $this->doctrineDriver->loadMetadataForClass($class); |
|
| 32 | 12 | if (null === $classMetadata) { |
|
| 33 | $classMetadata = new ClassMetadata($class->getName()); |
||
|
1 ignored issue
–
show
|
|||
| 34 | } |
||
| 35 | |||
| 36 | 12 | $config = Yaml::parse(file_get_contents($file)); |
|
| 37 | 12 | $className = key($config); |
|
| 38 | |||
| 39 | 12 | if ($className !== $class->name) { |
|
| 40 | throw new \RuntimeException( |
||
| 41 | sprintf('Class definition mismatch for "%s" in "%s": %s', $class->getName(), $file, key($config)) |
||
|
1 ignored issue
–
show
|
|||
| 42 | ); |
||
| 43 | } |
||
| 44 | |||
| 45 | 12 | $config = $config[$className]; |
|
| 46 | 12 | if (!is_array($config)) { |
|
| 47 | $config = []; |
||
| 48 | } |
||
| 49 | |||
| 50 | 12 | if (array_key_exists('rootResource', $config) && true === $config['rootResource']) { |
|
| 51 | 12 | $classMetadata->setRestResource(true); |
|
| 52 | } |
||
| 53 | |||
| 54 | 12 | $propertyConfigs = []; |
|
| 55 | 12 | if (array_key_exists('properties', $config)) { |
|
| 56 | $propertyConfigs = $config['properties']; |
||
| 57 | } |
||
| 58 | |||
| 59 | 12 | foreach ($class->getProperties() as $reflectionProperty) { |
|
| 60 | |||
| 61 | 12 | $propertyMetadata = $classMetadata->getPropertyMetadata($reflectionProperty->getName()); |
|
| 62 | 12 | if (null === $propertyMetadata) { |
|
| 63 | $propertyMetadata = new PropertyMetadata($class->getName(), $reflectionProperty->getName()); |
||
|
1 ignored issue
–
show
|
|||
| 64 | } |
||
| 65 | |||
| 66 | 12 | if (array_key_exists($reflectionProperty->getName(), $propertyConfigs)) { |
|
| 67 | $propertyConfig = $propertyConfigs[$reflectionProperty->getName()]; |
||
| 68 | if (array_key_exists('puttable', $propertyConfig) && true === $propertyConfig['puttable']) { |
||
| 69 | $propertyMetadata->setPuttable(true); |
||
| 70 | } |
||
| 71 | if (array_key_exists('postable', $propertyConfig) && true === $propertyConfig['postable']) { |
||
| 72 | $propertyMetadata->setPostable(true); |
||
| 73 | } |
||
| 74 | } |
||
| 75 | 12 | $classMetadata->addPropertyMetadata($propertyMetadata); |
|
| 76 | } |
||
| 77 | |||
| 78 | 12 | return $classMetadata; |
|
| 79 | } |
||
| 80 | |||
| 89 |