Conditions | 2 |
Paths | 2 |
Total Lines | 68 |
Code Lines | 43 |
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 |
||
33 | public function safeUp() |
||
34 | { |
||
35 | $tableOptions = null; |
||
36 | if ($this->db->getDriverName() === 'mysql') { |
||
37 | /* @link http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci */ |
||
38 | $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; |
||
39 | } |
||
40 | |||
41 | // tables |
||
42 | $this->createTable( |
||
43 | $this->primaryTableName, |
||
44 | [ |
||
45 | 'id' => $this->primaryKey(), |
||
46 | |||
47 | 'slug' => $this->string()->notNull()->unique(), |
||
48 | 'published' => $this->boolean()->notNull()->defaultValue(true), |
||
49 | 'views_count' => $this->integer()->unsigned()->notNull()->defaultValue(0), |
||
50 | |||
51 | 'created_at' => $this->integer()->unsigned()->notNull()->defaultValue(0), |
||
52 | 'updated_at' => $this->integer()->unsigned()->notNull()->defaultValue(0), |
||
53 | |||
54 | 'valid_from' => $this->dateTime()->null(), |
||
55 | 'valid_until' => $this->dateTime()->null(), |
||
56 | ], |
||
57 | $tableOptions |
||
58 | ); |
||
59 | $this->createTable( |
||
60 | $this->translationTableName, |
||
61 | [ |
||
62 | 'id' => $this->primaryKey(), |
||
63 | 'banner_id' => $this->integer()->unsigned()->notNull(), |
||
64 | |||
65 | 'language' => $this->string(16)->notNull(), |
||
66 | 'content' => $this->text()->null(), |
||
67 | 'hint' => $this->string()->null(), |
||
68 | |||
69 | 'file_name' => $this->string()->notNull(), |
||
70 | 'alt' => $this->string()->null(), |
||
71 | |||
72 | 'link' => $this->string()->notNull()->defaultValue('#'), |
||
73 | ], |
||
74 | $tableOptions |
||
75 | ); |
||
76 | |||
77 | // foreign keys |
||
78 | $this->addForeignKey( |
||
79 | 'fk-banner_translation-banner_id-banner-id', |
||
80 | $this->translationTableName, |
||
81 | 'banner_id', |
||
82 | 'banner', |
||
83 | 'id', |
||
84 | 'CASCADE', |
||
85 | 'CASCADE' |
||
86 | ); |
||
87 | |||
88 | // indexes |
||
89 | $this->createIndex( |
||
90 | 'idx-banner-slug', |
||
91 | $this->primaryTableName, |
||
92 | 'slug', |
||
93 | true |
||
94 | ); |
||
95 | $this->createIndex( |
||
96 | 'idx-banner_translation-banner_id', |
||
97 | $this->translationTableName, |
||
98 | 'banner_id' |
||
99 | ); |
||
100 | } |
||
101 | |||
119 |