| Conditions | 5 |
| Paths | 16 |
| Total Lines | 51 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 19 | public function up(Schema $schema): void |
||
| 20 | { |
||
| 21 | $schemaManager = $this->connection->createSchemaManager(); |
||
| 22 | |||
| 23 | // Create justification_document table |
||
| 24 | if (!$schemaManager->tablesExist(['justification_document'])) { |
||
| 25 | $this->addSql(' |
||
| 26 | CREATE TABLE justification_document ( |
||
| 27 | id INT AUTO_INCREMENT NOT NULL, |
||
| 28 | code LONGTEXT DEFAULT NULL, |
||
| 29 | name LONGTEXT DEFAULT NULL, |
||
| 30 | validity_duration INT DEFAULT NULL, |
||
| 31 | comment LONGTEXT DEFAULT NULL, |
||
| 32 | date_manual_on INT DEFAULT NULL, |
||
| 33 | PRIMARY KEY(id) |
||
| 34 | ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC; |
||
| 35 | '); |
||
| 36 | } |
||
| 37 | |||
| 38 | // Create justification_document_rel_users table |
||
| 39 | if (!$schemaManager->tablesExist(['justification_document_rel_users'])) { |
||
| 40 | $this->addSql(' |
||
| 41 | CREATE TABLE justification_document_rel_users ( |
||
| 42 | id INT AUTO_INCREMENT NOT NULL, |
||
| 43 | justification_document_id INT DEFAULT NULL, |
||
| 44 | user_id INT DEFAULT NULL, |
||
| 45 | file_path VARCHAR(255) DEFAULT NULL, |
||
| 46 | date_validity DATE DEFAULT NULL, |
||
| 47 | INDEX IDX_D1BB19421F2B6144 (justification_document_id), |
||
| 48 | INDEX IDX_D1BB1942A76ED395 (user_id), |
||
| 49 | PRIMARY KEY(id) |
||
| 50 | ) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC; |
||
| 51 | '); |
||
| 52 | } |
||
| 53 | |||
| 54 | // Add foreign key constraints |
||
| 55 | $foreignKeys = $schemaManager->listTableForeignKeys('justification_document_rel_users'); |
||
| 56 | $foreignKeyNames = array_map(fn($fk) => $fk->getName(), $foreignKeys); |
||
| 57 | |||
| 58 | if (!in_array('FK_D1BB19421F2B6144', $foreignKeyNames, true)) { |
||
| 59 | $this->addSql(' |
||
| 60 | ALTER TABLE justification_document_rel_users |
||
| 61 | ADD CONSTRAINT FK_D1BB19421F2B6144 |
||
| 62 | FOREIGN KEY (justification_document_id) |
||
| 63 | REFERENCES justification_document (id) |
||
| 64 | ON DELETE CASCADE; |
||
| 65 | '); |
||
| 66 | } |
||
| 67 | |||
| 68 | if (!in_array('FK_D1BB1942A76ED395', $foreignKeyNames, true)) { |
||
| 69 | $this->addSql(' |
||
| 70 | ALTER TABLE justification_document_rel_users |
||
| 114 |