Conditions | 1 |
Paths | 1 |
Total Lines | 63 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
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 testRender() |
||
48 | { |
||
49 | $handler = $this->handler(); |
||
50 | $exception = new Exception("Exception message"); |
||
51 | $res = $handler->render($this->request(), $exception); |
||
52 | self::assertInstanceOf(JsonResponse::class, $res); |
||
53 | /** @var JsonResponse $res */ |
||
54 | self::assertEquals(['status' => 500, 'message' => 'Exception message', 'name' => 'InternalException'], |
||
55 | $res->getData(true)); |
||
56 | |||
57 | $exception = new Exception("Exception message", 402); |
||
58 | $res = $handler->render($this->request(), $exception); |
||
59 | self::assertInstanceOf(JsonResponse::class, $res); |
||
60 | /** @var JsonResponse $res */ |
||
61 | self::assertEquals(['status' => 402, 'message' => 'Exception message', 'name' => 'InternalException'], |
||
62 | $res->getData(true)); |
||
63 | |||
64 | $exception = new AuthenticationException("Authentication Exception message"); |
||
65 | $res = $handler->render($this->request(), $exception); |
||
66 | self::assertInstanceOf(JsonResponse::class, $res); |
||
67 | /** @var JsonResponse $res */ |
||
68 | self::assertEquals(['status' => 401, 'message' => 'Authentication Exception message', |
||
69 | 'name' => 'AuthenticationException'], $res->getData(true)); |
||
70 | |||
71 | $exception = new DuplicateException('value', 'name', 'array'); |
||
72 | $res = $handler->render($this->request(), $exception); |
||
73 | self::assertInstanceOf(JsonResponse::class, $res); |
||
74 | /** @var JsonResponse $res */ |
||
75 | self::assertEquals(['status' => 409, 'message' => 'Duplicate Exception', |
||
76 | 'name' => 'DuplicateException', 'duplicateValue' => 'value', 'arrayName' => 'array'], $res->getData(true)); |
||
77 | |||
78 | $exception = new ReferenceException('value', 'name'); |
||
79 | $res = $handler->render($this->request(), $exception); |
||
80 | self::assertInstanceOf(JsonResponse::class, $res); |
||
81 | /** @var JsonResponse $res */ |
||
82 | self::assertEquals(['status' => 409, 'message' => 'Reference Exception', |
||
83 | 'name' => 'ReferenceException', 'referenceValue' => 'value', 'referenceName' => 'name'], $res->getData(true)); |
||
84 | |||
85 | $exception = new UnorderedPhaseNumberException(2, 1); |
||
86 | $res = $handler->render($this->request(), $exception); |
||
87 | self::assertInstanceOf(JsonResponse::class, $res); |
||
88 | /** @var JsonResponse $res */ |
||
89 | self::assertEquals(['status' => 409, 'message' => 'Unordered Phase Number Exception', |
||
90 | 'name' => 'UnorderedPhaseNumberException', 'previousPhaseNumber' => 2, 'nextPhaseNumber' => 1], |
||
91 | $res->getData(true)); |
||
92 | |||
93 | $exception = new PlayerAlreadyExists([]); |
||
94 | $res = $handler->render($this->request(), $exception); |
||
95 | self::assertInstanceOf(JsonResponse::class, $res); |
||
96 | /** @var JsonResponse $res */ |
||
97 | self::assertEquals(['status' => 409, 'message' => 'Some players do already exist', |
||
98 | 'name' => 'PlayerAlreadyExistsException', 'players' => []], $res->getData(true)); |
||
99 | |||
100 | // test trace in debug mode |
||
101 | $exception = new PlayerAlreadyExists([]); |
||
102 | $res = $handler->render($this->request(), $exception, true); |
||
103 | self::assertInstanceOf(JsonResponse::class, $res); |
||
104 | /** @var JsonResponse $res */ |
||
105 | $data = $res->getData(true); |
||
106 | self::assertArrayIsSubset(['status' => 409, 'message' => 'Some players do already exist', |
||
107 | 'name' => 'PlayerAlreadyExistsException', 'players' => []], $data); |
||
108 | self::assertArrayHasKey('trace', $data); |
||
109 | self::assertNotEmpty($data['trace']); |
||
110 | } |
||
154 | } |