Conditions | 10 |
Paths | 10 |
Total Lines | 41 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 1 | Features | 1 |
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 |
||
31 | private function loadFile($path, SchemaContainer $schemaContainer) |
||
32 | { |
||
33 | $config = Yaml::parse($this->getFileContent($path)); |
||
34 | |||
35 | foreach ($config as $type => $mapping) { |
||
36 | switch ($type) { |
||
37 | case 'query': |
||
38 | $querySchema = $schemaContainer->getQuerySchema(); |
||
39 | if (null === $querySchema) { |
||
40 | $querySchema = new Query(); |
||
41 | $schemaContainer->setQuerySchema($querySchema); |
||
42 | } |
||
43 | |||
44 | $this->populateFieldContainer($querySchema, $mapping); |
||
45 | break; |
||
46 | case 'mutation': |
||
47 | $mutationSchema = $schemaContainer->getMutationSchema(); |
||
48 | if (null === $mutationSchema) { |
||
49 | $mutationSchema = new Query(); |
||
50 | $schemaContainer->setMutationSchema($mutationSchema); |
||
51 | } |
||
52 | |||
53 | $this->populateFieldContainer($mutationSchema, $mapping); |
||
54 | break; |
||
55 | case 'types': |
||
56 | foreach ($mapping as $name => $typeMapping) { |
||
57 | $type = $this->createType($name, $typeMapping); |
||
58 | $schemaContainer->addType($type); |
||
59 | } |
||
60 | break; |
||
61 | case 'interfaces': |
||
62 | foreach ($mapping as $name => $interfaceMapping) { |
||
63 | $interface = $this->createInterface($name, $interfaceMapping); |
||
64 | $schemaContainer->addInterface($interface); |
||
65 | } |
||
66 | break; |
||
67 | default: |
||
68 | throw new \UnexpectedValueException(sprintf('Unsupported key "%s"')); |
||
69 | } |
||
70 | } |
||
71 | } |
||
72 | |||
162 |