| Conditions | 7 |
| Paths | 7 |
| Total Lines | 51 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 39 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 40 | { |
||
| 41 | // install the 'system' module |
||
| 42 | $xoops = \Xoops::getInstance(); |
||
| 43 | $module = 'system'; |
||
| 44 | $output->writeln(sprintf('Installing %s', $module)); |
||
| 45 | if (false !== $xoops->getModuleByDirname($module)) { |
||
|
|
|||
| 46 | $output->writeln(sprintf('<error>%s module is already installed!</error>', $module)); |
||
| 47 | return; |
||
| 48 | } |
||
| 49 | $xoops->setTpl(new XoopsTpl()); |
||
| 50 | \XoopsLoad::load('module', 'system'); |
||
| 51 | $sysmod = new \SystemModule(); |
||
| 52 | $result = $sysmod->install($module); |
||
| 53 | foreach ($sysmod->trace as $message) { |
||
| 54 | if (is_array($message)) { |
||
| 55 | foreach ($message as $subMessage) { |
||
| 56 | if (!is_array($subMessage)) { |
||
| 57 | $output->writeln(strip_tags($subMessage)); |
||
| 58 | } |
||
| 59 | } |
||
| 60 | } else { |
||
| 61 | $output->writeln(strip_tags($message)); |
||
| 62 | } |
||
| 63 | } |
||
| 64 | if ($result===false) { |
||
| 65 | $output->writeln(sprintf('<error>Install of %s module failed!</error>', $module)); |
||
| 66 | } else { |
||
| 67 | $output->writeln(sprintf('<info>Install of %s module completed.</info>', $module)); |
||
| 68 | } |
||
| 69 | $xoops->cache()->delete('system'); |
||
| 70 | |||
| 71 | // add an admin user |
||
| 72 | $adminname = 'admin'; |
||
| 73 | $adminpass = password_hash($adminname, PASSWORD_DEFAULT); // user: admin pass: admin |
||
| 74 | $regdate = time(); |
||
| 75 | $result = $xoops->db()->insertPrefix( |
||
| 76 | 'system_user', |
||
| 77 | array( |
||
| 78 | // 'uid' => 1, // mediumint(8) unsigned NOT NULL auto_increment, |
||
| 79 | 'uname' => $adminname, // varchar(25) NOT NULL default '', |
||
| 80 | 'email' => 'nobody@localhost', // varchar(60) NOT NULL default '', |
||
| 81 | 'user_regdate' => $regdate, // int(10) unsigned NOT NULL default '0', |
||
| 82 | 'user_viewemail' => 1, // tinyint(1) unsigned NOT NULL default '0', |
||
| 83 | 'pass' => $adminpass, // varchar(255) NOT NULL default '', |
||
| 84 | 'rank' => 7, // smallint(5) unsigned NOT NULL default '0', |
||
| 85 | 'level' => 5, // tinyint(3) unsigned NOT NULL default '1', |
||
| 86 | 'last_login' => $regdate, // int(10) unsigned NOT NULL default '0', |
||
| 87 | ) |
||
| 88 | ); |
||
| 89 | $output->writeln(sprintf('<info>Inserted %d user.</info>', $result)); |
||
| 90 | } |
||
| 92 |