| Conditions | 2 |
| Paths | 2 |
| Total Lines | 133 |
| Code Lines | 107 |
| 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 |
||
| 99 | protected function createTheSchemasTables() |
||
| 100 | { |
||
| 101 | $stmts = []; |
||
| 102 | $connection = $this->getContainer()->get('db_connection'); |
||
| 103 | |||
| 104 | /*** Users Table **************************************************/ |
||
| 105 | |||
| 106 | $stmts[] = <<<'SQL' |
||
| 107 | CREATE TABLE IF NOT EXISTS `user` ( |
||
| 108 | `user_id` INT UNSIGNED NOT NULL AUTO_INCREMENT, |
||
| 109 | `user_name` VARCHAR(255) NOT NULL, |
||
| 110 | `user_email` VARCHAR(100) NOT NULL, |
||
| 111 | `user_pass` VARCHAR(128) NOT NULL, |
||
| 112 | `user_role` VARCHAR(45) NOT NULL, |
||
| 113 | `user_created_at` DATETIME NOT NULL, |
||
| 114 | `user_status` VARCHAR(45) NOT NULL, |
||
| 115 | `user_meta` JSON NULL, |
||
| 116 | PRIMARY KEY (`user_id`)) |
||
| 117 | ENGINE = InnoDB |
||
| 118 | SQL; |
||
| 119 | |||
| 120 | $stmts[] = <<<'SQL' |
||
| 121 | CREATE UNIQUE INDEX `user_email_UNIQUE` ON `user` (`user_email` ASC) |
||
| 122 | SQL; |
||
| 123 | |||
| 124 | /*** Cities Table *************************************************/ |
||
| 125 | |||
| 126 | $stmts[] = <<<'SQL' |
||
| 127 | CREATE TABLE IF NOT EXISTS `city` ( |
||
| 128 | `city_id` INT UNSIGNED NOT NULL AUTO_INCREMENT, |
||
| 129 | `city_name` VARCHAR(255) NOT NULL, |
||
| 130 | `city_created_at` DATETIME NOT NULL, |
||
| 131 | `city_created_by` INT UNSIGNED NULL, |
||
| 132 | PRIMARY KEY (`city_id`), |
||
| 133 | CONSTRAINT `city_created_by` |
||
| 134 | FOREIGN KEY (`city_created_by`) |
||
| 135 | REFERENCES `user` (`user_id`) |
||
| 136 | ON DELETE SET NULL |
||
| 137 | ON UPDATE CASCADE) |
||
| 138 | ENGINE = InnoDB |
||
| 139 | SQL; |
||
| 140 | |||
| 141 | $stmts[] = <<<'SQL' |
||
| 142 | CREATE INDEX `city_created_by_idx` ON `city` (`city_created_by` ASC) |
||
| 143 | SQL; |
||
| 144 | |||
| 145 | $stmts[] = <<<'SQL' |
||
| 146 | CREATE UNIQUE INDEX `city_name_UNIQUE` ON `city` (`city_name` ASC) |
||
| 147 | SQL; |
||
| 148 | |||
| 149 | /*** Districts Table **********************************************/ |
||
| 150 | |||
| 151 | $stmts[] = <<<'SQL' |
||
| 152 | CREATE TABLE IF NOT EXISTS `district` ( |
||
| 153 | `district_id` INT UNSIGNED NOT NULL AUTO_INCREMENT, |
||
| 154 | `district_name` VARCHAR(255) NOT NULL, |
||
| 155 | `district_city_id` INT UNSIGNED NOT NULL, |
||
| 156 | `district_created_at` DATETIME NOT NULL, |
||
| 157 | `district_created_by` INT UNSIGNED NULL, |
||
| 158 | PRIMARY KEY (`district_id`), |
||
| 159 | CONSTRAINT `district_city_id` |
||
| 160 | FOREIGN KEY (`district_city_id`) |
||
| 161 | REFERENCES `city` (`city_id`) |
||
| 162 | ON DELETE NO ACTION |
||
| 163 | ON UPDATE NO ACTION, |
||
| 164 | CONSTRAINT `district_created_by` |
||
| 165 | FOREIGN KEY (`district_created_by`) |
||
| 166 | REFERENCES `user` (`user_id`) |
||
| 167 | ON DELETE SET NULL |
||
| 168 | ON UPDATE CASCADE) |
||
| 169 | ENGINE = InnoDB |
||
| 170 | SQL; |
||
| 171 | |||
| 172 | $stmts[] = <<<'SQL' |
||
| 173 | CREATE INDEX `district_city_id_idx` ON `district` (`district_city_id` ASC) |
||
| 174 | SQL; |
||
| 175 | |||
| 176 | $stmts[] = <<<'SQL' |
||
| 177 | CREATE INDEX `district_created_by_idx` ON `district` (`district_created_by` ASC) |
||
| 178 | SQL; |
||
| 179 | |||
| 180 | $stmts[] = <<<'SQL' |
||
| 181 | CREATE UNIQUE INDEX `district_name_UNIQUE` ON `district` (`district_name` ASC, `district_city_id` ASC) |
||
| 182 | SQL; |
||
| 183 | |||
| 184 | /*** Donors Table *************************************************/ |
||
| 185 | |||
| 186 | $stmts[] = <<<'SQL' |
||
| 187 | CREATE TABLE IF NOT EXISTS `donor` ( |
||
| 188 | `donor_id` INT UNSIGNED NOT NULL AUTO_INCREMENT, |
||
| 189 | `donor_name` VARCHAR(255) NOT NULL, |
||
| 190 | `donor_gender` VARCHAR(45) NOT NULL, |
||
| 191 | `donor_birthdate` DATE NOT NULL, |
||
| 192 | `donor_blood_group` VARCHAR(45) NOT NULL, |
||
| 193 | `donor_district_id` INT UNSIGNED NOT NULL, |
||
| 194 | `donor_created_at` DATETIME NOT NULL, |
||
| 195 | `donor_created_by` INT UNSIGNED NULL, |
||
| 196 | `donor_status` VARCHAR(45) NOT NULL, |
||
| 197 | `donor_meta` JSON NULL, |
||
| 198 | PRIMARY KEY (`donor_id`), |
||
| 199 | CONSTRAINT `donor_district_id` |
||
| 200 | FOREIGN KEY (`donor_district_id`) |
||
| 201 | REFERENCES `district` (`district_id`) |
||
| 202 | ON DELETE NO ACTION |
||
| 203 | ON UPDATE NO ACTION, |
||
| 204 | CONSTRAINT `donor_created_by` |
||
| 205 | FOREIGN KEY (`donor_created_by`) |
||
| 206 | REFERENCES `user` (`user_id`) |
||
| 207 | ON DELETE SET NULL |
||
| 208 | ON UPDATE CASCADE) |
||
| 209 | ENGINE = InnoDB |
||
| 210 | SQL; |
||
| 211 | |||
| 212 | $stmts[] = <<<'SQL' |
||
| 213 | CREATE INDEX `donor_district_id_idx` ON `donor` (`donor_district_id` ASC) |
||
| 214 | SQL; |
||
| 215 | |||
| 216 | $stmts[] = <<<'SQL' |
||
| 217 | CREATE INDEX `donor_created_by_idx` ON `donor` (`donor_created_by` ASC) |
||
| 218 | SQL; |
||
| 219 | |||
| 220 | /*** Variables Table **********************************************/ |
||
| 221 | |||
| 222 | $stmts[] = <<<'SQL' |
||
| 223 | CREATE TABLE IF NOT EXISTS `variable` ( |
||
| 224 | `variable_name` VARCHAR(45) NOT NULL, |
||
| 225 | `variable_value` LONGTEXT NULL, |
||
| 226 | PRIMARY KEY (`variable_name`)) |
||
| 227 | ENGINE = InnoDB |
||
| 228 | SQL; |
||
| 229 | |||
| 230 | foreach ($stmts as $stmt) { |
||
| 231 | $connection->exec($stmt); |
||
| 232 | } |
||
| 329 |