| Conditions | 11 |
| Paths | 16 |
| Total Lines | 41 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 24 | protected function getDefinitions(array $paths = array(), $returnFilename = false) |
||
| 25 | { |
||
| 26 | // if no paths defined, we look in all bundles |
||
| 27 | if (empty($paths)) { |
||
| 28 | $paths = array(); |
||
| 29 | /** @var $bundle \Symfony\Component\HttpKernel\Bundle\BundleInterface */ |
||
| 30 | foreach ($this->kernel->getBundles() as $bundle) |
||
| 31 | { |
||
| 32 | $path = $bundle->getPath() . "/" . $this->versionDirectory; |
||
| 33 | if (is_dir($path)) { |
||
| 34 | $paths[] = $path; |
||
| 35 | } |
||
| 36 | } |
||
| 37 | } |
||
| 38 | |||
| 39 | $definitions = array(); |
||
| 40 | foreach ($paths as $path) { |
||
| 41 | if (is_file($path)) { |
||
| 42 | $definitions[basename($path)] = $returnFilename ? $path : new WorkflowDefinition( |
||
| 43 | basename($path), |
||
| 44 | $path, |
||
| 45 | file_get_contents($path) |
||
| 46 | ); |
||
| 47 | } elseif (is_dir($path)) { |
||
| 48 | foreach (new \DirectoryIterator($path) as $file) { |
||
| 49 | if ($file->isFile()) { |
||
| 50 | $definitions[$file->getFilename()] = |
||
| 51 | $returnFilename ? $file->getRealPath() : new WorkflowDefinition( |
||
| 52 | $file->getFilename(), |
||
| 53 | $file->getRealPath(), |
||
| 54 | file_get_contents($file->getRealPath()) |
||
| 55 | ); |
||
| 56 | } |
||
| 57 | } |
||
| 58 | } else { |
||
| 59 | throw new \Exception("Path '$path' is neither a file nor directory"); |
||
| 60 | } |
||
| 61 | } |
||
| 62 | ksort($definitions); |
||
| 63 | |||
| 64 | return $definitions; |
||
| 65 | } |
||
| 67 |