| Conditions | 8 |
| Paths | 37 |
| Total Lines | 57 |
| Code Lines | 32 |
| 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 |
||
| 16 | public static function createInitialConfig(Event $event) |
||
| 17 | { |
||
| 18 | $installer = new Installer(); |
||
| 19 | $io = $event->getIO(); |
||
| 20 | |||
| 21 | // check if parameters.yml exists |
||
| 22 | $rootDir = realpath(__DIR__ . '/../../../../'); |
||
| 23 | if (file_exists($rootDir . '/app/config/parameters.yml')) { |
||
| 24 | $io->write( |
||
| 25 | $installer->getDecoratedMessage( |
||
| 26 | 'Skipping creating the initial config as parameters.yml already exists', |
||
| 27 | 'info', |
||
| 28 | $io->isDecorated() |
||
| 29 | ) |
||
| 30 | ); |
||
| 31 | } else { |
||
| 32 | $information = $installer->extractInformationFromPath($rootDir); |
||
| 33 | |||
| 34 | // ask all the information we need |
||
| 35 | $config = array(); |
||
| 36 | $config['client'] = $installer->ask($io, 'client name', $information['client']); |
||
| 37 | $config['project'] = $installer->ask($io, 'project name', $information['project']); |
||
| 38 | |||
| 39 | $config['database_name'] = substr($config['client'], 0, 8) . '_' . substr($config['project'], 0, 7); |
||
| 40 | $config['database_user'] = $config['database_name']; |
||
| 41 | |||
| 42 | if ($information['is_local']) { |
||
| 43 | // this is the ip-address of our Vagrantbox |
||
| 44 | $config['database_host'] = '10.11.12.13'; |
||
| 45 | $config['database_user'] = 'root'; |
||
| 46 | $config['database_password'] = 'root'; |
||
| 47 | } |
||
| 48 | |||
| 49 | $config['secret'] = md5(uniqid()); |
||
| 50 | |||
| 51 | // create the database if requested |
||
| 52 | if ($installer->askConfirmation($io, 'Should I create the database?')) { |
||
| 53 | passthru('mysqladmin create ' . $config['database_name']); |
||
| 54 | } |
||
| 55 | |||
| 56 | // alter the Capfile if requested |
||
| 57 | $capfilePath = $rootDir . '/Capfile'; |
||
| 58 | if (file_exists($capfilePath)) { |
||
| 59 | if ($installer->askConfirmation($io, 'Should I alter the Capfile?')) { |
||
| 60 | $installer->updateCapfile($capfilePath, $config); |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | // alter the dist file if requested |
||
| 65 | $parameterYmlDistPath = $rootDir . '/app/config/parameters.yml.dist'; |
||
| 66 | if (file_exists($parameterYmlDistPath)) { |
||
| 67 | if ($installer->askConfirmation($io, 'Should I alter parameters.yml.dist?')) { |
||
| 68 | $installer->updateYmlFile($parameterYmlDistPath, $config); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 131 |