Conditions | 13 |
Paths | 817 |
Total Lines | 51 |
Code Lines | 23 |
Lines | 23 |
Ratio | 45.1 % |
Changes | 1 | ||
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 namespace Comodojo\Installer\Actions; |
||
64 | private static function processCommand($io, $action, $package_name, $package_extra) { |
||
65 | |||
66 | foreach ($package_extra as $command => $actions) { |
||
67 | |||
68 | try { |
||
69 | |||
70 | if ( !self::validateCommand($actions) ) throw new InstallerException('Skipping invalid command '.$command.' in '.$package_name); |
||
71 | |||
72 | $class = $actions["class"]; |
||
73 | |||
74 | $description = empty($actions["description"]) ? null : $actions["description"]; |
||
75 | |||
76 | $aliases = isset($actions["aliases"]) && is_array($actions["aliases"]) ? $actions["aliases"] : array(); |
||
77 | |||
78 | $options = isset($actions["options"]) && is_array($actions["options"]) ? $actions["options"] : array(); |
||
79 | |||
80 | $arguments = isset($actions["arguments"]) && is_array($actions["arguments"]) ? $actions["arguments"] : array(); |
||
81 | |||
82 | View Code Duplication | switch ($action) { |
|
83 | |||
84 | case 'install': |
||
85 | |||
86 | $this->getPackageInstaller() |
||
87 | ->commands() |
||
88 | ->add($package_name, $command, $class, $description, $aliases, $options, $arguments); |
||
89 | |||
90 | $io->write(" <info>+</info> enabled command ".$command); |
||
91 | |||
92 | break; |
||
93 | |||
94 | case 'uninstall': |
||
95 | |||
96 | $id = $this->getPackageInstaller()->commands()->getByName($name)->getId(); |
||
97 | |||
98 | $this->getPackageInstaller()->commands()->delete($id); |
||
99 | |||
100 | $io->write(" <comment>-</comment> disabled command ".$command); |
||
101 | |||
102 | break; |
||
103 | |||
104 | } |
||
105 | |||
106 | } catch (Exception $e) { |
||
107 | |||
108 | $io->write('<error>Error processing command: '.$e->getMessage().'</error>'); |
||
109 | |||
110 | } |
||
111 | |||
112 | } |
||
113 | |||
114 | } |
||
115 | |||
123 |
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.