Conditions | 2 |
Paths | 2 |
Total Lines | 80 |
Code Lines | 45 |
Lines | 9 |
Ratio | 11.25 % |
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 |
||
24 | public function testAsyncLock() |
||
25 | { |
||
26 | /** |
||
27 | * create test entry |
||
28 | */ |
||
29 | $client = static::createRestClient(); |
||
30 | $statusEntry = new \stdClass(); |
||
31 | $statusEntry->id = 'locktest'; |
||
32 | $statusEntry->status = []; |
||
33 | $defaultStatus = new \stdClass(); |
||
34 | $defaultStatus->workerId = 'hans'; |
||
35 | $defaultStatus->status = 'opened'; |
||
36 | $statusEntry->status[] = $defaultStatus; |
||
37 | |||
38 | $client->put('/event/status/locktest', $statusEntry); |
||
39 | $this->assertSame(Response::HTTP_NO_CONTENT, $client->getResponse()->getStatusCode()); |
||
40 | |||
41 | /** |
||
42 | * the patch we will send |
||
43 | */ |
||
44 | $patchJson = json_encode( |
||
45 | [ |
||
46 | [ |
||
47 | 'op' => 'replace', |
||
48 | 'path' => '/status/0/status', |
||
49 | 'value' => 'ignored' |
||
50 | ], |
||
51 | [ |
||
52 | 'op' => 'add', |
||
53 | 'path' => '/status/0/action', |
||
54 | 'value' => [ |
||
55 | '$ref' => 'http://localhost/event/action/default' |
||
56 | ] |
||
57 | ], |
||
58 | [ |
||
59 | 'op' => 'add', |
||
60 | 'path' => '/information/-', |
||
61 | 'value' => [ |
||
62 | 'workerId' => 'hans', |
||
63 | 'type' => 'info', |
||
64 | 'content' => 'addedInfo' |
||
65 | ] |
||
66 | ] |
||
67 | ] |
||
68 | ); |
||
69 | |||
70 | $promiseStack = []; |
||
71 | $deferred = new \React\Promise\Deferred(); |
||
72 | |||
73 | $i = 0; |
||
74 | while ($i < 30) { |
||
75 | $promise = $deferred->promise(); |
||
76 | |||
77 | $promise->then( |
||
78 | function () use ($patchJson) { |
||
79 | $client = static::createRestClient(); |
||
80 | $client->request('PATCH', '/event/status/locktest', [], [], [], $patchJson); |
||
81 | $this->assertSame(Response::HTTP_OK, $client->getResponse()->getStatusCode()); |
||
82 | } |
||
83 | ); |
||
84 | |||
85 | $promiseStack[] = $promise; |
||
86 | $i++; |
||
87 | } |
||
88 | |||
89 | \React\Promise\all($promiseStack)->then( |
||
90 | View Code Duplication | function () { |
|
91 | // after all is done; check entry |
||
92 | $client = static::createRestClient(); |
||
93 | $client->request('GET', '/event/status/locktest'); |
||
94 | $result = $client->getResults(); |
||
95 | |||
96 | $this->assertSame(30, count($result->information)); |
||
97 | $this->assertSame(1, count($result->status)); |
||
98 | } |
||
99 | ); |
||
100 | |||
101 | // start the whole thing |
||
102 | $deferred->resolve(); |
||
103 | } |
||
104 | } |
||
105 |