| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace Composer\Installers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | class MicroweberInstaller extends BaseInstaller | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |     protected $locations = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |         'module'      => 'userfiles/modules/{$name}/', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |         'module-skin' => 'userfiles/modules/{$name}/templates/', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |         'template'    => 'userfiles/templates/{$name}/', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |         'element'     => 'userfiles/elements/{$name}/', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |         'vendor'      => 'vendor/{$name}/', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |         'components'  => 'components/{$name}/' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * Format package name. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * For package type microweber-module, cut off a trailing '-module' if present | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * For package type microweber-template, cut off a trailing '-template' if present. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     public function inflectPackageVars($vars) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         if ($vars['type'] === 'microweber-template') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             return $this->inflectTemplateVars($vars); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         if ($vars['type'] === 'microweber-templates') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             return $this->inflectTemplatesVars($vars); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         if ($vars['type'] === 'microweber-core') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |             return $this->inflectCoreVars($vars); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         if ($vars['type'] === 'microweber-adapter') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             return $this->inflectCoreVars($vars); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         if ($vars['type'] === 'microweber-module') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             return $this->inflectModuleVars($vars); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         if ($vars['type'] === 'microweber-modules') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             return $this->inflectModulesVars($vars); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         if ($vars['type'] === 'microweber-skin') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             return $this->inflectSkinVars($vars); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         if ($vars['type'] === 'microweber-element' or $vars['type'] === 'microweber-elements') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             return $this->inflectElementVars($vars); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         return $vars; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 53 |  | View Code Duplication |     protected function inflectTemplateVars($vars) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $vars['name'] = preg_replace('/-template$/', '', $vars['name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $vars['name'] = preg_replace('/template-$/', '', $vars['name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         return $vars; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 61 |  | View Code Duplication |     protected function inflectTemplatesVars($vars) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $vars['name'] = preg_replace('/-templates$/', '', $vars['name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $vars['name'] = preg_replace('/templates-$/', '', $vars['name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         return $vars; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 69 |  | View Code Duplication |     protected function inflectCoreVars($vars) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $vars['name'] = preg_replace('/-providers$/', '', $vars['name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $vars['name'] = preg_replace('/-provider$/', '', $vars['name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $vars['name'] = preg_replace('/-adapter$/', '', $vars['name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         return $vars; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                        
                            
            
                                                                    
                                                                                                        
            
            
                | 78 |  | View Code Duplication |     protected function inflectModuleVars($vars) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |         $vars['name'] = preg_replace('/-module$/', '', $vars['name']); | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |         $vars['name'] = preg_replace('/module-$/', '', $vars['name']); | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |         return $vars; | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 86 |  | View Code Duplication |     protected function inflectModulesVars($vars) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $vars['name'] = preg_replace('/-modules$/', '', $vars['name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $vars['name'] = preg_replace('/modules-$/', '', $vars['name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         return $vars; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 94 |  | View Code Duplication |     protected function inflectSkinVars($vars) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         $vars['name'] = preg_replace('/-skin$/', '', $vars['name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         $vars['name'] = preg_replace('/skin-$/', '', $vars['name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         return $vars; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 102 |  | View Code Duplication |     protected function inflectElementVars($vars) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         $vars['name'] = preg_replace('/-elements$/', '', $vars['name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         $vars['name'] = preg_replace('/elements-$/', '', $vars['name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         $vars['name'] = preg_replace('/-element$/', '', $vars['name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         $vars['name'] = preg_replace('/element-$/', '', $vars['name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         return $vars; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 111 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 112 |  |  |  | 
            
                        
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.