| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace GBProd\ElasticaExtraBundle\Command; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Symfony\Component\Console\Input\InputArgument; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Symfony\Component\Console\Input\InputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Symfony\Component\Console\Input\InputOption; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Symfony\Component\Console\Output\OutputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * Command to add alias | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @author gbprod <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | class AddAliasCommand extends ElasticaAwareCommand | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 20 | 1 | View Code Duplication |     protected function configure() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 | 1 |  |         $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 | 1 |  |             ->setName('elasticsearch:alias:add') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 | 1 |  |             ->setDescription('Add alias to an index') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 | 1 |  |             ->addArgument('index', InputArgument::REQUIRED, 'Which index ?') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 | 1 |  |             ->addArgument('alias', InputArgument::REQUIRED, 'Alias name') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 | 1 |  |             ->addOption('replace', null, InputOption::VALUE_NONE, 'If set, an existing alias will be replaced') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 | 1 |  |             ->addOption('client', null, InputOption::VALUE_REQUIRED, 'Client to use (if not default)', null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 1 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 34 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 35 | 1 |  |     protected function execute(InputInterface $input, OutputInterface $output) | 
            
                                                        
            
                                    
            
            
                | 36 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 37 | 1 |  |         $client  = $this->getClient($input->getOption('client')); | 
            
                                                        
            
                                    
            
            
                | 38 | 1 |  |         $index   = $input->getArgument('index'); | 
            
                                                        
            
                                    
            
            
                | 39 | 1 |  |         $alias   = $input->getArgument('alias'); | 
            
                                                        
            
                                    
            
            
                | 40 | 1 |  |         $replace = $input->getOption('replace'); | 
            
                                                        
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 42 | 1 |  |         $output->writeln(sprintf( | 
            
                                                        
            
                                    
            
            
                | 43 | 1 |  |             '<info>Add alias <comment>%s</comment> for index <comment>%s</comment></info>', | 
            
                                                        
            
                                    
            
            
                | 44 | 1 |  |             $alias, | 
            
                                                        
            
                                    
            
            
                | 45 |  |  |             $index | 
            
                                                        
            
                                    
            
            
                | 46 | 1 |  |         )); | 
            
                                                        
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 48 | 1 |  |         $this | 
            
                                                        
            
                                    
            
            
                | 49 | 1 |  |             ->getContainer() | 
            
                                                        
            
                                    
            
            
                | 50 | 1 |  |             ->get('gbprod.elastica_extra.add_alias_handler') | 
            
                                                        
            
                                    
            
            
                | 51 | 1 |  |             ->handle($client, $index, $alias, $replace); | 
            
                                                        
            
                                    
            
            
                | 52 |  |  |         ; | 
            
                                                        
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 54 | 1 |  |         $output->writeln('done'); | 
            
                                                        
            
                                    
            
            
                | 55 | 1 |  |     } | 
            
                                                        
            
                                    
            
            
                | 56 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 57 |  |  |  | 
            
                        
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.