| Conditions | 1 |
| Paths | 1 |
| Total Lines | 53 |
| Code Lines | 20 |
| 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 |
||
| 53 | public function testJsonSerialize() |
||
| 54 | { |
||
| 55 | $entities = [ |
||
| 56 | new Entity([ |
||
| 57 | 'id' => 1, |
||
| 58 | 'modified' => new Time('2017-01-01 10:00:00'), |
||
| 59 | ]), |
||
| 60 | new Entity([ |
||
| 61 | 'id' => 3, |
||
| 62 | 'modified' => new Time('2017-01-01 10:00:00'), |
||
| 63 | ]), |
||
| 64 | new Entity([ |
||
| 65 | 'id' => 5, |
||
| 66 | 'modified' => new Time('2017-01-01 10:00:00'), |
||
| 67 | ]), |
||
| 68 | ]; |
||
| 69 | |||
| 70 | $meta = [ |
||
| 71 | 'hasPrevious' => null, |
||
| 72 | 'previousCursor' => null, |
||
| 73 | 'hasNext' => true, |
||
| 74 | 'nextCursor' => [ |
||
| 75 | 'Posts.id' => 2, |
||
| 76 | 'Posts.modified' => new Time('2017-01-01 11:00:00'), |
||
| 77 | ], |
||
| 78 | ]; |
||
| 79 | |||
| 80 | $actual = json_encode(new PaginationResult($entities, $meta)); |
||
| 81 | $expected = '{ |
||
| 82 | "records": [ |
||
| 83 | { |
||
| 84 | "id": 1, |
||
| 85 | "modified": "2017-01-01T10:00:00+00:00" |
||
| 86 | }, |
||
| 87 | { |
||
| 88 | "id": 3, |
||
| 89 | "modified": "2017-01-01T10:00:00+00:00" |
||
| 90 | }, |
||
| 91 | { |
||
| 92 | "id": 5, |
||
| 93 | "modified": "2017-01-01T10:00:00+00:00" |
||
| 94 | } |
||
| 95 | ], |
||
| 96 | "hasPrevious": null, |
||
| 97 | "previousCursor": null, |
||
| 98 | "hasNext": true, |
||
| 99 | "nextCursor": { |
||
| 100 | "Posts.id": 2, |
||
| 101 | "Posts.modified": "2017-01-01T11:00:00+00:00" |
||
| 102 | } |
||
| 103 | }'; |
||
| 104 | |||
| 105 | $this->assertJsonStringEqualsJsonString($expected, $actual); |
||
| 106 | } |
||
| 140 |