| Conditions | 1 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 26 |
| 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 |
||
| 75 | public function testDeleteLocalisedRecords() |
||
| 76 | { |
||
| 77 | // Write in en-US |
||
| 78 | $record = new LocalisedRecord(); |
||
| 79 | $record->Title = 'us spanish content'; |
||
| 80 | $record->write(); |
||
| 81 | $recordID = $record->ID; |
||
| 82 | |||
| 83 | // Write in en-nz |
||
| 84 | FluentState::singleton()->withState(function (FluentState $newState) use ($recordID) { |
||
| 85 | $newState->setLocale('en_NZ'); |
||
| 86 | $record = LocalisedRecord::get()->byID($recordID); |
||
| 87 | $record->Title = 'nz content'; |
||
| 88 | $record->write(); |
||
| 89 | }); |
||
| 90 | |||
| 91 | // We should have 1 base record, 2 localised records |
||
| 92 | $this->assertEquals( |
||
| 93 | 2, |
||
| 94 | DB::query('SELECT COUNT("ID") FROM "FluentDeleteTest_LocalisedRecord_Localised"')->value() |
||
| 95 | ); |
||
| 96 | $this->assertEquals( |
||
| 97 | 1, |
||
| 98 | DB::query('SELECT COUNT("ID") FROM "FluentDeleteTest_LocalisedRecord"')->value() |
||
| 99 | ); |
||
| 100 | |||
| 101 | // Delete in base locale should reduce a _Localised count |
||
| 102 | $record->delete(); |
||
| 103 | $this->assertEquals( |
||
| 104 | 1, |
||
| 105 | DB::query('SELECT COUNT("ID") FROM "FluentDeleteTest_LocalisedRecord_Localised"')->value() |
||
| 106 | ); |
||
| 107 | $this->assertEquals( |
||
| 108 | 1, |
||
| 109 | DB::query('SELECT COUNT("ID") FROM "FluentDeleteTest_LocalisedRecord"')->value() |
||
| 110 | ); |
||
| 111 | |||
| 112 | // Delete in en-nz should remove all _Localised and base |
||
| 113 | FluentState::singleton()->withState(function (FluentState $newState) use ($recordID) { |
||
| 114 | $newState->setLocale('en_NZ'); |
||
| 115 | $record = LocalisedRecord::get()->byID($recordID); |
||
| 116 | $record->delete(); |
||
| 117 | }); |
||
| 118 | |||
| 119 | $this->assertEquals( |
||
| 120 | 0, |
||
| 121 | DB::query('SELECT COUNT("ID") FROM "FluentDeleteTest_LocalisedRecord_Localised"')->value() |
||
| 122 | ); |
||
| 123 | $this->assertEquals( |
||
| 124 | 0, |
||
| 125 | DB::query('SELECT COUNT("ID") FROM "FluentDeleteTest_LocalisedRecord"')->value() |
||
| 126 | ); |
||
| 177 |