| 1 |  |  | <?php namespace Anomaly\AddonsModule\Addon\Table; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | use Anomaly\Streams\Platform\Addon\Addon; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Anomaly\Streams\Platform\Addon\Extension\Extension; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Anomaly\Streams\Platform\Addon\Module\Module; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * Class AddonTableButtons | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @link          http://pyrocms.com/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @author        PyroCMS, Inc. <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @author        Ryan Thompson <[email protected]> | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 14 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  | class AddonTableButtons | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |      * Handle the command. | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |      * @param AddonTableBuilder $builder | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     public function handle(AddonTableBuilder $builder) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $builder->setButtons( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |                 'information' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |                     'data-toggle' => 'modal', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |                     'data-target' => '#modal', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |                     'href'        => 'admin/addons/details/{entry.namespace}', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |                 ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |                 'install'     => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |                     'data-toggle' => 'modal', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |                     'data-target' => '#modal', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |                     'href'        => 'admin/addons/options/{entry.namespace}', | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 36 |  | View Code Duplication |                     'enabled'     => function (Addon $entry) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |                         if (!$entry instanceof Module && !$entry instanceof Extension) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |                             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                         return !$entry->isInstalled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                     }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                 ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                 'migrate'   => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                     'class'      => 'btn-success', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                     'icon'       => 'fa fa-level-up', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                     'text'       => 'anomaly.module.addons::button.migrate', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |                     'href'       => 'admin/addons/migrate/{entry.namespace}', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |                     'data-match' => function (Addon $entry) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |                         return $entry->getTitle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                     }, | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 53 |  | View Code Duplication |                     'enabled'    => function (Addon $entry) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                         if (!$entry instanceof Module && !$entry instanceof Extension) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |                         return $entry->isInstalled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |                     }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |                 ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |                 'uninstall'   => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |                     'button'     => 'prompt', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |                     'icon'       => 'times-circle', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |                     'text'       => 'anomaly.module.addons::button.uninstall', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |                     'href'       => 'admin/addons/uninstall/{entry.namespace}', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                     'data-match' => function (Addon $entry) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |                         return $entry->getTitle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |                     }, | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 70 |  | View Code Duplication |                     'enabled'    => function (Addon $entry) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |                         if (!$entry instanceof Module && !$entry instanceof Extension) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |                             return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |                         return $entry->isInstalled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |                     }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |                 ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         ); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 81 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 82 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 83 |  |  |  | 
            
                        
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.