| Conditions | 1 |
| Paths | 1 |
| Total Lines | 62 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 47 | public function testPublishing() |
||
| 48 | { |
||
| 49 | // Check that write updates Stage |
||
| 50 | |||
| 51 | $item = new SearchVariantVersionedTest_Item(array('TestText' => 'Foo')); |
||
| 52 | $item->write(); |
||
| 53 | |||
| 54 | SearchUpdater::flush_dirty_indexes(); |
||
| 55 | $this->assertEquals(array( |
||
| 56 | array('ID' => $item->ID, '_versionedstage' => 'Stage') |
||
| 57 | ), self::$index->getAdded(array('ID', '_versionedstage'))); |
||
| 58 | |||
| 59 | // Check that publish updates Live |
||
| 60 | |||
| 61 | self::$index->reset(); |
||
| 62 | |||
| 63 | $item->copyVersionToStage('Stage', 'Live'); |
||
|
|
|||
| 64 | |||
| 65 | SearchUpdater::flush_dirty_indexes(); |
||
| 66 | $this->assertEquals(array( |
||
| 67 | array('ID' => $item->ID, '_versionedstage' => 'Stage'), |
||
| 68 | array('ID' => $item->ID, '_versionedstage' => 'Live') |
||
| 69 | ), self::$index->getAdded(array('ID', '_versionedstage'))); |
||
| 70 | |||
| 71 | // Just update a SiteTree field, and check it updates Stage |
||
| 72 | |||
| 73 | self::$index->reset(); |
||
| 74 | |||
| 75 | $item->Title = "Pow!"; |
||
| 76 | $item->write(); |
||
| 77 | |||
| 78 | SearchUpdater::flush_dirty_indexes(); |
||
| 79 | |||
| 80 | $expected = array(array( |
||
| 81 | 'ID' => $item->ID, |
||
| 82 | '_versionedstage' => 'Stage' |
||
| 83 | )); |
||
| 84 | $added = self::$index->getAdded(array('ID', '_versionedstage')); |
||
| 85 | $this->assertEquals($expected, $added); |
||
| 86 | |||
| 87 | // Test unpublish |
||
| 88 | |||
| 89 | self::$index->reset(); |
||
| 90 | |||
| 91 | $item->deleteFromStage('Live'); |
||
| 92 | |||
| 93 | SearchUpdater::flush_dirty_indexes(); |
||
| 94 | |||
| 95 | $this->assertCount(1, self::$index->deleted); |
||
| 96 | $this->assertEquals( |
||
| 97 | SiteTree::class, |
||
| 98 | self::$index->deleted[0]['base'] |
||
| 99 | ); |
||
| 100 | $this->assertEquals( |
||
| 101 | $item->ID, |
||
| 102 | self::$index->deleted[0]['id'] |
||
| 103 | ); |
||
| 104 | $this->assertEquals( |
||
| 105 | 'Live', |
||
| 106 | self::$index->deleted[0]['state'][SearchVariantVersioned::class] |
||
| 107 | ); |
||
| 108 | } |
||
| 109 | |||
| 143 |
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: