| Conditions | 12 |
| Paths | 10 |
| Total Lines | 46 |
| Code Lines | 25 |
| 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 |
||
| 17 | protected function createDatabases($instanceList, $dbSpecList) |
||
| 18 | { |
||
| 19 | // Sadly, psql does not allow to create a db and a user using a multiple-sql-commands string, |
||
| 20 | // and we have to resort to using temp files |
||
| 21 | /// @todo can we make this safer? Ideally the new user name and pwd should neither hit disk nor the process list... |
||
| 22 | $results = $this->executeSqlAction( |
||
| 23 | $instanceList, |
||
| 24 | 'Creating new database & user', |
||
| 25 | function ($schemaManager, $instanceName) use ($dbSpecList) { |
||
| 26 | $dbConnectionSpec = $dbSpecList[$instanceName]; |
||
| 27 | /** @var DatabaseSchemaManager $schemaManager */ |
||
| 28 | return $schemaManager->getCreateDatabaseSqlAction( |
||
| 29 | $dbConnectionSpec['dbname'], |
||
| 30 | isset($dbConnectionSpec['user']) ? $dbConnectionSpec['user'] : null, |
||
| 31 | isset($dbConnectionSpec['password']) ? $dbConnectionSpec['password'] : null, |
||
| 32 | (isset($dbConnectionSpec['charset']) && $dbConnectionSpec['charset'] != '') ? $dbConnectionSpec['charset'] : null |
||
| 33 | ); |
||
| 34 | } |
||
| 35 | ); |
||
| 36 | |||
| 37 | /// @todo the new connection spec should be generated by the schemaManager for each instance. This would allow |
||
| 38 | /// f.e. connection specs for Oracle to be different when using PDBs vs when using schemas |
||
| 39 | /// (this could be achieved by copying the 'dbname' member over the 'servicename' one, or unsetting 'servicename'...) |
||
| 40 | $finalData = []; |
||
| 41 | foreach($results['data'] as $instanceName => $data) { |
||
| 42 | // check for failure in creation of temp db |
||
| 43 | // @todo how can we tell apart correctly errors that actually prevented the db from being created from other errors? |
||
| 44 | if (is_array($data) && isset($data['exitcode']) && $data['exitcode'] != 0) { |
||
| 45 | continue; |
||
| 46 | } |
||
| 47 | $dbConnectionSpec = $dbSpecList[$instanceName]; |
||
| 48 | $finalData[$instanceName] = $instanceList[$instanceName]; |
||
| 49 | $finalData[$instanceName]['dbname'] = $dbConnectionSpec['dbname']; |
||
| 50 | if (isset($dbConnectionSpec['user'])) { |
||
| 51 | $finalData[$instanceName]['user'] = $dbConnectionSpec['user']; |
||
| 52 | } |
||
| 53 | if (isset($dbConnectionSpec['password'])) { |
||
| 54 | $finalData[$instanceName]['password'] = $dbConnectionSpec['password']; |
||
| 55 | } |
||
| 56 | if (isset($dbConnectionSpec['charset'])) { |
||
| 57 | $finalData[$instanceName]['charset'] = $dbConnectionSpec['charset']; |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | $results['data'] = $finalData; |
||
| 62 | return $results; |
||
| 63 | } |
||
| 90 |