Code Duplication    Length = 9-11 lines in 12 locations

src/Parser/Banking/Mt940/Engine.php 6 locations

@@ 352-362 (lines=11) @@
349
     *
350
     * @return string
351
     */
352
    protected function parseStatementNumber()
353
    {
354
        $results = [];
355
        if (preg_match('/:28C?:(.*)/', $this->getCurrentStatementData(), $results)
356
                && !empty($results[1])
357
        ) {
358
            return trim($results[1]);
359
        }
360
361
        return '';
362
    }
363
364
    // transaction parsers, these work with getCurrentTransactionData
365
    /**
@@ 370-380 (lines=11) @@
367
     *
368
     * @return string
369
     */
370
    protected function parseTransactionAccount()
371
    {
372
        $results = [];
373
        if (preg_match('/^:86: ?([\d\.]+)\s/im', $this->getCurrentTransactionData(), $results)
374
                && !empty($results[1])
375
        ) {
376
            return $this->sanitizeAccount($results[1]);
377
        }
378
379
        return '';
380
    }
381
382
    /**
383
     * uses the 86 field to determine accountname of the transaction.
@@ 387-397 (lines=11) @@
384
     *
385
     * @return string
386
     */
387
    protected function parseTransactionAccountName()
388
    {
389
        $results = [];
390
        if (preg_match('/:86: ?[\d\.]+ (.+)/', $this->getCurrentTransactionData(), $results)
391
                && !empty($results[1])
392
        ) {
393
            return $this->sanitizeAccountName($results[1]);
394
        }
395
396
        return '';
397
    }
398
399
    /**
400
     * uses the 61 field to determine amount/value of the transaction.
@@ 404-414 (lines=11) @@
401
     *
402
     * @return float
403
     */
404
    protected function parseTransactionPrice()
405
    {
406
        $results = [];
407
        if (preg_match('/^:61:.*[CD]([\d,\.]+)N/i', $this->getCurrentTransactionData(), $results)
408
                && !empty($results[1])
409
        ) {
410
            return $this->sanitizePrice($results[1]);
411
        }
412
413
        return 0;
414
    }
415
416
    /**
417
     * uses the 61 field to determine debit or credit of the transaction.
@@ 421-431 (lines=11) @@
418
     *
419
     * @return string
420
     */
421
    protected function parseTransactionDebitCredit()
422
    {
423
        $results = [];
424
        if (preg_match('/^:61:\d+([CD])\d+/', $this->getCurrentTransactionData(), $results)
425
                && !empty($results[1])
426
        ) {
427
            return $this->sanitizeDebitCredit($results[1]);
428
        }
429
430
        return '';
431
    }
432
433
    /**
434
     * uses the 86 field to determine retrieve the full description of the transaction.
@@ 493-503 (lines=11) @@
490
     *
491
     * @return string
492
     */
493
    protected function parseTransactionCode()
494
    {
495
        $results = [];
496
        if (preg_match('/^:61:.*?N(.{3}).*/', $this->getCurrentTransactionData(), $results)
497
                && !empty($results[1])
498
        ) {
499
            return trim($results[1]);
500
        }
501
502
        return '';
503
    }
504
505
    /**
506
     * @param string $string

src/Parser/Banking/Mt940/Engine/Knab.php 1 location

@@ 76-84 (lines=9) @@
73
    /**
74
     * @inheritdoc
75
     */
76
    protected function parseTransactionAccountName()
77
    {
78
        $results = [];
79
        if (preg_match('/NAAM: (.+)/', $this->getCurrentTransactionData(), $results)
80
                && !empty($results[1])
81
        ) {
82
            return trim($results[1]);
83
        }
84
    }
85
86
    /**
87
     * @inheritdoc

src/Parser/Banking/Mt940/Engine/Rabo.php 2 locations

@@ 80-88 (lines=9) @@
77
     *
78
     * {@inheritdoc}
79
     */
80
    protected function parseTransactionEntryTimestamp()
81
    {
82
        $results = [];
83
        if (preg_match('/^:60F:[C|D]([\d]{6})/m', $this->getCurrentStatementData(), $results) && !empty($results[1])) {
84
            return $this->sanitizeTimestamp($results[1], 'ymd');
85
        }
86
87
        return 0;
88
    }
89
90
    /**
91
     * Overloaded: Rabo has different way of storing transaction value timestamps (ymd).
@@ 95-103 (lines=9) @@
92
     *
93
     * {@inheritdoc}
94
     */
95
    protected function parseTransactionValueTimestamp()
96
    {
97
        $results = [];
98
        if (preg_match('/^:61:([\d]{6})[C|D]/', $this->getCurrentTransactionData(), $results) && !empty($results[1])) {
99
            return $this->sanitizeTimestamp($results[1], 'ymd');
100
        }
101
102
        return 0;
103
    }
104
105
    /**
106
     * Overloaded: Rabo uses longer strings for accountnumbers.

src/Parser/Banking/Mt940/Engine/Spk.php 2 locations

@@ 71-81 (lines=11) @@
68
     *
69
     * {@inheritdoc}
70
     */
71
    protected function parseTransactionPrice()
72
    {
73
        $results = [];
74
        if (preg_match('/^:61:.*[CD][a-zA-Z]?([\d,\.]+)N/i', $this->getCurrentTransactionData(), $results)
75
                && !empty($results[1])
76
        ) {
77
            return $this->sanitizePrice($results[1]);
78
        }
79
80
        return 0;
81
    }
82
83
    /**
84
     * Overloaded: Sparkasse can have the 3rd character of the currencyname after the C/D and an "R" for cancellation befor the C/D.
@@ 88-98 (lines=11) @@
85
     *
86
     * {@inheritdoc}
87
     */
88
    protected function parseTransactionDebitCredit()
89
    {
90
        $results = [];
91
        if (preg_match('/^:61:\d+R?([CD]).?\d+/', $this->getCurrentTransactionData(), $results)
92
                && !empty($results[1])
93
        ) {
94
            return $this->sanitizeDebitCredit($results[1]);
95
        }
96
97
        return '';
98
    }
99
100
    /**
101
     * Overloaded: Sparkasse does not have a header line.

src/Parser/Banking/Mt940/Engine/Triodos.php 1 location

@@ 28-38 (lines=11) @@
25
     *
26
     * {@inheritdoc}
27
     */
28
    protected function parseStatementAccount()
29
    {
30
        $results = [];
31
        if (preg_match('#:25:TRIODOSBANK/([\d\.]+)#', $this->getCurrentStatementData(), $results)
32
                && !empty($results[1])
33
        ) {
34
            return $this->sanitizeAccount($results[1]);
35
        }
36
37
        return parent::parseStatementAccount();
38
    }
39
40
    /**
41
     * Overloaded: According to spec, field :28: is always 1.