| Conditions | 1 |
| Paths | 1 |
| Total Lines | 80 |
| Code Lines | 63 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 142 | public function testGetPages(): void |
||
| 143 | { |
||
| 144 | $document = $this->getDocumentInstance(); |
||
| 145 | |||
| 146 | // Listing pages from type Page |
||
| 147 | $content = '<</Type/Page>>'; |
||
| 148 | $header = Header::parse($content, $document); |
||
| 149 | $object1 = $this->getPageInstance($document, $header); |
||
| 150 | $header = Header::parse($content, $document); |
||
| 151 | $object2 = $this->getPageInstance($document, $header); |
||
| 152 | $document->setObjects([1 => $object1, 2 => $object2]); |
||
| 153 | $pages = $document->getPages(); |
||
| 154 | |||
| 155 | $this->assertEquals(2, \count($pages)); |
||
| 156 | $this->assertTrue($pages[0] instanceof Page); |
||
| 157 | $this->assertTrue($pages[1] instanceof Page); |
||
| 158 | |||
| 159 | // Listing pages from type Pages (kids) |
||
| 160 | $content = '<</Type/Page>>'; |
||
| 161 | $header = Header::parse($content, $document); |
||
| 162 | $object1 = $this->getPageInstance($document, $header); |
||
| 163 | $header = Header::parse($content, $document); |
||
| 164 | $object2 = $this->getPageInstance($document, $header); |
||
| 165 | $header = Header::parse($content, $document); |
||
| 166 | $object3 = $this->getPageInstance($document, $header); |
||
| 167 | |||
| 168 | $content = '<</Type/Pages/Kids[1 0 R 2 0 R]>>'; |
||
| 169 | $header = Header::parse($content, $document); |
||
| 170 | $object4 = $this->getPagesInstance($document, $header); |
||
| 171 | |||
| 172 | $content = '<</Type/Pages/Kids[3 0 R]>>'; |
||
| 173 | $header = Header::parse($content, $document); |
||
| 174 | $object5 = $this->getPagesInstance($document, $header); |
||
| 175 | |||
| 176 | $document->setObjects([ |
||
| 177 | '1_0' => $object1, |
||
| 178 | '2_0' => $object2, |
||
| 179 | '3_0' => $object3, |
||
| 180 | '4_0' => $object4, |
||
| 181 | '5_0' => $object5, |
||
| 182 | ]); |
||
| 183 | $pages = $document->getPages(); |
||
| 184 | |||
| 185 | $this->assertEquals(3, \count($pages)); |
||
| 186 | $this->assertTrue($pages[0] instanceof Page); |
||
| 187 | $this->assertTrue($pages[1] instanceof Page); |
||
| 188 | $this->assertTrue($pages[2] instanceof Page); |
||
| 189 | |||
| 190 | // Listing pages from type Catalog |
||
| 191 | $content = '<</Type/Page>>'; |
||
| 192 | $header = Header::parse($content, $document); |
||
| 193 | $object1 = $this->getPageInstance($document, $header); |
||
| 194 | $header = Header::parse($content, $document); |
||
| 195 | $object2 = $this->getPageInstance($document, $header); |
||
| 196 | $header = Header::parse($content, $document); |
||
| 197 | $object3 = $this->getPageInstance($document, $header); |
||
| 198 | $content = '<</Type/Pages/Kids[1 0 R 2 0 R]>>'; |
||
| 199 | $header = Header::parse($content, $document); |
||
| 200 | $object4 = $this->getPagesInstance($document, $header); |
||
| 201 | $content = '<</Type/Pages/Kids[4 0 R 3 0 R]>>'; |
||
| 202 | $header = Header::parse($content, $document); |
||
| 203 | $object5 = $this->getPagesInstance($document, $header); |
||
| 204 | $content = '<</Type/Catalog/Pages 5 0 R >>'; |
||
| 205 | $header = Header::parse($content, $document); |
||
| 206 | $object6 = $this->getPagesInstance($document, $header); |
||
| 207 | $document->setObjects( |
||
| 208 | [ |
||
| 209 | '1_0' => $object1, |
||
| 210 | '2_0' => $object2, |
||
| 211 | '3_0' => $object3, |
||
| 212 | '4_0' => $object4, |
||
| 213 | '5_0' => $object5, |
||
| 214 | '6_0' => $object6, |
||
| 215 | ] |
||
| 216 | ); |
||
| 217 | $pages = $document->getPages(); |
||
| 218 | $this->assertEquals(3, \count($pages)); |
||
| 219 | $this->assertTrue($pages[0] instanceof Page); |
||
| 220 | $this->assertTrue($pages[1] instanceof Page); |
||
| 221 | $this->assertTrue($pages[2] instanceof Page); |
||
| 222 | } |
||
| 259 |