| Conditions | 1 |
| Paths | 1 |
| Total Lines | 57 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 13 | public function testSerializingItemResource() |
||
| 14 | { |
||
| 15 | $manager = new Manager(); |
||
| 16 | $manager->parseIncludes('author'); |
||
| 17 | $manager->setSerializer(new DataArraySerializer()); |
||
| 18 | |||
| 19 | $bookData = [ |
||
| 20 | 'title' => 'Foo', |
||
| 21 | 'year' => '1991', |
||
| 22 | '_author' => [ |
||
| 23 | 'name' => 'Dave', |
||
| 24 | ], |
||
| 25 | ]; |
||
| 26 | |||
| 27 | // Try without metadata |
||
| 28 | $resource = new Item($bookData, new GenericBookTransformer(), 'book'); |
||
| 29 | $scope = new Scope($manager, $resource); |
||
| 30 | |||
| 31 | $expected = [ |
||
| 32 | 'data' => [ |
||
| 33 | 'title' => 'Foo', |
||
| 34 | 'year' => 1991, |
||
| 35 | 'author' => [ |
||
| 36 | 'data' => [ |
||
| 37 | 'name' => 'Dave', |
||
| 38 | ], |
||
| 39 | ], |
||
| 40 | ], |
||
| 41 | ]; |
||
| 42 | |||
| 43 | $this->assertSame($expected, $scope->toArray()); |
||
| 44 | |||
| 45 | // Same again with metadata |
||
| 46 | $resource = new Item($bookData, new GenericBookTransformer(), 'book'); |
||
| 47 | $resource->setMetaValue('foo', 'bar'); |
||
| 48 | |||
| 49 | $scope = new Scope($manager, $resource); |
||
| 50 | |||
| 51 | |||
| 52 | $expected = [ |
||
| 53 | 'data' => [ |
||
| 54 | 'title' => 'Foo', |
||
| 55 | 'year' => 1991, |
||
| 56 | 'author' => [ |
||
| 57 | 'data' => [ |
||
| 58 | 'name' => 'Dave', |
||
| 59 | |||
| 60 | ], |
||
| 61 | ], |
||
| 62 | ], |
||
| 63 | 'meta' => [ |
||
| 64 | 'foo' => 'bar', |
||
| 65 | ], |
||
| 66 | ]; |
||
| 67 | |||
| 68 | $this->assertSame($expected, $scope->toArray()); |
||
| 69 | } |
||
| 70 | |||
| 210 |