| Conditions | 4 |
| Paths | 6 |
| Total Lines | 66 |
| Code Lines | 15 |
| 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 |
||
| 27 | function updateDramielDB($logger) |
||
| 28 | { |
||
| 29 | $tables = array('storage', 'messageQueue', 'renameQueue', 'corpCache', 'contactList'); |
||
| 30 | |||
| 31 | $tableCreateCode = array( |
||
| 32 | 'storage' => ' |
||
| 33 | BEGIN; |
||
| 34 | CREATE TABLE IF NOT EXISTS `storage` ( |
||
| 35 | `id` INTEGER PRIMARY KEY AUTOINCREMENT, |
||
| 36 | `key` VARCHAR(255) NOT NULL, |
||
| 37 | `value` VARCHAR(255) NOT NULL |
||
| 38 | ); |
||
| 39 | CREATE UNIQUE INDEX key ON storage (key); |
||
| 40 | COMMIT;', |
||
| 41 | 'messageQueue' => ' |
||
| 42 | BEGIN; |
||
| 43 | CREATE TABLE IF NOT EXISTS `messageQueue` ( |
||
| 44 | `id` INTEGER PRIMARY KEY AUTOINCREMENT, |
||
| 45 | `message` VARCHAR(255) NOT NULL, |
||
| 46 | `channel` VARCHAR(255) NOT NULL, |
||
| 47 | `guild` VARCHAR(255) NOT NULL |
||
| 48 | ); |
||
| 49 | COMMIT;', |
||
| 50 | 'renameQueue' => ' |
||
| 51 | BEGIN; |
||
| 52 | CREATE TABLE IF NOT EXISTS `renameQueue` ( |
||
| 53 | `id` INTEGER PRIMARY KEY AUTOINCREMENT, |
||
| 54 | `discordID` VARCHAR(255) NOT NULL, |
||
| 55 | `nick` VARCHAR(255) NOT NULL, |
||
| 56 | `guild` VARCHAR(255) NOT NULL |
||
| 57 | ); |
||
| 58 | COMMIT;', |
||
| 59 | 'corpCache' => ' |
||
| 60 | BEGIN; |
||
| 61 | CREATE TABLE IF NOT EXISTS `corpCache` ( |
||
| 62 | `id` INTEGER PRIMARY KEY AUTOINCREMENT, |
||
| 63 | `corpID` VARCHAR(255) NOT NULL UNIQUE, |
||
| 64 | `corpTicker` VARCHAR(255) NOT NULL, |
||
| 65 | `corpName` VARCHAR(255) NOT NULL |
||
| 66 | ); |
||
| 67 | COMMIT;', |
||
| 68 | 'contactList' => ' |
||
| 69 | BEGIN; |
||
| 70 | CREATE TABLE IF NOT EXISTS `contactList` ( |
||
| 71 | `id` INTEGER PRIMARY KEY AUTOINCREMENT, |
||
| 72 | `contactID` VARCHAR(255) NOT NULL UNIQUE, |
||
| 73 | `contactName` VARCHAR(255) NOT NULL, |
||
| 74 | `standing` VARCHAR(255) NOT NULL |
||
| 75 | ); |
||
| 76 | COMMIT;', |
||
| 77 | ); |
||
| 78 | |||
| 79 | // Does the file exist? |
||
| 80 | if (!file_exists(__DIR__ . '/../../database/dramiel.sqlite')) { |
||
| 81 | touch(__DIR__ . '/../../database/dramiel.sqlite'); |
||
| 82 | } |
||
| 83 | |||
| 84 | // Create table if not exists |
||
| 85 | foreach ($tables as $table) { |
||
| 86 | $exists = dbQueryField("SELECT name FROM sqlite_master WHERE type = 'table' AND name = :name", 'name', array(':name' => $table)); |
||
| 87 | if (!$exists) { |
||
| 88 | $logger->addInfo("Creating {$table} in dramiel.sqlite, since it does not exist"); |
||
| 89 | dbExecute(trim($tableCreateCode[$table])); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | } |