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