CompilerConfigurator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 39
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 25 3
A loadCompilerPasses() 0 4 2
1
<?php
2
3
/**
4
 * This file is part of byrokrat\giroapp.
5
 *
6
 * byrokrat\giroapp is free software: you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License as published
8
 * by the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * byrokrat\giroapp is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with byrokrat\giroapp. If not, see <http://www.gnu.org/licenses/>.
18
 *
19
 * Copyright 2016-21 Hannes Forsgård
20
 */
21
22
declare(strict_types=1);
23
24
namespace byrokrat\giroapp\Xml;
25
26
use Money\MoneyParser;
27
28
/**
29
 * Configure compiler based on ini settings
30
 */
31
final class CompilerConfigurator
32
{
33
    public const PAYER_NR_STRATEGY_PERSONAL_ID = 'personal-id';
34
    public const PAYER_NR_STRATEGY_IGNORE = 'ignore';
35
36
    /** @var array<CompilerPassInterface> */
37
    private $compilerPasses = [];
38
39
    public function __construct(
40
        string $payerNrStrategy,
41
        string $donationAmountFromAttribute,
42
        string $phoneFromAttribute,
43
        string $emailFromAttribute,
44
        string $commentFromAttribute,
45
        MoneyParser $moneyParser
46
    ) {
47
        switch ($payerNrStrategy) {
48
            case self::PAYER_NR_STRATEGY_PERSONAL_ID:
49
                $this->compilerPasses[] = new PayerNrFromPersonalIdPass();
50
                break;
51
            case self::PAYER_NR_STRATEGY_IGNORE:
52
            default:
53
                // ignore
54
        }
55
56
        $this->compilerPasses[] = new DonationAmountFromAttributePass(
57
            $donationAmountFromAttribute,
58
            $moneyParser
59
        );
60
61
        $this->compilerPasses[] = new PhoneFromAttributePass($phoneFromAttribute);
62
        $this->compilerPasses[] = new EmailFromAttributePass($emailFromAttribute);
63
        $this->compilerPasses[] = new CommentFromAttributePass($commentFromAttribute);
64
    }
65
66
    public function loadCompilerPasses(XmlMandateCompiler $compiler): void
67
    {
68
        foreach ($this->compilerPasses as $compilerPass) {
69
            $compiler->addCompilerPass($compilerPass);
70
        }
71
    }
72
}
73