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

RegionTrait::validateSyntax_check_region()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 21
rs 9.8333
cc 4
nc 3
nop 0
1
<?php
2
/**
3
 * File containing the trait {@see \Mailcode\Traits\Commands\Validation\RegionTrait}.
4
 *
5
 * @package Mailcode
6
 * @subpackage Validation
7
 * @see \Mailcode\Traits\Commands\Validation\RegionTrait
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
/**
15
 * @package Mailcode
16
 * @subpackage Validation
17
 * @author Olaf Böcker <[email protected]>
18
 *
19
 * @see RegionInterface
20
 */
21
trait RegionTrait
22
{
23
    private ?Mailcode_Parser_Statement_Tokenizer_Token $region = null;
24
25
    /**
26
     * @throws Mailcode_Exception
27
     */
28
    protected function validateSyntax_check_region(): void
29
    {
30
        $token = $this
31
            ->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

31
            ->/** @scrutinizer ignore-call */ requireParams()
Loading history...
32
            ->getInfo()
33
            ->getTokenByParamName(RegionInterface::REGION_PARAMETER_NAME);
34
35
        if ($token === null) {
36
            return;
37
        }
38
39
        if (!$token instanceof Mailcode_Parser_Statement_Tokenizer_Token_Variable &&
40
            !$token instanceof Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral) {
41
            $this->validationResult->makeError(
42
                t('Invalid region token:') . ' ' . t('Expected a variable or a string.'),
43
                RegionInterface::VALIDATION_REGION_WRONG_TYPE
44
            );
45
            return;
46
        }
47
48
        $this->region = $token;
49
    }
50
51
    public function isRegionPresent(): bool
52
    {
53
        return $this->getRegionToken() !== null;
54
    }
55
56
    public function getRegionToken(): ?Mailcode_Parser_Statement_Tokenizer_Token
57
    {
58
        return $this->region;
59
    }
60
}
61