Passed
Pull Request — master (#10)
by
unknown
03:24
created

TimezoneTrait::getTimezoneToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * File containing the trait {@see \Mailcode\Traits\Commands\Validation\TimezoneTrait}.
4
 *
5
 * @package Mailcode
6
 * @subpackage Validation
7
 * @see \Mailcode\Traits\Commands\Validation\TimezoneTrait
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode\Traits\Commands\Validation;
13
14
use Mailcode\Interfaces\Commands\Validation\TimezoneInterface;
15
use Mailcode\Mailcode_Parser_Statement_Tokenizer_Token;
16
use Mailcode\Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral;
17
use Mailcode\Mailcode_Parser_Statement_Tokenizer_Token_Variable;
18
use function Mailcode\t;
19
20
/**
21
 * @package Mailcode
22
 * @subpackage Validation
23
 * @author Olaf Böcker <[email protected]>
24
 *
25
 * @see TimezoneInterface
26
 */
27
trait TimezoneTrait
28
{
29
    private bool $timezoneEnabled = false;
30
31
    private ?Mailcode_Parser_Statement_Tokenizer_Token $timezoneToken = null;
32
33
    protected function validateSyntax_check_timezone(): void
34
    {
35
        $tokens = $this->requireParams()->getInfo()->getTokens();
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
        $tokens = $this->/** @scrutinizer ignore-call */ requireParams()->getInfo()->getTokens();
Loading history...
36
37
        if (count($tokens) > 2) {
38
            $this->timezoneToken = $tokens[2];
39
40
            if (!$this->timezoneToken instanceof Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral &&
41
                !$this->timezoneToken instanceof Mailcode_Parser_Statement_Tokenizer_Token_Variable) {
42
                $this->validationResult->makeError(
43
                    t('Invalid timezone type.' . ' ' . 'Expected String or Variable.'),
44
                    TimezoneInterface::VALIDATION_TIMEZONE_CODE_WRONG_TYPE
45
                );
46
                return;
47
            }
48
49
            $this->timezoneEnabled = true;
50
        }
51
    }
52
53
    public function hasTimezone(): bool
54
    {
55
        return isset($this->timezoneToken);
56
    }
57
58
    public function getTimezoneToken(): ?Mailcode_Parser_Statement_Tokenizer_Token
59
    {
60
        return $this->timezoneToken;
61
    }
62
}
63