| Conditions | 11 |
| Paths | 93 |
| Total Lines | 59 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 58 | public function listMigrations() |
||
| 59 | { |
||
| 60 | $db = Suricate::Database(true); |
||
| 61 | $dbConfigs = $db->getConfigs(); |
||
| 62 | unset($db); |
||
| 63 | $result = []; |
||
| 64 | |||
| 65 | $this->scanForMigrations(); |
||
| 66 | $suricateServices = Suricate::listServices(); |
||
| 67 | |||
| 68 | foreach ($suricateServices as $service) { |
||
| 69 | // Check all registered Suricate services if their |
||
| 70 | // migration handler has migrations to register |
||
| 71 | $serviceInstance = Suricate::$service(); |
||
| 72 | if ($serviceInstance instanceof Service) { |
||
| 73 | $serviceInstance->registerMigrations(); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | // Iterate through all databases configuration |
||
| 78 | foreach (array_keys($dbConfigs) as $dbConfigName) { |
||
| 79 | $result[$dbConfigName] = []; |
||
| 80 | |||
| 81 | // Create migration table if needed |
||
| 82 | $res = $this->initMigrationTable($dbConfigName); |
||
| 83 | switch ($res) { |
||
| 84 | case 0: |
||
| 85 | echo '[Migration] ✅ Migration table created successfully for config "' . $dbConfigName . '"' . "\n"; |
||
| 86 | break; |
||
| 87 | case 1: |
||
| 88 | echo '[Migration] ❌ Unsupported database type (config: "' . $dbConfigName . '")' . "\n"; |
||
| 89 | break; |
||
| 90 | } |
||
| 91 | |||
| 92 | // Load all DB listed migration for config |
||
| 93 | $migrations = MigrationModelList::loadAllWithConfig($dbConfigName); |
||
| 94 | $alreadyMigrated = []; |
||
| 95 | |||
| 96 | foreach ($migrations as $migration) { |
||
| 97 | $alreadyMigrated[$migration->name] = true; |
||
| 98 | $result[$dbConfigName][$migration->name] = $migration->date_added; |
||
| 99 | } |
||
| 100 | |||
| 101 | // 'ALL' config name for migrations that should me applied to all configs (eg: media-manager) |
||
| 102 | $confChecks = ['ALL', $dbConfigName]; |
||
| 103 | foreach ($confChecks as $currentConfigName) { |
||
| 104 | if (isset($this->registeredMigrations[$currentConfigName])) { |
||
| 105 | foreach (array_keys($this->registeredMigrations[$currentConfigName]) as $regMigrationName) { |
||
| 106 | if (isset($alreadyMigrated[$regMigrationName])) { |
||
| 107 | continue; |
||
| 108 | } |
||
| 109 | $result[$dbConfigName][$regMigrationName] = false; |
||
| 110 | } |
||
| 111 | } |
||
| 112 | } |
||
| 113 | ksort($result[$dbConfigName]); |
||
| 114 | } |
||
| 115 | |||
| 116 | return $result; |
||
| 117 | } |
||
| 209 |