| Conditions | 10 |
| Paths | 84 |
| Total Lines | 46 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 63 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 64 | { |
||
| 65 | $io = new SymfonyStyle($input, $output); |
||
| 66 | |||
| 67 | /** @var KernelInterface $kernel */ |
||
| 68 | $kernel = $this->getApplication()->getKernel(); |
||
|
|
|||
| 69 | $transPaths = []; |
||
| 70 | if ($this->defaultTransPath) { |
||
| 71 | $transPaths[] = $this->defaultTransPath; |
||
| 72 | } |
||
| 73 | $currentName = 'default directory'; |
||
| 74 | // Override with provided Bundle info (this section copied from symfony's translation:update command) |
||
| 75 | if (null !== $input->getArgument('bundle')) { |
||
| 76 | try { |
||
| 77 | $foundBundle = $kernel->getBundle($input->getArgument('bundle')); |
||
| 78 | $bundleDir = $foundBundle->getPath(); |
||
| 79 | $transPaths = [is_dir($bundleDir . '/Resources/translations') ? $bundleDir . '/Resources/translations' : $bundleDir . '/translations']; |
||
| 80 | $currentName = $foundBundle->getName(); |
||
| 81 | } catch (\InvalidArgumentException $e) { |
||
| 82 | // such a bundle does not exist, so treat the argument as path |
||
| 83 | $path = $input->getArgument('bundle'); |
||
| 84 | $transPaths = [$path . '/translations']; |
||
| 85 | if (!is_dir($transPaths[0]) && !isset($transPaths[1])) { |
||
| 86 | throw new InvalidArgumentException(sprintf('"%s" is neither an enabled bundle nor a directory.', $transPaths[0])); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | } |
||
| 90 | $io->title('Translation Messages Key to Value Transformer'); |
||
| 91 | $io->comment(sprintf('Transforming translation files for "<info>%s</info>"', $currentName)); |
||
| 92 | $finder = new Finder(); |
||
| 93 | $fs = new Filesystem(); |
||
| 94 | foreach ($finder->files()->in($transPaths)->name(['*.yaml', '*.yml']) as $file) { |
||
| 95 | $io->text(sprintf('<comment>Parsing %s</comment>', $file->getBasename())); |
||
| 96 | $messages = Yaml::parseFile($file->getRealPath()); |
||
| 97 | foreach ($messages as $key => $message) { |
||
| 98 | if (null === $message) { |
||
| 99 | $messages[$key] = $key; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | $io->text(sprintf('<info>Dumping %s</info>', $file->getBasename())); |
||
| 103 | $fs->dumpFile($file->getRealPath(), Yaml::dump($messages)); |
||
| 104 | } |
||
| 105 | |||
| 106 | $io->success('Success!'); |
||
| 107 | |||
| 108 | return Command::SUCCESS; |
||
| 109 | } |
||
| 111 |