Completed
Push — master ( 03230b...27b37b )
by Hannes
02:11
created

PayeeProcessor::beforePayeeBgcNumberNode()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 9

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
c 0
b 0
f 0
rs 9.4285
cc 3
eloc 9
nc 4
nop 1
1
<?php
2
/**
3
 * This file is part of byrokrat\autogiro.
4
 *
5
 * byrokrat\autogiro is free software: you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License as published
7
 * by the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * byrokrat\autogiro is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with byrokrat\autogiro. If not, see <http://www.gnu.org/licenses/>.
17
 *
18
 * Copyright 2016 Hannes Forsgård
19
 */
20
21
declare(strict_types = 1);
22
23
namespace byrokrat\autogiro\Processor;
24
25
use byrokrat\autogiro\Tree\FileNode;
26
use byrokrat\autogiro\Tree\PayeeBankgiroNode;
27
use byrokrat\autogiro\Tree\PayeeBgcNumberNode;
28
29
/**
30
 * Validate that payee bankgiro and BGC customer number are constant within tree
31
 */
32
class PayeeProcessor extends Processor
33
{
34
    /**
35
     * @var string Payee bankgiro account number
36
     */
37
    private $payeeBg;
38
39
    /**
40
     * @var string Payee BGC customer number
41
     */
42
    private $payeeBgcNr;
43
44
    /**
45
     * Reset payee bankgiro and customer number before a new file is traversed
46
     */
47
    public function beforeFileNode(FileNode $fileNode)
48
    {
49
        $this->payeeBg = '';
50
        $this->payeeBgcNr = '';
51
    }
52
53
    /**
54
     * Validate payee bankgiro number
55
     */
56 View Code Duplication
    public function beforePayeeBankgiroNode(PayeeBankgiroNode $node)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
    {
58
        if (!$this->payeeBg) {
59
            $this->payeeBg = $node->getValue();
60
        }
61
62
        if ($node->getValue() != $this->payeeBg) {
63
            $this->addError(
64
                "Non-matching payee bankgiro numbers (expecting: %s, found: %s) on line %s",
65
                $this->payeeBg,
66
                $node->getValue(),
67
                (string)$node->getLineNr()
68
            );
69
        }
70
    }
71
72
    /**
73
     * Validate payee BGC customer number
74
     */
75 View Code Duplication
    public function beforePayeeBgcNumberNode(PayeeBgcNumberNode $node)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
    {
77
        if (!$this->payeeBgcNr) {
78
            $this->payeeBgcNr = $node->getValue();
79
        }
80
81
        if ($node->getValue() != $this->payeeBgcNr) {
82
            $this->addError(
83
                "Non-matching payee BGC customer numbers (expecting: %s, found: %s) on line %s",
84
                $this->payeeBgcNr,
85
                $node->getValue(),
86
                (string)$node->getLineNr()
87
            );
88
        }
89
    }
90
}
91