| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace N98\Magento\Command\System\Store\Config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use N98\Magento\Command\AbstractMagentoCommand; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use N98\Util\Console\Helper\Table\Renderer\RendererFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use N98\Util\Console\Helper\TableHelper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Symfony\Component\Console\Input\InputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Symfony\Component\Console\Input\InputOption; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Symfony\Component\Console\Output\OutputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | class BaseUrlListCommand extends AbstractMagentoCommand | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                        
                            
            
                                                                    
                                                                                                        
            
            
                | 14 |  | View Code Duplication |     protected function configure() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |         $this | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |             ->setName('sys:store:config:base-url:list') | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |             ->setDescription('Lists all base urls') | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |             ->addOption( | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |                 'format', | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |                 null, | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |                 InputOption::VALUE_OPTIONAL, | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |                 'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']' | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |             ) | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |         ; | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @param InputInterface  $input | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * @param OutputInterface $output | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * @return int|void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     protected function execute(InputInterface $input, OutputInterface $output) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $this->detectMagento($output, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         if (!$input->getOption('format')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             $this->writeSection($output, 'Magento Stores - Base URLs'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $this->initMagento(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         foreach (\Mage::app()->getStores() as $store) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             $table[$store->getId()] = array( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                 $store->getId(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                 $store->getCode(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                 \Mage::getStoreConfig('web/unsecure/base_url', $store), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                 \Mage::getStoreConfig('web/secure/base_url', $store), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         ksort($table); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         /* @var $tableHelper TableHelper */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $tableHelper = $this->getHelper('table'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $tableHelper | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             ->setHeaders(array('id', 'code', 'unsecure_baseurl', 'secure_baseurl')) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             ->renderByFormat($output, $table, $input->getOption('format')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 59 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 60 |  |  |  | 
            
                        
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.