| Conditions | 11 |
| Paths | 88 |
| Total Lines | 57 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 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 |
||
| 53 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 54 | { |
||
| 55 | $indentation = 4; |
||
| 56 | |||
| 57 | if ($input->getOption('app-only')) { |
||
| 58 | $message = "This is the configuration defined in the app/ directory (not processed):\n"; |
||
| 59 | $config = $this->getServiceManager()->get('ApplicationConfig'); |
||
| 60 | } else { |
||
| 61 | $message = "This is the configuration in use for your current setup (merged and processed):\n"; |
||
| 62 | $config = $this->getServiceManager()->get('Config'); |
||
| 63 | } |
||
| 64 | |||
| 65 | $files = array(); |
||
| 66 | $contents = array(); |
||
| 67 | |||
| 68 | if (($files['php'] = $input->getOption('write-php'))) { |
||
| 69 | $contents['php'] = "<?php\n\nreturn " . var_export($config, true) . ";\n\n?>\n"; |
||
| 70 | } |
||
| 71 | |||
| 72 | if (($files['yaml'] = $input->getOption('write-yaml'))) { |
||
| 73 | $dumper = new Dumper(); |
||
| 74 | $dumper->setIndentation($indentation); |
||
| 75 | $contents['yaml'] = $dumper->dump($config, 6, 0, false, false); |
||
| 76 | } |
||
| 77 | |||
| 78 | if (empty($contents)) { |
||
| 79 | $dumper = new Dumper(); |
||
| 80 | $dumper->setIndentation($indentation); |
||
| 81 | $output->writeln($message); |
||
| 82 | |||
| 83 | foreach ($config as $rootKey => $subConfig) { |
||
| 84 | $output->writeln('<info>' . $rootKey . '</info>:'); |
||
| 85 | $output->writeln($dumper->dump($subConfig, 6, $indentation, false, false)); |
||
| 86 | } |
||
| 87 | |||
| 88 | return; |
||
| 89 | } |
||
| 90 | |||
| 91 | foreach ($files as $format => $file) { |
||
| 92 | $output->write('Saving configuration in <info>' . strtoupper($format) . '</info> format...'); |
||
| 93 | if ($fileExists = file_exists($file)) { |
||
| 94 | if (!isset($dialog)) { |
||
| 95 | $dialog = $this->getHelperSet()->get('dialog'); |
||
| 96 | } |
||
| 97 | if (!$dialog->askConfirmation($output, |
||
| 98 | " <question>File \"" . $file . "\" already exists. Proceed anyway?</question> ", false)) { |
||
| 99 | continue; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | file_put_contents($file, $contents[$format]); |
||
| 104 | |||
| 105 | if (!$fileExists) { |
||
| 106 | $output->writeln(' OK.'); |
||
| 107 | } |
||
| 108 | } |
||
| 109 | } |
||
| 110 | } |
||
| 111 |