Passed
Pull Request — master (#18)
by
unknown
09:22
created

CurrencyNameTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 12
c 1
b 0
f 0
dl 0
loc 35
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setCurrencyNameEnabled() 0 7 1
A getCurrencyNameToken() 0 6 1
A isCurrencyNameEnabled() 0 5 1
1
<?php
2
/**
3
 * File containing the {@see \Mailcode\Traits\Commands\Validation\CurrencyNameTrait} trait.
4
 *
5
 * @see \Mailcode\Traits\Commands\Validation\CurrencyNameTrait
6
 * @subpackage Validation
7
 * @package Mailcode
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
/**
15
 * Command validation drop-in: checks for the presence
16
 * of the `currency-name:` keyword in the command statement,
17
 * and sets the currency name enabled flag accordingly.
18
 *
19
 * @package Mailcode
20
 * @subpackage Validation
21
 * @author Olaf Böcker <[email protected]>
22
 *
23
 * @see CurrencyNameInterface
24
 */
25
trait CurrencyNameTrait
26
{
27
    /**
28
     * @throws Mailcode_Exception
29
     */
30
    public function isCurrencyNameEnabled(): bool
31
    {
32
        return $this->requireParams()
0 ignored issues
show
Bug introduced by
It seems like requireParams() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

32
        return $this->/** @scrutinizer ignore-call */ requireParams()
Loading history...
33
            ->getInfo()
34
            ->hasKeyword(Mailcode_Commands_Keywords::TYPE_CURRENCY_NAME);
35
    }
36
37
    /**
38
     * @param bool $enabled
39
     * @return $this
40
     * @throws Mailcode_Exception
41
     */
42
    public function setCurrencyNameEnabled(bool $enabled): self
43
    {
44
        $this->requireParams()
45
            ->getInfo()
46
            ->setKeywordEnabled(Mailcode_Commands_Keywords::TYPE_CURRENCY_NAME, $enabled);
47
48
        return $this;
49
    }
50
51
    /**
52
     * @throws Mailcode_Exception
53
     */
54
    public function getCurrencyNameToken(): ?Mailcode_Parser_Statement_Tokenizer_Token_Keyword
55
    {
56
        return $this->requireParams()
57
            ->getInfo()
58
            ->getKeywordsCollection()
59
            ->getByName(Mailcode_Commands_Keywords::TYPE_CURRENCY_NAME);
60
    }
61
}
62