| Conditions | 5 | 
| Paths | 5 | 
| Total Lines | 66 | 
| Code Lines | 36 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 2 | ||
| Bugs | 0 | Features | 0 | 
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php  | 
            ||
| 30 | public function handle()  | 
            ||
| 31 |     { | 
            ||
| 32 | $this->newLine(2);  | 
            ||
| 33 | |||
| 34 |         Log::notice('Activate Module Command running for './** @scrutinizer ignore-type */$this->argument('module')); | 
            ||
| 35 | |||
| 36 | // Verify that the module is not already installed  | 
            ||
| 37 | $activeModules = Module::allEnabled();  | 
            ||
| 38 | foreach($activeModules as $module)  | 
            ||
| 39 |         { | 
            ||
| 40 |             if($module->getName() === $this->argument('module')); | 
            ||
| 41 |             { | 
            ||
| 42 |                 $this->error('The '.$this->argument('module').' is already active'); | 
            ||
| 43 |                 Log::critical('The '.$this->argument('module').' is already active'); | 
            ||
| 44 | return 1;  | 
            ||
| 45 | }  | 
            ||
| 46 | }  | 
            ||
| 47 | |||
| 48 |         $this->line('Activating Module '.$this->argument('module')); | 
            ||
| 49 | $this->newLine(2);  | 
            ||
| 50 | |||
| 51 | // Verify that the module exists and is valid  | 
            ||
| 52 |         $module = $this->findModule($this->argument('module')); | 
            ||
| 53 | if(!$module)  | 
            ||
| 54 |         { | 
            ||
| 55 |             $this->error('Unable to find module - '.$this->argument('module')); | 
            ||
| 56 |             $this->error('Please make sure that this is a proper Tech Bench Module and loaded into the Modules directory'); | 
            ||
| 57 |             Log::critical('Unable to find module - '.$this->argument('module')); | 
            ||
| 58 | return 1;  | 
            ||
| 59 | }  | 
            ||
| 60 | |||
| 61 |         $this->line('Found Module.  Checking Prerequisites'); | 
            ||
| 62 | |||
| 63 | // Verify that the correct version of Tech Bench is running for this module  | 
            ||
| 64 | if(!$this->checkPrerequisites($module->getRequires()))  | 
            ||
| 65 |         { | 
            ||
| 66 |             $this->error('Tech Bench does not meet the prerequisites for installing this module'); | 
            ||
| 67 |             $this->error('Please install the missing requirements and try again'); | 
            ||
| 68 |             Log::critical('Tech Bench does not meet the prerequisites for installing this module'); | 
            ||
| 69 |             Log::critical('Please install the missing requirements and try again'); | 
            ||
| 70 | return 1;  | 
            ||
| 71 | }  | 
            ||
| 72 | |||
| 73 |         $this->line('Prerequisites passed.  Activating Module'); | 
            ||
| 74 | |||
| 75 | // Enable the module  | 
            ||
| 76 |         $this->call('module:enable', ['module' => $module->getStudlyName()]); | 
            ||
| 77 | |||
| 78 | // Run any migrations  | 
            ||
| 79 |         $this->line('Setting up database'); | 
            ||
| 80 |         $this->call('module:migrate', ['module' => $module->getStudlyName()]); | 
            ||
| 81 | |||
| 82 | // Install NPM and Composer packages  | 
            ||
| 83 |         $this->line('Copying Files'); | 
            ||
| 84 |         shell_exec('cd '.base_path().DIRECTORY_SEPARATOR.'Modules'.DIRECTORY_SEPARATOR.$module->getStudlyName().' && composer install --no-dev --no-interaction --optimize-autoloader'); | 
            ||
| 85 |         shell_exec('cd '.base_path().DIRECTORY_SEPARATOR.'Modules'.DIRECTORY_SEPARATOR.$module->getStudlyName().' && npm install --silent --only=production'); | 
            ||
| 86 | |||
| 87 | // Combine the new Javascript files  | 
            ||
| 88 |         $this->line('Creating Javascript files (this may take some time)'); | 
            ||
| 89 |         shell_exec('cd '.base_path().DIRECTORY_SEPARATOR.'Modules'.DIRECTORY_SEPARATOR.$module->getStudlyName().' && npm run production'); | 
            ||
| 90 |         shell_exec('cd '.base_path().DIRECTORY_SEPARATOR.' && npm run production'); | 
            ||
| 91 | |||
| 92 |         $this->info('Module has been activated'); | 
            ||
| 93 |         Log::notice('Module '.$this->argument('module').' has been activated'); | 
            ||
| 94 | |||
| 95 | return Command::SUCCESS;  | 
            ||
| 96 | }  | 
            ||
| 164 |