Conditions | 17 |
Paths | 610 |
Total Lines | 63 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Tests | 20 |
CRAP Score | 34.6626 |
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 | 14 | protected function loadMetadataFromFile(\ReflectionClass $class, $file) |
|
29 | { |
||
30 | /** @var ClassMetadata $ddrRestClassMetadata */ |
||
31 | 14 | $classMetadata = $this->doctrineDriver->loadMetadataForClass($class); |
|
32 | 14 | if (null === $classMetadata) { |
|
33 | $classMetadata = new ClassMetadata($class->getName()); |
||
1 ignored issue
–
show
|
|||
34 | } |
||
35 | |||
36 | 14 | $config = Yaml::parse(file_get_contents($file)); |
|
37 | 14 | $className = key($config); |
|
38 | |||
39 | 14 | 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 | 14 | $config = $config[$className]; |
|
46 | 14 | if (!is_array($config)) { |
|
47 | $config = []; |
||
48 | } |
||
49 | |||
50 | 14 | if (array_key_exists('rootResource', $config) && true === $config['rootResource']) { |
|
51 | 14 | $classMetadata->setRestResource(true); |
|
52 | } |
||
53 | |||
54 | 14 | if (array_key_exists('service', $config)) { |
|
55 | 4 | $classMetadata->setService($config['service']); |
|
56 | } |
||
57 | |||
58 | 14 | $propertyConfigs = []; |
|
59 | 14 | if (array_key_exists('fields', $config)) { |
|
60 | $propertyConfigs = $config['fields']; |
||
61 | } |
||
62 | |||
63 | 14 | foreach ($class->getProperties() as $reflectionProperty) { |
|
64 | |||
65 | 12 | $propertyMetadata = $classMetadata->getPropertyMetadata($reflectionProperty->getName()); |
|
66 | 12 | if (null === $propertyMetadata) { |
|
67 | $propertyMetadata = new PropertyMetadata($class->getName(), $reflectionProperty->getName()); |
||
1 ignored issue
–
show
|
|||
68 | } |
||
69 | |||
70 | 12 | if (array_key_exists($reflectionProperty->getName(), $propertyConfigs)) { |
|
71 | |||
72 | $propertyConfig = $propertyConfigs[$reflectionProperty->getName()]; |
||
73 | |||
74 | if (array_key_exists('puttable', $propertyConfig) && true === $propertyConfig['puttable']) { |
||
75 | $propertyMetadata->setPuttable(true); |
||
76 | } |
||
77 | |||
78 | if (array_key_exists('excluded', $propertyConfig) && true === $propertyConfig['excluded']) { |
||
79 | $propertyMetadata->setExcluded(true); |
||
80 | } |
||
81 | |||
82 | if (array_key_exists('postable', $propertyConfig) && true === $propertyConfig['postable']) { |
||
83 | $propertyMetadata->setPostable(true); |
||
84 | } |
||
85 | } |
||
86 | 12 | $classMetadata->addPropertyMetadata($propertyMetadata); |
|
87 | } |
||
88 | |||
89 | 14 | return $classMetadata; |
|
90 | } |
||
91 | |||
100 |