Completed
Push — master ( a29d2d...4681dd )
by Hannes
10:53 queued 08:08
created

PayeeProcessor::beforeFileNode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
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\OpeningNode;
26
use byrokrat\autogiro\Tree\FileNode;
27
28
/**
29
 * Validate that payee bankgiro and BGC customer number are constant within tree
30
 */
31
class PayeeProcessor extends Processor
32
{
33
    /**
34
     * @var string
35
     */
36
    private $bankgiro;
37
38
    /**
39
     * @var string
40
     */
41
    private $custNr;
42
43
    /**
44
     * Reset bankgiro and customer number before a new file is traversed
45
     */
46
    public function beforeFileNode(FileNode $fileNode)
47
    {
48
        $this->bankgiro = '';
49
        $this->custNr = '';
50
    }
51
52
    /**
53
     * Validate bankgiro and customer number of section
54
     */
55
    public function beforeOpeningNode(OpeningNode $node)
56
    {
57
        if (!$this->bankgiro) {
58
            $this->bankgiro = $node->getChild('bankgiro')->getValue();
59
        }
60
61
        if (!$this->custNr) {
62
            $this->custNr = $node->getChild('customer_number')->getValue();
63
        }
64
65 View Code Duplication
        if ($node->getChild('bankgiro')->getValue() != $this->bankgiro) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
66
            $this->addError(
67
                "Non-matching payee bankgiro numbers within file (%s and %s) on line %s",
68
                $this->bankgiro,
69
                $node->getChild('bankgiro')->getValue(),
70
                (string)$node->getLineNr()
71
            );
72
        }
73
74 View Code Duplication
        if ($node->getChild('customer_number')->getValue() != $this->custNr) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
75
            $this->addError(
76
                "Non-matching payee BGC customer numbers within file (%s and %s) on line %s",
77
                $this->custNr,
78
                $node->getChild('customer_number')->getValue(),
79
                (string)$node->getLineNr()
80
            );
81
        }
82
    }
83
}
84