Conditions | 1 |
Paths | 1 |
Total Lines | 60 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
71 | public function testSerialize() |
||
72 | { |
||
73 | $factory = new PagerfantaFactory(); |
||
74 | $pagerfanta = new Pagerfanta(new ArrayAdapter(array( |
||
75 | 'bim', |
||
76 | 'bam', |
||
77 | 'boom' |
||
78 | ))); |
||
79 | |||
80 | $collection = $factory->createRepresentation($pagerfanta, new Route('my_route')); |
||
81 | |||
82 | $this->assertSame( |
||
83 | <<<XML |
||
84 | <?xml version="1.0" encoding="UTF-8"?> |
||
85 | <collection page="1" limit="10" pages="1" total="3"> |
||
86 | <entry rel="items"> |
||
87 | <entry><![CDATA[bim]]></entry> |
||
88 | <entry><![CDATA[bam]]></entry> |
||
89 | <entry><![CDATA[boom]]></entry> |
||
90 | </entry> |
||
91 | <link rel="self" href="my_route?page=1&limit=10"/> |
||
92 | <link rel="first" href="my_route?page=1&limit=10"/> |
||
93 | <link rel="last" href="my_route?page=1&limit=10"/> |
||
94 | </collection> |
||
95 | |||
96 | XML |
||
97 | , |
||
98 | $this->hateoas->serialize($collection, 'xml') |
||
99 | ); |
||
100 | $this->assertSame( |
||
101 | <<<JSON |
||
102 | { |
||
103 | "page": 1, |
||
104 | "limit": 10, |
||
105 | "pages": 1, |
||
106 | "total": 3, |
||
107 | "_links": { |
||
108 | "self": { |
||
109 | "href": "my_route?page=1&limit=10" |
||
110 | }, |
||
111 | "first": { |
||
112 | "href": "my_route?page=1&limit=10" |
||
113 | }, |
||
114 | "last": { |
||
115 | "href": "my_route?page=1&limit=10" |
||
116 | } |
||
117 | }, |
||
118 | "_embedded": { |
||
119 | "items": [ |
||
120 | "bim", |
||
121 | "bam", |
||
122 | "boom" |
||
123 | ] |
||
124 | } |
||
125 | } |
||
126 | JSON |
||
127 | , |
||
128 | $this->json($this->hateoas->serialize($collection, 'json')) |
||
129 | ); |
||
130 | } |
||
131 | |||
170 |