| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the Conveyor package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * (c) Jeroen Fiege <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | namespace Webcreate\Conveyor\Command; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Symfony\Component\Console\Input\InputArgument; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Symfony\Component\Console\Input\InputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Symfony\Component\Console\Input\InputOption; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Symfony\Component\Console\Output\OutputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | class DeployCommand extends AbstractCommand | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 20 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 21 | 2 |  |     protected function configure() | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |         $this | 
            
                                                                        
                            
            
                                    
            
            
                | 24 | 2 |  |             ->setName('deploy') | 
            
                                                                        
                            
            
                                    
            
            
                | 25 | 2 |  |             ->setDescription('Deploy') | 
            
                                                                        
                            
            
                                    
            
            
                | 26 | 2 |  |             ->addArgument('target', InputArgument::REQUIRED, 'Target or group to deploy') | 
            
                                                                        
                            
            
                                    
            
            
                | 27 | 2 |  |             ->addArgument('version', InputArgument::REQUIRED, 'Version to deploy') | 
            
                                                                        
                            
            
                                    
            
            
                | 28 | 2 |  |             ->addOption('force', '-f', InputOption::VALUE_NONE, 'Force deploy') | 
            
                                                                        
                            
            
                                    
            
            
                | 29 | 2 |  |             ->addOption('full', null, InputOption::VALUE_NONE, 'Full deploy instead of incremental deploy') | 
            
                                                                        
                            
            
                                    
            
            
                | 30 | 2 |  |             ->addOption('after', null, InputOption::VALUE_NONE, 'Only run deploy after tasks') | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |         ; | 
            
                                                                        
                            
            
                                    
            
            
                | 32 | 2 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     protected function execute(InputInterface $input, OutputInterface $output) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $conveyor = $this->getConveyor($input, $output, $this->getHelperSet()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $options = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $options['full_deploy'] = (bool) $input->getOption('full'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $options['deploy_after_only'] = (bool) $input->getOption('after'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $options['force'] = (bool) $input->getOption('force'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $target = $input->getArgument('target'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $targets = [$target]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 47 |  | View Code Duplication |         if (false !== strpos($target, ',')) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             $output->writeln('<info>Deprecated: Comma-separated list of targets is no longer supported, please use target groups to deploy to multiple targets at once.</info>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             $targets = explode(',', $target); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         foreach ($targets as $target) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             $conveyor->deploy($target, $input->getArgument('version'), $options); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 57 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |  | 
            
                        
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.