Passed
Pull Request — master (#18)
by
unknown
13:04 queued 09:21
created

Mailcode_Commands_Command_ShowPrice::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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
/**
15
 * Mailcode command: show a date variable value.
16
 *
17
 * @package Mailcode
18
 * @subpackage Commands
19
 * @author Olaf Böcker <[email protected]>
20
 */
21
class Mailcode_Commands_Command_ShowPrice extends Mailcode_Commands_ShowBase
22
    implements
23
    CurrencyNameInterface
24
{
25
    public const VALIDATION_CODE_1 = 163401;
26
27
    use CurrencyNameTrait;
28
29
    /**
30
     * @var Mailcode_Parser_Statement_Tokenizer_Token_Keyword|NULL
31
     */
32
    private ?Mailcode_Parser_Statement_Tokenizer_Token_Keyword $absoluteKeyword = null;
33
34
    /**
35
     * @var Mailcode_Number_LocalCurrency
36
     */
37
    private Mailcode_Number_LocalCurrency $localCurrency;
38
39
    public function getName(): string
40
    {
41
        return 'showprice';
42
    }
43
44
    public function getLabel(): string
45
    {
46
        return t('Show price variable');
47
    }
48
49
    protected function getValidations(): array
50
    {
51
        return array(
52
            Mailcode_Interfaces_Commands_Validation_Variable::VALIDATION_NAME_VARIABLE,
53
            'absolute'
54
        );
55
    }
56
57
    protected function validateSyntax_absolute(): void
58
    {
59
        $keywords = $this->requireParams()
60
            ->getInfo()
61
            ->getKeywords();
62
63
        foreach ($keywords as $keyword) {
64
            if ($keyword->getKeyword() === Mailcode_Commands_Keywords::TYPE_ABSOLUTE) {
65
                $this->absoluteKeyword = $keyword;
66
                break;
67
            }
68
        }
69
    }
70
71
    public function isAbsolute(): bool
72
    {
73
        return isset($this->absoluteKeyword);
74
    }
75
76
    public function setAbsolute(bool $absolute): Mailcode_Commands_Command_ShowPrice
77
    {
78
        if ($absolute === false && isset($this->absoluteKeyword)) {
79
            $this->requireParams()->getInfo()->removeKeyword($this->absoluteKeyword->getKeyword());
0 ignored issues
show
Bug introduced by
The method getKeyword() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

79
            $this->requireParams()->getInfo()->removeKeyword($this->absoluteKeyword->/** @scrutinizer ignore-call */ getKeyword());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
80
            $this->absoluteKeyword = null;
81
        }
82
83
        if ($absolute === true && !isset($this->absoluteKeyword)) {
84
            $this->requireParams()
85
                ->getInfo()
86
                ->addKeyword(Mailcode_Commands_Keywords::TYPE_ABSOLUTE);
87
88
            $this->validateSyntax_absolute();
89
        }
90
91
        return $this;
92
    }
93
94
    public function getLocalCurrency(): Mailcode_Number_LocalCurrency
95
    {
96
        if (!isset($this->localCurrency)) {
97
            $this->localCurrency = Mailcode_Number_LocalCurrency::defaultInstance();
98
        }
99
        return $this->localCurrency;
100
    }
101
102
    public function setLocalCurrency(Mailcode_Number_LocalCurrency $localCurrency): Mailcode_Commands_Command_ShowPrice
103
    {
104
        $this->localCurrency = $localCurrency;
105
        return $this;
106
    }
107
}
108
109