| Conditions | 10 |
| Paths | 78 |
| Total Lines | 38 |
| 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 |
||
| 46 | public function addResource($bundle, $format, $prefix = null, $path = 'routing') |
||
| 47 | { |
||
| 48 | $current = ''; |
||
| 49 | |||
| 50 | if (null === $prefix) { |
||
| 51 | $prefix = '/admin/'.Container::underscore($bundle). ($this->yaml_prefix ? '/'.$this->yaml_prefix : ''); |
||
| 52 | } |
||
| 53 | |||
| 54 | $routing_name=$bundle.('/' !== $prefix ? '_'.str_replace('/', '_', substr($prefix, 1)) : ''); |
||
| 55 | if (file_exists($this->file)) { |
||
| 56 | $current = file_get_contents($this->file); |
||
| 57 | |||
| 58 | // Don't add same bundle twice |
||
| 59 | if (false !== strpos($current, $routing_name)) { |
||
| 60 | throw new \RuntimeException(sprintf('Bundle "%s" is already imported.', $bundle)); |
||
| 61 | } |
||
| 62 | } elseif (!is_dir($dir = dirname(realpath($this->file)))) { |
||
| 63 | mkdir($dir, 0777, true); |
||
| 64 | } |
||
| 65 | |||
| 66 | |||
| 67 | |||
| 68 | $code = sprintf("%s:\n", $routing_name); |
||
| 69 | if ('admingenerator' == $format) { |
||
| 70 | $code .= sprintf(" resource: \"@%s/Controller/%s\"\n type: admingenerator\n", $bundle, $this->yaml_prefix ? ucfirst($this->yaml_prefix).'/' : ''); |
||
| 71 | } else { |
||
| 72 | $code .= sprintf(" resource: \"@%s/Resources/config/%s.%s\"\n", $bundle, $path, $format); |
||
| 73 | } |
||
| 74 | $code .= sprintf(" prefix: %s\n", $prefix); |
||
| 75 | $code .= "\n"; |
||
| 76 | $code .= $current; |
||
| 77 | |||
| 78 | if (false === file_put_contents($this->file, $code)) { |
||
| 79 | return false; |
||
| 80 | } |
||
| 81 | |||
| 82 | return true; |
||
| 83 | } |
||
| 84 | } |
||
| 85 |