Passed
Pull Request — master (#18)
by Sebastian
07:37
created

Mailcode_Commands_Command_ShowPrice   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 36
c 1
b 0
f 0
dl 0
loc 70
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setLocalCurrency() 0 4 1
A getValidations() 0 8 1
A getName() 0 3 1
A getLabel() 0 3 1
A getLocalCurrency() 0 6 2
A validateSyntax_check_currency_exclusive() 0 16 3
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Commands_Command_ShowPrice} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Commands
7
 * @see Mailcode_Commands_Command_ShowPrice
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
use Mailcode\Interfaces\Commands\Validation\AbsoluteKeywordInterface;
15
use Mailcode\Traits\Commands\Validation\AbsoluteKeywordTrait;
16
17
/**
18
 * Mailcode command: Display a variable containing a price with currency.
19
 *
20
 * @package Mailcode
21
 * @subpackage Commands
22
 * @author Olaf Böcker <[email protected]>
23
 */
24
class Mailcode_Commands_Command_ShowPrice extends Mailcode_Commands_ShowBase
25
    implements
26
    RegionInterface,
27
    CurrencyInterface,
28
    CurrencyNameInterface,
29
    AbsoluteKeywordInterface
30
{
31
    use RegionTrait;
32
    use CurrencyTrait;
33
    use CurrencyNameTrait;
34
    use AbsoluteKeywordTrait;
35
36
    /**
37
     * @var Mailcode_Number_LocalCurrency
38
     */
39
    private Mailcode_Number_LocalCurrency $localCurrency;
40
41
    public function getName(): string
42
    {
43
        return 'showprice';
44
    }
45
46
    public function getLabel(): string
47
    {
48
        return t('Show price variable');
49
    }
50
51
    protected function getValidations(): array
52
    {
53
        return array(
54
            Mailcode_Interfaces_Commands_Validation_Variable::VALIDATION_NAME_VARIABLE,
55
            AbsoluteKeywordInterface::VALIDATION_NAME,
56
            'check_currency_exclusive',
57
            'check_currency',
58
            'check_region'
59
        );
60
    }
61
62
    protected function validateSyntax_check_currency_exclusive(): void
63
    {
64
        $hasCurrencyNameKeyword = $this
65
            ->requireParams()
66
            ->getInfo()
67
            ->hasKeyword(Mailcode_Commands_Keywords::TYPE_CURRENCY_NAME);
68
69
        $hasCurrencyParameter = $this
70
            ->requireParams()
71
            ->getInfo()
72
            ->getTokenByParamName(CurrencyInterface::CURRENCY_PARAMETER_NAME);
73
74
        if ($hasCurrencyParameter && $hasCurrencyNameKeyword) {
75
            $this->validationResult->makeError(
76
                t("Can not use both 'currency-name' and 'currency'"),
77
                CurrencyInterface::VALIDATION_CURRENCY_EXCLUSIVE
78
            );
79
        }
80
    }
81
82
    public function getLocalCurrency(): Mailcode_Number_LocalCurrency
83
    {
84
        if (!isset($this->localCurrency)) {
85
            $this->localCurrency = Mailcode_Number_LocalCurrency::defaultInstance();
86
        }
87
        return $this->localCurrency;
88
    }
89
90
    public function setLocalCurrency(Mailcode_Number_LocalCurrency $localCurrency): Mailcode_Commands_Command_ShowPrice
91
    {
92
        $this->localCurrency = $localCurrency;
93
        return $this;
94
    }
95
}
96
97