| Conditions | 10 |
| Paths | 10 |
| Total Lines | 40 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 Hafiz\Commands; |
||
| 71 | public function run(array $params = []) |
||
| 72 | { |
||
| 73 | helper(['inflector', 'filesystem']); |
||
| 74 | $this->file = new FileHandler(); |
||
| 75 | $this->db = new DBHandler(); |
||
| 76 | |||
| 77 | $name = array_shift($params); |
||
| 78 | $ns = $params['-n'] ?? CLI::getOption('n'); |
||
| 79 | $table = $params['-t'] ?? CLI::getOption('t'); |
||
| 80 | $alltables = $params['-all'] ?? CLI::getOption('all'); |
||
| 81 | |||
| 82 | if (empty($name) && is_null($alltables)) |
||
| 83 | $name = CLI::prompt(lang('Recharge.migrateName'), null, 'string'); |
||
| 84 | |||
| 85 | if (empty($name) && is_null($alltables)) { |
||
| 86 | CLI::error(lang('Recharge.badName')); |
||
| 87 | return; |
||
| 88 | } |
||
| 89 | |||
| 90 | //namespace locator |
||
| 91 | $nsinfo = $this->file->getNamespaceInfo($ns, 'App'); |
||
| 92 | //class & file name |
||
| 93 | $ns = $nsinfo['ns']; |
||
| 94 | $targetDir = $nsinfo['path'] . '/Database/Migrations/'; |
||
| 95 | $config = config('Migrations'); |
||
| 96 | $timestamp = gmdate($config->timestampFormat); |
||
| 97 | |||
| 98 | //if all database migration creation selected |
||
| 99 | |||
| 100 | if (is_bool($alltables) && $alltables === true) { |
||
| 101 | $tableNames = $this->db->getTableNames(); |
||
| 102 | |||
| 103 | foreach ($tableNames as $tableName) { |
||
| 104 | //disable framework generation tables |
||
| 105 | if ($tableName == 'migrations' || $tableName == 'ci_sessions') continue; |
||
| 106 | |||
| 107 | $this->generateMigration($timestamp, $ns, $targetDir, NULL, $tableName); |
||
| 108 | } |
||
| 109 | } else |
||
| 110 | $this->generateMigration($timestamp, $ns, $targetDir, $name, $table); |
||
|
|
|||
| 111 | } |
||
| 162 |