1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Geekish\Crap\Command; |
4
|
|
|
|
5
|
|
|
use Composer\Command\UpdateCommand as ComposerUpdateCommand; |
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class UpdateCommand |
12
|
|
|
* @package Geekish\Crap\Command |
13
|
|
|
*/ |
14
|
|
View Code Duplication |
final class UpdateCommand extends BaseComposerCommand |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @inheritDoc |
18
|
|
|
*/ |
19
|
|
|
protected function configure() |
20
|
|
|
{ |
21
|
|
|
$this->setName('update'); |
22
|
|
|
$this->setDescription('Gets package name and version by alias, calls `composer update`'); |
23
|
|
|
$this->addArgument('aliases', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'Package aliases'); |
24
|
|
|
|
25
|
|
|
$command = new ComposerUpdateCommand; |
26
|
|
|
|
27
|
|
|
foreach ($command->getDefinition()->getOptions() as $option) { |
28
|
|
|
$this->getDefinition()->addOption($option); |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @inheritDoc |
34
|
|
|
* @codeCoverageIgnore |
35
|
|
|
*/ |
36
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
37
|
|
|
{ |
38
|
|
|
$packages = $this->helper->parseArguments($input->getArgument('aliases')); |
39
|
|
|
|
40
|
|
|
$options = $this->getOptions($input, $output->isDecorated()); |
41
|
|
|
$helper = $this->getHelper('process'); |
42
|
|
|
$process = $this->createProcess('update', $packages, $options); |
43
|
|
|
|
44
|
|
|
$helper->run($output, $process, 'Command failed.', function ($type, $data) use ($output) { |
45
|
|
|
$output->write($data, false); |
46
|
|
|
}); |
47
|
|
|
|
48
|
|
|
return $process->getExitCode(); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.