| Conditions | 4 |
| Paths | 6 |
| Total Lines | 55 |
| Code Lines | 12 |
| 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 |
||
| 51 | private static function getMigrationQueries(PDO $connection): array |
||
| 52 | { |
||
| 53 | $driver = $connection->getAttribute(PDO::ATTR_DRIVER_NAME); |
||
| 54 | $createdAtDefault = ($driver === 'pgsql') ? 'DEFAULT NOW()' : 'DEFAULT CURRENT_TIMESTAMP'; |
||
| 55 | |||
| 56 | if ($driver === 'sqlite') { |
||
| 57 | $query = " |
||
| 58 | CREATE TABLE IF NOT EXISTS cacheer_table ( |
||
| 59 | id INTEGER PRIMARY KEY AUTOINCREMENT, |
||
| 60 | cacheKey VARCHAR(255) NOT NULL, |
||
| 61 | cacheData TEXT NOT NULL, |
||
| 62 | cacheNamespace VARCHAR(255), |
||
| 63 | expirationTime DATETIME NOT NULL, |
||
| 64 | created_at DATETIME $createdAtDefault, |
||
| 65 | UNIQUE(cacheKey, cacheNamespace) |
||
| 66 | ); |
||
| 67 | CREATE INDEX IF NOT EXISTS idx_cacheer_cacheKey ON cacheer_table (cacheKey); |
||
| 68 | CREATE INDEX IF NOT EXISTS idx_cacheer_cacheNamespace ON cacheer_table (cacheNamespace); |
||
| 69 | CREATE INDEX IF NOT EXISTS idx_cacheer_expirationTime ON cacheer_table (expirationTime); |
||
| 70 | CREATE INDEX IF NOT EXISTS idx_cacheer_key_namespace ON cacheer_table (cacheKey, cacheNamespace); |
||
| 71 | "; |
||
| 72 | } elseif ($driver === 'pgsql') { |
||
| 73 | $query = " |
||
| 74 | CREATE TABLE IF NOT EXISTS cacheer_table ( |
||
| 75 | id SERIAL PRIMARY KEY, |
||
| 76 | cacheKey VARCHAR(255) NOT NULL, |
||
| 77 | cacheData TEXT NOT NULL, |
||
| 78 | cacheNamespace VARCHAR(255), |
||
| 79 | expirationTime TIMESTAMP NOT NULL, |
||
| 80 | created_at TIMESTAMP $createdAtDefault, |
||
| 81 | UNIQUE(cacheKey, cacheNamespace) |
||
| 82 | ); |
||
| 83 | CREATE INDEX IF NOT EXISTS idx_cacheer_cacheKey ON cacheer_table (cacheKey); |
||
| 84 | CREATE INDEX IF NOT EXISTS idx_cacheer_cacheNamespace ON cacheer_table (cacheNamespace); |
||
| 85 | CREATE INDEX IF NOT EXISTS idx_cacheer_expirationTime ON cacheer_table (expirationTime); |
||
| 86 | CREATE INDEX IF NOT EXISTS idx_cacheer_key_namespace ON cacheer_table (cacheKey, cacheNamespace); |
||
| 87 | "; |
||
| 88 | } else { |
||
| 89 | $query = " |
||
| 90 | CREATE TABLE IF NOT EXISTS cacheer_table ( |
||
| 91 | id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, |
||
| 92 | cacheKey VARCHAR(255) NOT NULL, |
||
| 93 | cacheData LONGTEXT NOT NULL, |
||
| 94 | cacheNamespace VARCHAR(255) NULL, |
||
| 95 | expirationTime DATETIME NOT NULL, |
||
| 96 | created_at TIMESTAMP $createdAtDefault, |
||
| 97 | UNIQUE KEY unique_cache_key_namespace (cacheKey, cacheNamespace), |
||
| 98 | KEY idx_cacheer_cacheKey (cacheKey), |
||
| 99 | KEY idx_cacheer_cacheNamespace (cacheNamespace), |
||
| 100 | KEY idx_cacheer_expirationTime (expirationTime), |
||
| 101 | KEY idx_cacheer_key_namespace (cacheKey, cacheNamespace) |
||
| 102 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; |
||
| 103 | "; |
||
| 104 | } |
||
| 105 | return array_filter(array_map('trim', explode(';', $query))); |
||
| 106 | } |
||
| 108 |