| Conditions | 1 |
| Paths | 1 |
| Total Lines | 69 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | 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 |
||
| 83 | public function testEmbeddedRelationIsMergedWithCustomRelations() |
||
| 84 | { |
||
| 85 | $collection = new CollectionRepresentation( |
||
| 86 | array( |
||
| 87 | 'Adrien', |
||
| 88 | 'William', |
||
| 89 | ), |
||
| 90 | 'authors', |
||
| 91 | null, |
||
| 92 | null, |
||
| 93 | null, |
||
| 94 | array( |
||
| 95 | new Relation( |
||
| 96 | 'custom', |
||
| 97 | new Route('/custom') |
||
| 98 | ), |
||
| 99 | ) |
||
| 100 | ); |
||
| 101 | $collection->setXmlElementName('users'); |
||
| 102 | |||
| 103 | $this->assertSame( |
||
| 104 | <<<XML |
||
| 105 | <?xml version="1.0" encoding="UTF-8"?> |
||
| 106 | <collection> |
||
| 107 | <link rel="custom" href="/custom"/> |
||
| 108 | <users rel="authors"> |
||
| 109 | <entry><![CDATA[Adrien]]></entry> |
||
| 110 | <entry><![CDATA[William]]></entry> |
||
| 111 | </users> |
||
| 112 | </collection> |
||
| 113 | |||
| 114 | XML |
||
| 115 | , |
||
| 116 | $this->hateoas->serialize($collection, 'xml') |
||
| 117 | ); |
||
| 118 | $this->assertSame( |
||
| 119 | <<<XML |
||
| 120 | <?xml version="1.0" encoding="UTF-8"?> |
||
| 121 | <collection> |
||
| 122 | <link rel="custom" href="/custom"/> |
||
| 123 | <resource rel="authors"><![CDATA[Adrien]]></resource> |
||
| 124 | <resource rel="authors"><![CDATA[William]]></resource> |
||
| 125 | </collection> |
||
| 126 | |||
| 127 | XML |
||
| 128 | , |
||
| 129 | $this->halHateoas->serialize($collection, 'xml') |
||
| 130 | ); |
||
| 131 | |||
| 132 | $this->assertSame( |
||
| 133 | <<<JSON |
||
| 134 | { |
||
| 135 | "_links": { |
||
| 136 | "custom": { |
||
| 137 | "href": "\/custom" |
||
| 138 | } |
||
| 139 | }, |
||
| 140 | "_embedded": { |
||
| 141 | "authors": [ |
||
| 142 | "Adrien", |
||
| 143 | "William" |
||
| 144 | ] |
||
| 145 | } |
||
| 146 | } |
||
| 147 | JSON |
||
| 148 | , |
||
| 149 | $this->json($this->halHateoas->serialize($collection, 'json')) |
||
| 150 | ); |
||
| 151 | } |
||
| 152 | } |
||
| 153 |