| Conditions | 13 |
| Paths | 576 |
| Total Lines | 67 |
| Code Lines | 44 |
| 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 |
||
| 115 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 116 | { |
||
| 117 | $browscap = new Browscap(); |
||
| 118 | |||
| 119 | // Set source |
||
| 120 | $source = null; |
||
| 121 | if ($input->getOption('ini-php')) { |
||
| 122 | $source = new PhpSetting(); |
||
| 123 | } elseif ($input->getOption('ini-load')) { |
||
| 124 | $type = Type::STANDARD; |
||
| 125 | switch ($input->getOption('ini-load')) { |
||
| 126 | case 'lite': |
||
| 127 | $type = Type::LITE; |
||
| 128 | break; |
||
| 129 | case 'full': |
||
| 130 | $type = Type::FULL; |
||
| 131 | break; |
||
| 132 | } |
||
| 133 | $source = new BrowscapOrg($type); |
||
| 134 | } elseif ($input->getOption('ini-file')) { |
||
| 135 | $file = (string)$input->getOption('ini-file'); |
||
| 136 | $source = new File($file); |
||
| 137 | } |
||
| 138 | if ($source !== null) { |
||
| 139 | $browscap->getParser()->setSource($source); |
||
| 140 | } |
||
| 141 | |||
| 142 | // Set filter |
||
| 143 | $filter = null; |
||
| 144 | if ($input->getOption('filter-allowed')) { |
||
| 145 | $properties = (array)$input->getOption('filter-allowed'); |
||
| 146 | $filter = new Allowed($properties); |
||
| 147 | } elseif ($input->getOption('filter-disallowed')) { |
||
| 148 | $properties = (array)$input->getOption('filter-disallowed'); |
||
| 149 | $filter = new Disallowed($properties); |
||
| 150 | } |
||
| 151 | if ($filter !== null) { |
||
| 152 | $browscap->getParser()->setPropertyFilter($filter); |
||
| 153 | } |
||
| 154 | |||
| 155 | // Set data directory |
||
| 156 | if ($input->getOption('dir')) { |
||
| 157 | /** @var Parser $parser */ |
||
| 158 | $parser = $browscap->getParser(); |
||
| 159 | $parser->setDataDirectory((string)$input->getOption('dir')); |
||
| 160 | } |
||
| 161 | |||
| 162 | // Force an update? |
||
| 163 | $force = false; |
||
| 164 | if ($input->getOption('force')) { |
||
| 165 | $force = true; |
||
| 166 | } |
||
| 167 | |||
| 168 | // Process update |
||
| 169 | $output->writeln('Processing update...'); |
||
| 170 | $updated = $browscap->update($force); |
||
| 171 | |||
| 172 | // Output result |
||
| 173 | $version = $browscap->getParser()->getReader()->getVersion(); |
||
| 174 | $type = $browscap->getParser()->getReader()->getType(); |
||
| 175 | $name = Type::getName($type); |
||
| 176 | if ($updated === true) { |
||
| 177 | $output->writeln(sprintf('Browscap data successfully updated. New version: %s (%s)', $version, $name)); |
||
| 178 | } else { |
||
| 179 | $output->writeln(sprintf('Nothing to update. Current version: %s (%s)', $version, $name)); |
||
| 180 | } |
||
| 181 | } |
||
| 182 | } |
||
| 183 |