| Conditions | 1 |
| Paths | 1 |
| Total Lines | 95 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 2 | 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 |
||
| 71 | public function testSerializingCollectionResource() |
||
| 72 | { |
||
| 73 | $manager = new Manager(); |
||
| 74 | $manager->parseIncludes('author'); |
||
| 75 | $manager->setSerializer(new DataArraySerializer()); |
||
| 76 | |||
| 77 | $booksData = [ |
||
| 78 | [ |
||
| 79 | 'title' => 'Foo', |
||
| 80 | 'year' => '1991', |
||
| 81 | '_author' => [ |
||
| 82 | 'name' => 'Dave', |
||
| 83 | ], |
||
| 84 | ], |
||
| 85 | [ |
||
| 86 | 'title' => 'Bar', |
||
| 87 | 'year' => '1997', |
||
| 88 | '_author' => [ |
||
| 89 | 'name' => 'Bob', |
||
| 90 | ], |
||
| 91 | ], |
||
| 92 | ]; |
||
| 93 | |||
| 94 | // Try without metadata |
||
| 95 | $resource = new Collection($booksData, new GenericBookTransformer(), 'book'); |
||
| 96 | |||
| 97 | $scope = new Scope($manager, $resource); |
||
| 98 | |||
| 99 | $expected = [ |
||
| 100 | 'data' => [ |
||
| 101 | [ |
||
| 102 | 'title' => 'Foo', |
||
| 103 | 'year' => 1991, |
||
| 104 | 'author' => [ |
||
| 105 | 'data' => [ |
||
| 106 | 'name' => 'Dave', |
||
| 107 | ], |
||
| 108 | ], |
||
| 109 | ], |
||
| 110 | [ |
||
| 111 | 'title' => 'Bar', |
||
| 112 | 'year' => 1997, |
||
| 113 | 'author' => [ |
||
| 114 | 'data' => [ |
||
| 115 | 'name' => 'Bob', |
||
| 116 | ], |
||
| 117 | ], |
||
| 118 | ], |
||
| 119 | ], |
||
| 120 | ]; |
||
| 121 | |||
| 122 | $this->assertSame($expected, $scope->toArray()); |
||
| 123 | |||
| 124 | $expectedJson = '{"data":[{"title":"Foo","year":1991,"author":{"data":{"name":"Dave"}}},{"title":"Bar","year":1997,"author":{"data":{"name":"Bob"}}}]}'; |
||
| 125 | $this->assertSame($expectedJson, $scope->toJson()); |
||
| 126 | |||
| 127 | // Same again with meta |
||
| 128 | $resource = new Collection($booksData, new GenericBookTransformer(), 'book'); |
||
| 129 | $resource->setMetaValue('foo', 'bar'); |
||
| 130 | |||
| 131 | $scope = new Scope($manager, $resource); |
||
| 132 | |||
| 133 | |||
| 134 | $expected = [ |
||
| 135 | 'data' => [ |
||
| 136 | [ |
||
| 137 | 'title' => 'Foo', |
||
| 138 | 'year' => 1991, |
||
| 139 | 'author' => [ |
||
| 140 | 'data' => [ |
||
| 141 | 'name' => 'Dave', |
||
| 142 | ], |
||
| 143 | ], |
||
| 144 | ], |
||
| 145 | [ |
||
| 146 | 'title' => 'Bar', |
||
| 147 | 'year' => 1997, |
||
| 148 | 'author' => [ |
||
| 149 | 'data' => [ |
||
| 150 | 'name' => 'Bob', |
||
| 151 | |||
| 152 | ], |
||
| 153 | ], |
||
| 154 | ], |
||
| 155 | ], |
||
| 156 | 'meta' => [ |
||
| 157 | 'foo' => 'bar', |
||
| 158 | ], |
||
| 159 | ]; |
||
| 160 | |||
| 161 | $this->assertSame($expected, $scope->toArray()); |
||
| 162 | |||
| 163 | $expectedJson = '{"data":[{"title":"Foo","year":1991,"author":{"data":{"name":"Dave"}}},{"title":"Bar","year":1997,"author":{"data":{"name":"Bob"}}}],"meta":{"foo":"bar"}}'; |
||
| 164 | $this->assertSame($expectedJson, $scope->toJson()); |
||
| 165 | } |
||
| 166 | |||
| 210 |