Conditions | 1 |
Paths | 1 |
Total Lines | 65 |
Code Lines | 35 |
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 |
||
152 | public function testArchive(): void |
||
153 | { |
||
154 | FluentState::singleton()->withState(function (FluentState $state): void { |
||
155 | $state->setLocale('en_US'); |
||
156 | |||
157 | /** @var FluentDataObject|Versioned|FluentVersionedExtension $object */ |
||
158 | $object = FluentDataObject::get()->byID($this->objectId); |
||
159 | $object->doArchive(); |
||
160 | }); |
||
161 | |||
162 | FluentState::singleton()->withState(function (FluentState $state): void { |
||
163 | $state->setLocale('jp_JP'); |
||
164 | |||
165 | /** @var FluentDataObject|Versioned|FluentVersionedExtension $object */ |
||
166 | $object = FluentDataObject::get()->byID($this->objectId); |
||
167 | $object->doArchive(); |
||
168 | }); |
||
169 | |||
170 | FluentState::singleton()->withState(function (FluentState $state): void { |
||
171 | $state->setLocale('en_US'); |
||
172 | |||
173 | /** @var FluentDataObject|Versioned|FluentVersionedExtension $object */ |
||
174 | $object = Versioned::get_latest_version(FluentDataObject::class, $this->objectId); |
||
175 | |||
176 | $this->assertNotNull($object); |
||
177 | $this->assertTrue($object->isArchived()); |
||
178 | $this->assertTrue($object->hasArchiveInLocale()); |
||
179 | |||
180 | // Restore |
||
181 | $object->writeToStage(Versioned::DRAFT); |
||
182 | |||
183 | $object = FluentDataObject::get()->byID($this->objectId); |
||
184 | $this->assertEquals('US Description', $object->Description); |
||
185 | }); |
||
186 | |||
187 | FluentState::singleton()->withState(function (FluentState $state): void { |
||
188 | $state->setLocale('jp_JP'); |
||
189 | |||
190 | /** @var FluentDataObject|Versioned|FluentVersionedExtension $object */ |
||
191 | $object = Versioned::get_latest_version(FluentDataObject::class, $this->objectId); |
||
192 | $this->assertNotNull($object); |
||
193 | |||
194 | $this->assertNotNull($object); |
||
195 | $this->assertTrue($object->isArchived()); |
||
196 | $this->assertTrue($object->hasArchiveInLocale()); |
||
197 | |||
198 | // Restore |
||
199 | $object->writeToStage(Versioned::DRAFT); |
||
200 | |||
201 | $object = FluentDataObject::get()->byID($this->objectId); |
||
202 | $this->assertEquals('JP Description', $object->Description); |
||
203 | }); |
||
204 | |||
205 | FluentState::singleton()->withState(function (FluentState $state): void { |
||
206 | $state->setLocale('en_CA'); |
||
207 | |||
208 | /** @var FluentDataObject|Versioned|FluentVersionedExtension $object */ |
||
209 | $object = Versioned::get_latest_version(FluentDataObject::class, $this->objectId); |
||
210 | $this->assertNull($object); |
||
211 | |||
212 | $object = FluentDataObject::get()->byID($this->objectId); |
||
213 | |||
214 | $this->assertNotNull($object); |
||
215 | $this->assertFalse($object->isArchived()); |
||
216 | $this->assertFalse($object->hasArchiveInLocale()); |
||
217 | }); |
||
252 |