| Conditions | 1 |
| Paths | 1 |
| Total Lines | 55 |
| Code Lines | 33 |
| 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 |
||
| 99 | public function testListTasks() |
||
| 100 | { |
||
| 101 | $queue = ServiceContainer::getInstance()->queue; |
||
| 102 | |||
| 103 | $task1 = new Task( |
||
| 104 | new Profile('profile1'), |
||
| 105 | new DummyJob, |
||
| 106 | [ |
||
| 107 | 'param1' => 'value1', |
||
| 108 | 'param2' => 'value2', |
||
| 109 | ], [ |
||
| 110 | 'tag1', 'tag2' |
||
| 111 | ] |
||
| 112 | ); |
||
| 113 | |||
| 114 | $request1 = new ServerRequest([], [], '/tasks', 'POST', 'php://input', [ |
||
| 115 | 'content-type' => 'application/json', |
||
| 116 | ], [], [], $task1->jsonSerialize()); |
||
| 117 | |||
| 118 | $response1 = (new AddTask($queue))->handle($request1); |
||
| 119 | $this->assertEquals(200, $response1->getStatusCode()); |
||
| 120 | |||
| 121 | $task2 = new Task( |
||
| 122 | new Profile('profile1'), |
||
| 123 | new DummyJob, |
||
| 124 | [ |
||
| 125 | 'param1' => 'value1', |
||
| 126 | 'param2' => 'value2', |
||
| 127 | ], [ |
||
| 128 | 'tag1', 'tag2' |
||
| 129 | ] |
||
| 130 | ); |
||
| 131 | |||
| 132 | $request2 = new ServerRequest([], [], '/tasks', 'POST', 'php://input', [ |
||
| 133 | 'content-type' => 'application/json', |
||
| 134 | ], [], [], $task2->jsonSerialize()); |
||
| 135 | |||
| 136 | $response2 = (new AddTask($queue))->handle($request2); |
||
| 137 | $this->assertEquals(200, $response2->getStatusCode()); |
||
| 138 | |||
| 139 | $request = new ServerRequest([], [], '/tasks', 'GET'); |
||
| 140 | |||
| 141 | $response = (new ListTasks($queue))->handle($request); |
||
| 142 | $this->assertEquals(200, $response->getStatusCode()); |
||
| 143 | |||
| 144 | $tasks = json_decode($response->getBody(), true); |
||
| 145 | |||
| 146 | $this->assertEquals(3, count($tasks)); |
||
| 147 | |||
| 148 | $profiles = [ |
||
| 149 | 'profile1', |
||
| 150 | 'profile2', |
||
| 151 | ]; |
||
| 152 | $this->assertTrue(in_array($tasks[1]['profile'], $profiles)); |
||
| 153 | $this->assertTrue(in_array($tasks[2]['profile'], $profiles)); |
||
| 154 | } |
||
| 156 |