| Conditions | 2 |
| Paths | 2 |
| Total Lines | 58 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 33 | public function safeUp() |
||
| 34 | { |
||
| 35 | $tableOptions = null; |
||
| 36 | |||
| 37 | if ('mysql' === $this->db->driverName) { |
||
| 38 | /* @link http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci */ |
||
| 39 | $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; |
||
| 40 | } |
||
| 41 | |||
| 42 | // Tables |
||
| 43 | $this->createTable( |
||
| 44 | $this->primaryTableName, |
||
| 45 | [ |
||
| 46 | 'id' => $this->primaryKey()->unsigned(), |
||
| 47 | 'key' => $this->string()->notNull()->unique(), |
||
| 48 | ], |
||
| 49 | $tableOptions |
||
| 50 | ); |
||
| 51 | $this->createTable( |
||
| 52 | $this->translationTableName, |
||
| 53 | [ |
||
| 54 | 'id' => $this->primaryKey()->unsigned(), |
||
| 55 | 'templateId' => $this->integer()->unsigned()->notNull(), |
||
| 56 | 'language' => $this->string(16)->notNull(), |
||
| 57 | 'subject' => $this->string()->notNull(), |
||
| 58 | 'body' => $this->text()->notNull(), |
||
| 59 | 'hint' => $this->string(500), |
||
| 60 | ], |
||
| 61 | $tableOptions |
||
| 62 | ); |
||
| 63 | |||
| 64 | // Indexes |
||
| 65 | $this->createIndex( |
||
| 66 | 'idx-email_template-key', |
||
| 67 | $this->primaryTableName, |
||
| 68 | 'key', |
||
| 69 | true |
||
| 70 | ); |
||
| 71 | $this->createIndex( |
||
| 72 | 'idx-email_template_translation-templateId', |
||
| 73 | $this->translationTableName, |
||
| 74 | 'templateId' |
||
| 75 | ); |
||
| 76 | $this->createIndex( |
||
| 77 | 'idx-email_template_translation-language', |
||
| 78 | $this->translationTableName, |
||
| 79 | 'language' |
||
| 80 | ); |
||
| 81 | |||
| 82 | // Foreign keys |
||
| 83 | $this->addForeignKey( |
||
| 84 | 'fk-email_template_translation-email_template', |
||
| 85 | $this->translationTableName, |
||
| 86 | 'templateId', |
||
| 87 | $this->primaryTableName, |
||
| 88 | 'id', |
||
| 89 | 'CASCADE', |
||
| 90 | 'CASCADE' |
||
| 91 | ); |
||
| 109 |