| Conditions | 10 |
| Paths | 29 |
| Total Lines | 39 |
| Code Lines | 26 |
| 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 |
||
| 64 | protected function load($dsl) |
||
| 65 | { |
||
| 66 | if (!isset($dsl['file'])) { |
||
| 67 | throw new \Exception("Invalid step definition: miss 'file' for loading references"); |
||
| 68 | } |
||
| 69 | $fileName = $dsl['file']; |
||
| 70 | |||
| 71 | $overwrite = isset($dsl['overwrite']) ? $overwrite = $dsl['overwrite'] : false; |
||
| 72 | |||
| 73 | $fileName = str_replace('{ENV}', $this->container->get('kernel')->getEnvironment(), $fileName); |
||
| 74 | if (!is_file($fileName)) { |
||
| 75 | throw new \Exception("Invalid step definition: invalid 'file' for loading references"); |
||
| 76 | } |
||
| 77 | $data = file_get_contents($fileName); |
||
| 78 | |||
| 79 | $ext = pathinfo($dsl['file'], PATHINFO_EXTENSION); |
||
| 80 | switch ($ext) { |
||
| 81 | case 'json': |
||
| 82 | $data = json_decode($data, true); |
||
| 83 | break; |
||
| 84 | case 'yml': |
||
| 85 | case 'yaml': |
||
| 86 | $data = Yaml::parse($data); |
||
| 87 | break; |
||
| 88 | default: |
||
| 89 | throw new \Exception("Invalid step definition: unsupported file extension for loading references from"); |
||
| 90 | } |
||
| 91 | |||
| 92 | if (!is_array($data)) { |
||
| 93 | throw new \Exception("Invalid step definition: file does not contain an array of key/value pairs"); |
||
| 94 | } |
||
| 95 | |||
| 96 | foreach ($data as $refName => $value) { |
||
| 97 | if (preg_match('/%.+%$/', $value)) { |
||
| 98 | $value = $this->container->getParameter(trim($value, '%')); |
||
| 99 | } |
||
| 100 | $this->referenceResolver->addReference($refName, $value, $overwrite); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 115 |