| Conditions | 8 |
| Paths | 8 |
| Total Lines | 220 |
| Code Lines | 154 |
| 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 |
||
| 132 | public function testTransactionDetails() |
||
| 133 | { |
||
| 134 | $messages = [ |
||
| 135 | $this->getV2Message(), |
||
| 136 | $this->getV4Message(), |
||
| 137 | ]; |
||
| 138 | |||
| 139 | foreach ($messages as $message) { |
||
| 140 | $notifications = $message->getRecords(); |
||
| 141 | |||
| 142 | $this->assertCount(1, $notifications); |
||
| 143 | foreach ($notifications as $notification) { |
||
| 144 | $entries = $notification->getEntries(); |
||
| 145 | |||
| 146 | $this->assertCount(1, $entries); |
||
| 147 | foreach ($entries as $entry) { |
||
| 148 | $transactionDetails = $entry->getTransactionDetails(); |
||
| 149 | |||
| 150 | $this->assertCount(3, $transactionDetails); |
||
| 151 | foreach ($transactionDetails as $index=>$transactionDetail) { |
||
| 152 | switch ($index) { |
||
| 153 | case 0: |
||
| 154 | // Legacy : The first message comes from unstructured block |
||
| 155 | $this->assertEquals( |
||
| 156 | 'Unstructured Remittance Information V1', |
||
| 157 | $transactionDetail |
||
| 158 | ->getRemittanceInformation() |
||
| 159 | ->getMessage() |
||
| 160 | ); |
||
| 161 | |||
| 162 | // Only one structured data block |
||
| 163 | $this->assertEquals( |
||
| 164 | 'Unstructured Remittance Information V1', |
||
| 165 | $transactionDetail |
||
| 166 | ->getRemittanceInformation() |
||
| 167 | ->getUnstructuredBlock() |
||
| 168 | ->getMessage() |
||
| 169 | ); |
||
| 170 | |||
| 171 | // Check structured and unstructured blocks |
||
| 172 | $this->assertEquals( |
||
| 173 | 'ISR ref number V1', |
||
| 174 | $transactionDetail |
||
| 175 | ->getRemittanceInformation() |
||
| 176 | ->getStructuredBlock() |
||
| 177 | ->getCreditorReferenceInformation() |
||
| 178 | ->getRef() |
||
| 179 | ); |
||
| 180 | |||
| 181 | $this->assertEquals( |
||
| 182 | 'ISR Reference', |
||
| 183 | $transactionDetail |
||
| 184 | ->getRemittanceInformation() |
||
| 185 | ->getStructuredBlock() |
||
| 186 | ->getCreditorReferenceInformation() |
||
| 187 | ->getProprietary() |
||
| 188 | ); |
||
| 189 | |||
| 190 | $this->assertEquals( |
||
| 191 | null, |
||
| 192 | $transactionDetail |
||
| 193 | ->getRemittanceInformation() |
||
| 194 | ->getStructuredBlock() |
||
| 195 | ->getCreditorReferenceInformation() |
||
| 196 | ->getCode() |
||
| 197 | ); |
||
| 198 | |||
| 199 | $this->assertEquals( |
||
| 200 | 'Additional Remittance Information V1', |
||
| 201 | $transactionDetail |
||
| 202 | ->getRemittanceInformation() |
||
| 203 | ->getStructuredBlock() |
||
| 204 | ->getAdditionalRemittanceInformation() |
||
| 205 | ); |
||
| 206 | break; |
||
| 207 | case 1: |
||
| 208 | |||
| 209 | // Legacy : ref number from the structured information |
||
| 210 | // because the unstructured block is not present |
||
| 211 | $this->assertEquals( |
||
| 212 | 'ISR ref number V2', |
||
| 213 | $transactionDetail |
||
| 214 | ->getRemittanceInformation() |
||
| 215 | ->getMessage() |
||
| 216 | ); |
||
| 217 | |||
| 218 | // No unstructured block |
||
| 219 | $this->assertEquals( |
||
| 220 | 0, |
||
| 221 | count( |
||
| 222 | $transactionDetail |
||
| 223 | ->getRemittanceInformation() |
||
| 224 | ->getUnstructuredBlocks() |
||
| 225 | ) |
||
| 226 | ); |
||
| 227 | |||
| 228 | // Check structured and unstructured blocks |
||
| 229 | $this->assertEquals( |
||
| 230 | 'ISR ref number V2', |
||
| 231 | $transactionDetail |
||
| 232 | ->getRemittanceInformation() |
||
| 233 | ->getStructuredBlock() |
||
| 234 | ->getCreditorReferenceInformation() |
||
| 235 | ->getRef() |
||
| 236 | ); |
||
| 237 | |||
| 238 | $this->assertEquals( |
||
| 239 | 'ISR Reference', |
||
| 240 | $transactionDetail |
||
| 241 | ->getRemittanceInformation() |
||
| 242 | ->getStructuredBlock() |
||
| 243 | ->getCreditorReferenceInformation() |
||
| 244 | ->getProprietary() |
||
| 245 | ); |
||
| 246 | |||
| 247 | $this->assertEquals( |
||
| 248 | null, |
||
| 249 | $transactionDetail |
||
| 250 | ->getRemittanceInformation() |
||
| 251 | ->getStructuredBlock() |
||
| 252 | ->getCreditorReferenceInformation() |
||
| 253 | ->getCode() |
||
| 254 | ); |
||
| 255 | |||
| 256 | $this->assertEquals( |
||
| 257 | 'Additional Remittance Information V2', |
||
| 258 | $transactionDetail |
||
| 259 | ->getRemittanceInformation() |
||
| 260 | ->getStructuredBlock() |
||
| 261 | ->getAdditionalRemittanceInformation() |
||
| 262 | ); |
||
| 263 | |||
| 264 | break; |
||
| 265 | case 2: |
||
| 266 | // Legacy : ref number from the first unstructured block |
||
| 267 | $this->assertEquals( |
||
| 268 | 'Unstructured Remittance Information V3 block 1', |
||
| 269 | $transactionDetail |
||
| 270 | ->getRemittanceInformation() |
||
| 271 | ->getMessage() |
||
| 272 | ); |
||
| 273 | |||
| 274 | // First unstructured block |
||
| 275 | $this->assertEquals( |
||
| 276 | 'Unstructured Remittance Information V3 block 1', |
||
| 277 | $transactionDetail |
||
| 278 | ->getRemittanceInformation() |
||
| 279 | ->getUnstructuredBlocks()[0] |
||
| 280 | ->getMessage() |
||
| 281 | ); |
||
| 282 | |||
| 283 | // Second unstructured block |
||
| 284 | $this->assertEquals( |
||
| 285 | 'Unstructured Remittance Information V3 block 2', |
||
| 286 | $transactionDetail |
||
| 287 | ->getRemittanceInformation() |
||
| 288 | ->getUnstructuredBlocks()[1] |
||
| 289 | ->getMessage() |
||
| 290 | ); |
||
| 291 | |||
| 292 | // Ref number from the first structured block |
||
| 293 | $this->assertEquals( |
||
| 294 | 'Ref number V3 block 1', |
||
| 295 | $transactionDetail |
||
| 296 | ->getRemittanceInformation() |
||
| 297 | ->getStructuredBlocks()[0] |
||
| 298 | ->getCreditorReferenceInformation() |
||
| 299 | ->getRef() |
||
| 300 | ); |
||
| 301 | |||
| 302 | // Ref number from the second structured block |
||
| 303 | $this->assertEquals( |
||
| 304 | 'Ref number V3 block 2', |
||
| 305 | $transactionDetail |
||
| 306 | ->getRemittanceInformation() |
||
| 307 | ->getStructuredBlocks()[1] |
||
| 308 | ->getCreditorReferenceInformation() |
||
| 309 | ->getRef() |
||
| 310 | ); |
||
| 311 | |||
| 312 | // Code from the first structured block |
||
| 313 | $this->assertEquals( |
||
| 314 | 'SCOR', |
||
| 315 | $transactionDetail |
||
| 316 | ->getRemittanceInformation() |
||
| 317 | ->getStructuredBlocks()[0] |
||
| 318 | ->getCreditorReferenceInformation() |
||
| 319 | ->getCode() |
||
| 320 | ); |
||
| 321 | |||
| 322 | // Code from the second structured block |
||
| 323 | $this->assertEquals( |
||
| 324 | 'SCOR', |
||
| 325 | $transactionDetail |
||
| 326 | ->getRemittanceInformation() |
||
| 327 | ->getStructuredBlocks()[1] |
||
| 328 | ->getCreditorReferenceInformation() |
||
| 329 | ->getCode() |
||
| 330 | ); |
||
| 331 | |||
| 332 | // Additional remittance information from the first structured block |
||
| 333 | $this->assertEquals( |
||
| 334 | 'Additional Remittance Information V3 block 1', |
||
| 335 | $transactionDetail |
||
| 336 | ->getRemittanceInformation() |
||
| 337 | ->getStructuredBlocks()[0] |
||
| 338 | ->getAdditionalRemittanceInformation() |
||
| 339 | ); |
||
| 340 | |||
| 341 | // Additional remittance information from the second structured block |
||
| 342 | $this->assertEquals( |
||
| 343 | 'Additional Remittance Information V3 block 2', |
||
| 344 | $transactionDetail |
||
| 345 | ->getRemittanceInformation() |
||
| 346 | ->getStructuredBlocks()[1] |
||
| 347 | ->getAdditionalRemittanceInformation() |
||
| 348 | ); |
||
| 349 | break; |
||
| 350 | default: |
||
| 351 | break; |
||
| 352 | } |
||
| 359 |