| Conditions | 11 |
| Paths | 23 |
| Total Lines | 50 |
| Code Lines | 30 |
| 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 declare(strict_types=1); |
||
| 54 | public function resolveRepository(OutputInterface $output, callable $resolver, callable $checker = null): int |
||
| 55 | { |
||
| 56 | $result = 0; |
||
| 57 | |||
| 58 | foreach ($this->repositories as [$url, $remote, $path, $merge]) { |
||
| 59 | if (null !== $checker && !$checker([$url, $remote, $path, $merge])) { |
||
| 60 | continue; |
||
| 61 | } |
||
| 62 | |||
| 63 | if (\file_exists($clonePath = \rtrim($this->config['cache'], '\/').'/'.$remote)) { |
||
| 64 | if ($this->config['reclone']) { |
||
| 65 | $output->writeln(\sprintf('Deleting previous clone of <info>%s</info>', $remote)); |
||
| 66 | Process::fromShellCommandline(('\\' === \DIRECTORY_SEPARATOR ? 'rd /s /q "' : 'rm -rf "').$clonePath.'"')->run(); |
||
| 67 | } else { |
||
| 68 | $this->repository->run('pull', ['--all'], cwd: $clonePath); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | $output->writeln(\sprintf('<info>Cloning %s into %s</info>', $url, $clonePath)); |
||
| 73 | @\mkdir($clonePath, recursive: true); |
||
|
|
|||
| 74 | $this->repository->run('clone', ['-q', '--bare', $url, $clonePath]); |
||
| 75 | |||
| 76 | if (0 !== $this->repository->getExitCode()) { |
||
| 77 | $output->writeln(\sprintf('<error>Failed to clone %s</error>', $url)); |
||
| 78 | |||
| 79 | return WorkflowCommand::FAILURE; |
||
| 80 | } |
||
| 81 | |||
| 82 | if (null === $this->repository->getConfig('remote.'.$remote.'.url')) { |
||
| 83 | $output->writeln(\sprintf('<info>Adding remote %s</info>', $remote)); |
||
| 84 | $this->repository->run('remote', ['add', $remote, $clonePath]); |
||
| 85 | } else { |
||
| 86 | $output->writeln(\sprintf('<info>Updating remote %s</info>', $remote)); |
||
| 87 | $this->repository->run('remote', ['set-url', $remote, $clonePath]); |
||
| 88 | } |
||
| 89 | |||
| 90 | $result = $resolver([$url, $remote, $path, $clonePath, $merge]); |
||
| 91 | $this->repository->run('remote', ['remove', $remote]); |
||
| 92 | $output->writeln(''); |
||
| 93 | |||
| 94 | if (null === $result) { |
||
| 95 | continue; |
||
| 96 | } |
||
| 97 | |||
| 98 | if ($result > 0) { |
||
| 99 | return $result; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | return $result; |
||
| 104 | } |
||
| 129 |
If you suppress an error, we recommend checking for the error condition explicitly: