Conditions | 1 |
Paths | 1 |
Total Lines | 65 |
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 |
||
46 | public function testRender() |
||
47 | { |
||
48 | $handler = $this->handler(); |
||
49 | $exception = new \Exception("Exception message"); |
||
50 | $res = $handler->render($this->request(), $exception); |
||
51 | self::assertInstanceOf(JsonResponse::class, $res); |
||
52 | /** @var JsonResponse $res */ |
||
53 | self::assertEquals(['status' => 500, 'message' => 'Exception message', 'name' => 'InternalException'], |
||
54 | $res->getData(true)); |
||
55 | |||
56 | $exception = new \Exception("Exception message", 402); |
||
57 | $res = $handler->render($this->request(), $exception); |
||
58 | self::assertInstanceOf(JsonResponse::class, $res); |
||
59 | /** @var JsonResponse $res */ |
||
60 | self::assertEquals(['status' => 402, 'message' => 'Exception message', 'name' => 'InternalException'], |
||
61 | $res->getData(true)); |
||
62 | |||
63 | $exception = new AuthenticationException("Authentication Exception message"); |
||
64 | $res = $handler->render($this->request(), $exception); |
||
65 | self::assertInstanceOf(JsonResponse::class, $res); |
||
66 | /** @var JsonResponse $res */ |
||
67 | self::assertEquals(['status' => 401, 'message' => 'Authentication Exception message', |
||
68 | 'name' => 'AuthenticationException'], $res->getData(true)); |
||
69 | |||
70 | $exception = new DuplicateException('value', 'name', 'array'); |
||
71 | $res = $handler->render($this->request(), $exception); |
||
72 | self::assertInstanceOf(JsonResponse::class, $res); |
||
73 | /** @var JsonResponse $res */ |
||
74 | self::assertEquals(['status' => 409, 'message' => 'Duplicate Exception', |
||
75 | 'name' => 'DuplicateException', 'duplicateValue' => 'value', 'arrayName' => 'array'], $res->getData(true)); |
||
76 | |||
77 | $exception = new ReferenceException('value', 'name'); |
||
78 | $res = $handler->render($this->request(), $exception); |
||
79 | self::assertInstanceOf(JsonResponse::class, $res); |
||
80 | /** @var JsonResponse $res */ |
||
81 | self::assertEquals(['status' => 409, 'message' => 'Reference Exception', |
||
82 | 'name' => 'ReferenceException', 'referenceValue' => 'value', 'referenceName' => 'name'], $res->getData(true)); |
||
83 | |||
84 | $exception = new UnorderedPhaseNumberException(2, 1); |
||
85 | $res = $handler->render($this->request(), $exception); |
||
86 | self::assertInstanceOf(JsonResponse::class, $res); |
||
87 | /** @var JsonResponse $res */ |
||
88 | self::assertEquals(['status' => 409, 'message' => 'Unordered Phase Number Exception', |
||
89 | 'name' => 'UnorderedPhaseNumberException', 'previousPhaseNumber' => 2, 'nextPhaseNumber' => 1], |
||
90 | $res->getData(true)); |
||
91 | |||
92 | $exception = new PlayerAlreadyExists([]); |
||
93 | $res = $handler->render($this->request(), $exception); |
||
94 | self::assertInstanceOf(JsonResponse::class, $res); |
||
95 | /** @var JsonResponse $res */ |
||
96 | self::assertEquals(['status' => 409, 'message' => 'Some players do already exist', |
||
97 | 'name' => 'PlayerAlreadyExistsException', 'players' => []], $res->getData(true)); |
||
98 | |||
99 | // test trace in debug mode |
||
100 | |||
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::assertArraySubset(['status' => 409, 'message' => 'Some players do already exist', |
||
|
|||
107 | 'name' => 'PlayerAlreadyExistsException', 'players' => []], $data); |
||
108 | self::assertArrayHasKey('trace', $data); |
||
109 | self::assertNotEmpty($data['trace']); |
||
110 | } |
||
111 | |||
154 | } |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.