| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 59 | 
| Code Lines | 41 | 
| 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  | 
            ||
| 69 | public function testVariations(): void  | 
            ||
| 70 |     { | 
            ||
| 71 | $ballRoot = $this->objFromFixture(Product::class, 'ball');  | 
            ||
| 72 | // add parent for categories in JSON response  | 
            ||
| 73 | $parent = $this->objFromFixture(ProductCategory::class, 'products');  | 
            ||
| 74 | $ballRoot->ParentID = $parent->ID;  | 
            ||
| 75 | $ballRoot->write();  | 
            ||
| 76 | |||
| 77 |         $ballRoot->copyVersionToStage('Stage', 'Live'); | 
            ||
| 78 | $ball1 = $this->objFromFixture(Variation::class, 'redLarge');  | 
            ||
| 79 | $ball2 = $this->objFromFixture(Variation::class, 'redSmall');  | 
            ||
| 80 |         $this->logInWithPermission('ADMIN'); | 
            ||
| 81 | $ball1->publishSingle();  | 
            ||
| 82 | $ball2->publishSingle();  | 
            ||
| 83 | |||
| 84 | // Add the two variation items  | 
            ||
| 85 | $response = $this->get(ShoppingCartController::add_item_link($ball1) . "?ajax=1");  | 
            ||
| 86 | $this->assertEquals(  | 
            ||
| 87 | 200,  | 
            ||
| 88 | $response->getStatusCode(),  | 
            ||
| 89 | "Response status code is 200"  | 
            ||
| 90 | );  | 
            ||
| 91 | $this->assertEquals(  | 
            ||
| 92 | "application/json; charset=utf-8",  | 
            ||
| 93 |             $response->getHeader("Content-Type"), | 
            ||
| 94 | "Json response header"  | 
            ||
| 95 | );  | 
            ||
| 96 | $this->assertJson(  | 
            ||
| 97 | $response->getBody(),  | 
            ||
| 98 | "Contains json in the body of the response"  | 
            ||
| 99 | );  | 
            ||
| 100 | $this->assertStringContainsString(  | 
            ||
| 101 | "Size:Large, Color:Red",  | 
            ||
| 102 | $response->getBody(),  | 
            ||
| 103 | "Contains json in the body of the cart id"  | 
            ||
| 104 | );  | 
            ||
| 105 | |||
| 106 | $response = $this->get(ShoppingCartController::add_item_link($ball2) . "?ajax=1");  | 
            ||
| 107 | $items = ShoppingCart::curr()->Items();  | 
            ||
| 108 | $this->assertEquals(  | 
            ||
| 109 | $items->Count(),  | 
            ||
| 110 | 2,  | 
            ||
| 111 | "There are 2 items in the cart"  | 
            ||
| 112 | );  | 
            ||
| 113 | |||
| 114 | // Remove one and see what happens  | 
            ||
| 115 | $this->get(ShoppingCartController::remove_all_item_link($ball1) . "?ajax=1");  | 
            ||
| 116 | $this->assertEquals(  | 
            ||
| 117 | $items->Count(),  | 
            ||
| 118 | 1,  | 
            ||
| 119 | "There is 1 item in the cart"  | 
            ||
| 120 | );  | 
            ||
| 121 | $this->assertNull(  | 
            ||
| 122 | $this->cart->get($ball1),  | 
            ||
| 123 | "first item not in cart"  | 
            ||
| 124 | );  | 
            ||
| 125 | $this->assertNotNull(  | 
            ||
| 126 | $this->cart->get($ball2),  | 
            ||
| 127 | "second item is still in cart"  | 
            ||
| 128 | );  | 
            ||
| 131 |