Conditions | 1 |
Paths | 1 |
Total Lines | 105 |
Code Lines | 78 |
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 |
||
114 | public function testListTableDetailsWithDifferentIdentifierQuotingRequirements() |
||
115 | { |
||
116 | $primaryTableName = '"Primary_Table"'; |
||
117 | $offlinePrimaryTable = new Schema\Table($primaryTableName); |
||
118 | $offlinePrimaryTable->addColumn( |
||
119 | '"Id"', |
||
120 | 'integer', |
||
121 | array('autoincrement' => true, 'comment' => 'Explicit casing.') |
||
122 | ); |
||
123 | $offlinePrimaryTable->addColumn('select', 'integer', array('comment' => 'Reserved keyword.')); |
||
124 | $offlinePrimaryTable->addColumn('foo', 'integer', array('comment' => 'Implicit uppercasing.')); |
||
125 | $offlinePrimaryTable->addColumn('BAR', 'integer'); |
||
126 | $offlinePrimaryTable->addColumn('"BAZ"', 'integer'); |
||
127 | $offlinePrimaryTable->addIndex(array('select'), 'from'); |
||
128 | $offlinePrimaryTable->addIndex(array('foo'), 'foo_index'); |
||
129 | $offlinePrimaryTable->addIndex(array('BAR'), 'BAR_INDEX'); |
||
130 | $offlinePrimaryTable->addIndex(array('"BAZ"'), 'BAZ_INDEX'); |
||
131 | $offlinePrimaryTable->setPrimaryKey(array('"Id"')); |
||
132 | |||
133 | $foreignTableName = 'foreign'; |
||
134 | $offlineForeignTable = new Schema\Table($foreignTableName); |
||
135 | $offlineForeignTable->addColumn('id', 'integer', array('autoincrement' => true)); |
||
136 | $offlineForeignTable->addColumn('"Fk"', 'integer'); |
||
137 | $offlineForeignTable->addIndex(array('"Fk"'), '"Fk_index"'); |
||
138 | $offlineForeignTable->addForeignKeyConstraint( |
||
139 | $primaryTableName, |
||
140 | array('"Fk"'), |
||
141 | array('"Id"'), |
||
142 | array(), |
||
143 | '"Primary_Table_Fk"' |
||
144 | ); |
||
145 | $offlineForeignTable->setPrimaryKey(array('id')); |
||
146 | |||
147 | $this->_sm->tryMethod('dropTable', $foreignTableName); |
||
148 | $this->_sm->tryMethod('dropTable', $primaryTableName); |
||
149 | |||
150 | $this->_sm->createTable($offlinePrimaryTable); |
||
151 | $this->_sm->createTable($offlineForeignTable); |
||
152 | |||
153 | $onlinePrimaryTable = $this->_sm->listTableDetails($primaryTableName); |
||
154 | $onlineForeignTable = $this->_sm->listTableDetails($foreignTableName); |
||
155 | |||
156 | $platform = $this->_sm->getDatabasePlatform(); |
||
157 | |||
158 | // Primary table assertions |
||
159 | self::assertSame($primaryTableName, $onlinePrimaryTable->getQuotedName($platform)); |
||
160 | |||
161 | self::assertTrue($onlinePrimaryTable->hasColumn('"Id"')); |
||
162 | self::assertSame('"Id"', $onlinePrimaryTable->getColumn('"Id"')->getQuotedName($platform)); |
||
163 | self::assertTrue($onlinePrimaryTable->hasPrimaryKey()); |
||
164 | self::assertSame(array('"Id"'), $onlinePrimaryTable->getPrimaryKey()->getQuotedColumns($platform)); |
||
165 | |||
166 | self::assertTrue($onlinePrimaryTable->hasColumn('select')); |
||
167 | self::assertSame('"select"', $onlinePrimaryTable->getColumn('select')->getQuotedName($platform)); |
||
168 | |||
169 | self::assertTrue($onlinePrimaryTable->hasColumn('foo')); |
||
170 | self::assertSame('FOO', $onlinePrimaryTable->getColumn('foo')->getQuotedName($platform)); |
||
171 | |||
172 | self::assertTrue($onlinePrimaryTable->hasColumn('BAR')); |
||
173 | self::assertSame('BAR', $onlinePrimaryTable->getColumn('BAR')->getQuotedName($platform)); |
||
174 | |||
175 | self::assertTrue($onlinePrimaryTable->hasColumn('"BAZ"')); |
||
176 | self::assertSame('BAZ', $onlinePrimaryTable->getColumn('"BAZ"')->getQuotedName($platform)); |
||
177 | |||
178 | self::assertTrue($onlinePrimaryTable->hasIndex('from')); |
||
179 | self::assertTrue($onlinePrimaryTable->getIndex('from')->hasColumnAtPosition('"select"')); |
||
180 | self::assertSame(array('"select"'), $onlinePrimaryTable->getIndex('from')->getQuotedColumns($platform)); |
||
181 | |||
182 | self::assertTrue($onlinePrimaryTable->hasIndex('foo_index')); |
||
183 | self::assertTrue($onlinePrimaryTable->getIndex('foo_index')->hasColumnAtPosition('foo')); |
||
184 | self::assertSame(array('FOO'), $onlinePrimaryTable->getIndex('foo_index')->getQuotedColumns($platform)); |
||
185 | |||
186 | self::assertTrue($onlinePrimaryTable->hasIndex('BAR_INDEX')); |
||
187 | self::assertTrue($onlinePrimaryTable->getIndex('BAR_INDEX')->hasColumnAtPosition('BAR')); |
||
188 | self::assertSame(array('BAR'), $onlinePrimaryTable->getIndex('BAR_INDEX')->getQuotedColumns($platform)); |
||
189 | |||
190 | self::assertTrue($onlinePrimaryTable->hasIndex('BAZ_INDEX')); |
||
191 | self::assertTrue($onlinePrimaryTable->getIndex('BAZ_INDEX')->hasColumnAtPosition('"BAZ"')); |
||
192 | self::assertSame(array('BAZ'), $onlinePrimaryTable->getIndex('BAZ_INDEX')->getQuotedColumns($platform)); |
||
193 | |||
194 | // Foreign table assertions |
||
195 | self::assertTrue($onlineForeignTable->hasColumn('id')); |
||
196 | self::assertSame('ID', $onlineForeignTable->getColumn('id')->getQuotedName($platform)); |
||
197 | self::assertTrue($onlineForeignTable->hasPrimaryKey()); |
||
198 | self::assertSame(array('ID'), $onlineForeignTable->getPrimaryKey()->getQuotedColumns($platform)); |
||
199 | |||
200 | self::assertTrue($onlineForeignTable->hasColumn('"Fk"')); |
||
201 | self::assertSame('"Fk"', $onlineForeignTable->getColumn('"Fk"')->getQuotedName($platform)); |
||
202 | |||
203 | self::assertTrue($onlineForeignTable->hasIndex('"Fk_index"')); |
||
204 | self::assertTrue($onlineForeignTable->getIndex('"Fk_index"')->hasColumnAtPosition('"Fk"')); |
||
205 | self::assertSame(array('"Fk"'), $onlineForeignTable->getIndex('"Fk_index"')->getQuotedColumns($platform)); |
||
206 | |||
207 | self::assertTrue($onlineForeignTable->hasForeignKey('"Primary_Table_Fk"')); |
||
208 | self::assertSame( |
||
209 | $primaryTableName, |
||
210 | $onlineForeignTable->getForeignKey('"Primary_Table_Fk"')->getQuotedForeignTableName($platform) |
||
211 | ); |
||
212 | self::assertSame( |
||
213 | array('"Fk"'), |
||
214 | $onlineForeignTable->getForeignKey('"Primary_Table_Fk"')->getQuotedLocalColumns($platform) |
||
215 | ); |
||
216 | self::assertSame( |
||
217 | array('"Id"'), |
||
218 | $onlineForeignTable->getForeignKey('"Primary_Table_Fk"')->getQuotedForeignColumns($platform) |
||
219 | ); |
||
302 |