| Conditions | 15 |
| Paths | 416 |
| Total Lines | 62 |
| Code Lines | 42 |
| 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 |
||
| 72 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 73 | { |
||
| 74 | $languagePackService = GeneralUtility::makeInstance(LanguagePackService::class); |
||
| 75 | $noProgress = $input->getOption('no-progress') || $output->isVerbose(); |
||
| 76 | $isos = (array)$input->getArgument('locales'); |
||
| 77 | $skipExtensions = (array)$input->getOption('skip-extension'); |
||
| 78 | |||
| 79 | // Condition for the scheduler command, e.g. "de fr pt" |
||
| 80 | if (count($isos) === 1 && strpos($isos[0], ' ') !== false) { |
||
| 81 | $isos = GeneralUtility::trimExplode(' ', $isos[0], true); |
||
| 82 | } |
||
| 83 | if (empty($isos)) { |
||
| 84 | $isos = $languagePackService->getActiveLanguages(); |
||
| 85 | } |
||
| 86 | |||
| 87 | $output->writeln(sprintf( |
||
| 88 | '<info>Updating language packs of all activated extensions for locale(s) "%s"</info>', |
||
| 89 | implode('", "', $isos) |
||
| 90 | )); |
||
| 91 | |||
| 92 | $extensions = $languagePackService->getExtensionLanguagePackDetails(); |
||
| 93 | |||
| 94 | if ($noProgress) { |
||
| 95 | $progressBarOutput = new NullOutput(); |
||
| 96 | } else { |
||
| 97 | $progressBarOutput = $output; |
||
| 98 | } |
||
| 99 | $progressBar = new ProgressBar($progressBarOutput, count($isos) * count($extensions)); |
||
| 100 | $hasErrors = false; |
||
| 101 | foreach ($isos as $iso) { |
||
| 102 | foreach ($extensions as $extension) { |
||
| 103 | if (in_array($extension['key'], $skipExtensions, true)) { |
||
| 104 | continue; |
||
| 105 | } |
||
| 106 | if ($noProgress) { |
||
| 107 | $output->writeln(sprintf('<info>Fetching pack for language "%s" for extension "%s"</info>', $iso, $extension['key']), $output::VERBOSITY_VERY_VERBOSE); |
||
| 108 | } |
||
| 109 | $result = $languagePackService->languagePackDownload($extension['key'], $iso); |
||
| 110 | if ($noProgress) { |
||
| 111 | switch ($result) { |
||
| 112 | case 'failed': |
||
| 113 | $output->writeln(sprintf('<error>Fetching pack for language "%s" for extension "%s" failed</error>', $iso, $extension['key'])); |
||
| 114 | $hasErrors = true; |
||
| 115 | break; |
||
| 116 | case 'update': |
||
| 117 | $output->writeln(sprintf('<info>Updated pack for language "%s" for extension "%s"</info>', $iso, $extension['key'])); |
||
| 118 | break; |
||
| 119 | case 'new': |
||
| 120 | $output->writeln(sprintf('<info>Fetching new pack for language "%s" for extension "%s"</info>', $iso, $extension['key'])); |
||
| 121 | break; |
||
| 122 | } |
||
| 123 | } |
||
| 124 | $progressBar->advance(); |
||
| 125 | } |
||
| 126 | } |
||
| 127 | $languagePackService->setLastUpdatedIsoCode($isos); |
||
| 128 | $progressBar->finish(); |
||
| 129 | |||
| 130 | // Flush language cache |
||
| 131 | GeneralUtility::makeInstance(CacheManager::class)->getCache('l10n')->flush(); |
||
| 132 | |||
| 133 | return $hasErrors ? 1 : 0; |
||
| 134 | } |
||
| 136 |