Passed
Push — master ( e7c89c...d9a062 )
by Sebastian
06:11 queued 12s
created

TimezoneTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 34
rs 10
c 1
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hasTimezone() 0 3 1
A validateSyntax_check_timezone() 0 17 4
A getTimezoneToken() 0 3 1
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