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

AbsoluteKeywordTrait::validateSyntax_absolute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 3
nc 3
nop 0
1
<?php
2
/**
3
 * @package Mailcode
4
 * @subpackage Validation
5
 */
6
7
declare(strict_types=1);
8
9
namespace Mailcode\Traits\Commands\Validation;
10
11
use Mailcode\Interfaces\Commands\Validation\AbsoluteKeywordInterface;
12
use Mailcode\Mailcode_Commands_Keywords;
13
use Mailcode\Mailcode_Parser_Statement_Tokenizer_Token_Keyword;
14
15
/**
16
 * Command validation drop-in: checks for the presence
17
 * of the `absolute:` keyword in the command statement,
18
 * and sets the absolute number flag accordingly.
19
 *
20
 * @package Mailcode
21
 * @subpackage Validation
22
 * @author Sebastian Mordziol <[email protected]>
23
 *
24
 * @see AbsoluteKeywordInterface
25
 */
26
trait AbsoluteKeywordTrait
27
{
28
    /**
29
     * @var Mailcode_Parser_Statement_Tokenizer_Token_Keyword|NULL
30
     */
31
    private ?Mailcode_Parser_Statement_Tokenizer_Token_Keyword $absoluteKeyword = null;
32
33
    protected function validateSyntax_absolute(): void
34
    {
35
        $keywords = $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

35
        $keywords = $this->/** @scrutinizer ignore-call */ requireParams()
Loading history...
36
            ->getInfo()
37
            ->getKeywords();
38
39
        foreach ($keywords as $keyword) {
40
            if ($keyword->getKeyword() === Mailcode_Commands_Keywords::TYPE_ABSOLUTE) {
41
                $this->absoluteKeyword = $keyword;
42
                break;
43
            }
44
        }
45
    }
46
47
    public function isAbsolute(): bool
48
    {
49
        return isset($this->absoluteKeyword);
50
    }
51
52
    /**
53
     * @inheritdoc
54
     * @return $this
55
     */
56
    public function setAbsolute(bool $absolute): self
57
    {
58
        if ($absolute === false && isset($this->absoluteKeyword)) {
59
            $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

59
            $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...
60
            $this->absoluteKeyword = null;
61
        }
62
63
        if ($absolute === true && !isset($this->absoluteKeyword)) {
64
            $this->requireParams()
65
                ->getInfo()
66
                ->addKeyword(Mailcode_Commands_Keywords::TYPE_ABSOLUTE);
67
68
            $this->validateSyntax_absolute();
69
        }
70
71
        return $this;
72
    }
73
}
74