Conditions | 2 |
Paths | 3 |
Total Lines | 87 |
Code Lines | 68 |
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 |
||
150 | public function testGetPages() |
||
151 | { |
||
152 | $document = $this->getDocumentInstance(); |
||
153 | |||
154 | // Listing pages from type Page |
||
155 | $content = '<</Type/Page>>'; |
||
156 | $header = Header::parse($content, $document); |
||
157 | $object1 = $this->getPageInstance($document, $header); |
||
158 | $header = Header::parse($content, $document); |
||
159 | $object2 = $this->getPageInstance($document, $header); |
||
160 | $document->setObjects([1 => $object1, 2 => $object2]); |
||
161 | $pages = $document->getPages(); |
||
162 | |||
163 | $this->assertEquals(2, \count($pages)); |
||
164 | $this->assertTrue($pages[0] instanceof Page); |
||
165 | $this->assertTrue($pages[1] instanceof Page); |
||
166 | |||
167 | // Listing pages from type Pages (kids) |
||
168 | $content = '<</Type/Page>>'; |
||
169 | $header = Header::parse($content, $document); |
||
170 | $object1 = $this->getPageInstance($document, $header); |
||
171 | $header = Header::parse($content, $document); |
||
172 | $object2 = $this->getPageInstance($document, $header); |
||
173 | $header = Header::parse($content, $document); |
||
174 | $object3 = $this->getPageInstance($document, $header); |
||
175 | |||
176 | $content = '<</Type/Pages/Kids[1 0 R 2 0 R]>>'; |
||
177 | $header = Header::parse($content, $document); |
||
178 | $object4 = $this->getPagesInstance($document, $header); |
||
179 | |||
180 | $content = '<</Type/Pages/Kids[3 0 R]>>'; |
||
181 | $header = Header::parse($content, $document); |
||
182 | $object5 = $this->getPagesInstance($document, $header); |
||
183 | |||
184 | $document->setObjects([ |
||
185 | '1_0' => $object1, |
||
186 | '2_0' => $object2, |
||
187 | '3_0' => $object3, |
||
188 | '4_0' => $object4, |
||
189 | '5_0' => $object5, |
||
190 | ]); |
||
191 | $pages = $document->getPages(); |
||
192 | |||
193 | $this->assertEquals(3, \count($pages)); |
||
194 | $this->assertTrue($pages[0] instanceof Page); |
||
195 | $this->assertTrue($pages[1] instanceof Page); |
||
196 | $this->assertTrue($pages[2] instanceof Page); |
||
197 | |||
198 | // Listing pages from type Catalog |
||
199 | $content = '<</Type/Page>>'; |
||
200 | $header = Header::parse($content, $document); |
||
201 | $object1 = $this->getPageInstance($document, $header); |
||
202 | $header = Header::parse($content, $document); |
||
203 | $object2 = $this->getPageInstance($document, $header); |
||
204 | $header = Header::parse($content, $document); |
||
205 | $object3 = $this->getPageInstance($document, $header); |
||
206 | $content = '<</Type/Pages/Kids[1 0 R 2 0 R]>>'; |
||
207 | $header = Header::parse($content, $document); |
||
208 | $object4 = $this->getPagesInstance($document, $header); |
||
209 | $content = '<</Type/Pages/Kids[4 0 R 3 0 R]>>'; |
||
210 | $header = Header::parse($content, $document); |
||
211 | $object5 = $this->getPagesInstance($document, $header); |
||
212 | $content = '<</Type/Catalog/Pages 5 0 R >>'; |
||
213 | $header = Header::parse($content, $document); |
||
214 | $object6 = $this->getPagesInstance($document, $header); |
||
215 | $document->setObjects( |
||
216 | [ |
||
217 | '1_0' => $object1, |
||
218 | '2_0' => $object2, |
||
219 | '3_0' => $object3, |
||
220 | '4_0' => $object4, |
||
221 | '5_0' => $object5, |
||
222 | '6_0' => $object6, |
||
223 | ] |
||
224 | ); |
||
225 | $pages = $document->getPages(); |
||
226 | $this->assertEquals(3, \count($pages)); |
||
227 | $this->assertTrue($pages[0] instanceof Page); |
||
228 | $this->assertTrue($pages[1] instanceof Page); |
||
229 | $this->assertTrue($pages[2] instanceof Page); |
||
230 | } |
||
231 | |||
232 | public function testGetPagesMissingCatalog() |
||
233 | { |
||
234 | $this->expectException(Exception::class); |
||
235 | $this->expectExceptionMessage('Missing catalog.'); |
||
236 | |||
237 | // Missing catalog |
||
242 |