Conditions | 1 |
Paths | 1 |
Total Lines | 57 |
Code Lines | 42 |
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 |
||
16 | public function testGetAction($kernel) |
||
17 | { |
||
18 | self::createAndBootKernel($kernel); |
||
19 | self::configureDb(); |
||
20 | |||
21 | $em = self::getEntityManager(); |
||
22 | $entity = new MyEntity('my-test-secret'); |
||
23 | $em->persist($entity); |
||
24 | $parent = new MyEntity('non-recursing-entity'); |
||
25 | $em->persist($parent); |
||
26 | $entity->setParent($parent); |
||
27 | $em->flush(); |
||
28 | $em->clear(); |
||
29 | |||
30 | $client = self::createClient(); |
||
31 | $client->request( |
||
32 | 'GET', |
||
33 | '/api/entity/my-entity/read', |
||
34 | ['identifier' => $entity->getId()], |
||
35 | [], |
||
36 | ['HTTP_CONTENT_TYPE' => 'application/json'] |
||
37 | ); |
||
38 | $response = $client->getResponse(); |
||
39 | |||
40 | self::assertTrue($response->isSuccessful()); |
||
41 | $data = json_decode($response->getContent()); |
||
42 | |||
43 | self::assertEquals(JSON_ERROR_NONE, json_last_error()); |
||
44 | |||
45 | self::assertInstanceOf(\stdClass::class, $data); |
||
46 | self::assertSame($entity->getId(), $data->id); |
||
47 | self::assertSame('defaults', $data->public_api_field); |
||
48 | self::assertObjectNotHasAttribute('private_field', $data); |
||
49 | self::assertSame($parent->getId(), $data->parent); |
||
50 | self::assertSame([], $data->children); |
||
51 | |||
52 | $client->request( |
||
53 | 'GET', |
||
54 | '/api/entity/my-entity/read', |
||
55 | ['identifier' => $parent->getId()], |
||
56 | [], |
||
57 | ['HTTP_CONTENT_TYPE' => 'application/json'] |
||
58 | ); |
||
59 | $response = $client->getResponse(); |
||
60 | |||
61 | self::assertTrue($response->isSuccessful()); |
||
62 | $data = json_decode($response->getContent()); |
||
63 | |||
64 | self::assertEquals(JSON_ERROR_NONE, json_last_error()); |
||
65 | |||
66 | self::assertInstanceOf(\stdClass::class, $data); |
||
67 | self::assertSame($parent->getId(), $data->id); |
||
68 | self::assertSame('defaults', $data->public_api_field); |
||
69 | self::assertObjectNotHasAttribute('private_field', $data); |
||
70 | self::assertNull($data->parent); |
||
71 | self::assertSame([$entity->getId()], $data->children); |
||
72 | } |
||
73 | } |
||
74 |