| Conditions | 1 |
| Paths | 1 |
| Total Lines | 68 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 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 |
||
| 78 | public function testSerializingCollectionResource() |
||
| 79 | { |
||
| 80 | $manager = new Manager(); |
||
| 81 | $manager->parseIncludes('author'); |
||
| 82 | $manager->setSerializer(new ArraySerializer()); |
||
| 83 | |||
| 84 | $resource = new Collection($this->bookCollectionInput, new GenericBookTransformer(), 'books'); |
||
| 85 | |||
| 86 | // Try without metadata |
||
| 87 | $scope = new Scope($manager, $resource); |
||
| 88 | |||
| 89 | $expected = [ |
||
| 90 | 'books' => [ |
||
| 91 | [ |
||
| 92 | 'title' => 'Foo', |
||
| 93 | 'year' => 1991, |
||
| 94 | 'author' => [ |
||
| 95 | 'name' => 'Dave', |
||
| 96 | ], |
||
| 97 | ], |
||
| 98 | [ |
||
| 99 | 'title' => 'Bar', |
||
| 100 | 'year' => 1997, |
||
| 101 | 'author' => [ |
||
| 102 | 'name' => 'Bob', |
||
| 103 | ], |
||
| 104 | ], |
||
| 105 | ], |
||
| 106 | ]; |
||
| 107 | |||
| 108 | $this->assertSame($expected, $scope->toArray()); |
||
| 109 | |||
| 110 | // JSON array of JSON objects |
||
| 111 | $expectedJson = '{"books":[{"title":"Foo","year":1991,"author":{"name":"Dave"}},{"title":"Bar","year":1997,"author":{"name":"Bob"}}]}'; |
||
| 112 | $this->assertSame($expectedJson, $scope->toJson()); |
||
| 113 | |||
| 114 | // Same again with metadata |
||
| 115 | $resource->setMetaValue('foo', 'bar'); |
||
| 116 | |||
| 117 | $scope = new Scope($manager, $resource); |
||
| 118 | |||
| 119 | $expected = [ |
||
| 120 | 'books' => [ |
||
| 121 | [ |
||
| 122 | 'title' => 'Foo', |
||
| 123 | 'year' => 1991, |
||
| 124 | 'author' => [ |
||
| 125 | 'name' => 'Dave', |
||
| 126 | ], |
||
| 127 | ], |
||
| 128 | [ |
||
| 129 | 'title' => 'Bar', |
||
| 130 | 'year' => 1997, |
||
| 131 | 'author' => [ |
||
| 132 | 'name' => 'Bob', |
||
| 133 | ], |
||
| 134 | ], |
||
| 135 | ], |
||
| 136 | 'meta' => [ |
||
| 137 | 'foo' => 'bar', |
||
| 138 | ], |
||
| 139 | ]; |
||
| 140 | |||
| 141 | $this->assertSame($expected, $scope->toArray()); |
||
| 142 | |||
| 143 | $expectedJson = '{"books":[{"title":"Foo","year":1991,"author":{"name":"Dave"}},{"title":"Bar","year":1997,"author":{"name":"Bob"}}],"meta":{"foo":"bar"}}'; |
||
| 144 | $this->assertSame($expectedJson, $scope->toJson()); |
||
| 145 | } |
||
| 146 | |||
| 209 |