Passed
Push — master ( 5d6ae0...deb6f9 )
by Sebastian
03:48
created

validateSyntax_regex_enabled()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 9
rs 10
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Traits_Commands_Validation_RegexEnabled} trait.
4
 *
5
 * @package Mailcode
6
 * @subpackage Validation
7
 * @see Mailcode_Traits_Commands_Validation_RegexEnabled
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 `regex:` keyword in the command statement,
17
 * and sets the regex enabled flag accordingly.
18
 *
19
 * @package Mailcode
20
 * @subpackage Validation
21
 * @author Sebastian Mordziol <[email protected]>
22
 *
23
 * @property Mailcode_Parser_Statement_Validator $validator
24
 *
25
 * @see Mailcode_Interfaces_Commands_RegexEnabled
26
 */
27
trait Mailcode_Traits_Commands_Validation_RegexEnabled
28
{
29
    /**
30
     * @var boolean
31
     */
32
    protected $regexEnabled = false;
33
34
    /**
35
     * @var Mailcode_Parser_Statement_Tokenizer_Token_Keyword|NULL
36
     */
37
    protected $regexToken;
38
39
    protected function validateSyntax_regex_enabled() : void
40
    {
41
        $val = $this->validator->createKeyword('regex');
42
43
        $this->regexEnabled = $val->isValid();
44
45
        if($val->isValid())
46
        {
47
            $this->regexToken = $val->getToken();
48
        }
49
    }
50
51
    public function isRegexEnabled() : bool
52
    {
53
        return $this->regexEnabled;
54
    }
55
56
    public function getRegexToken() : ?Mailcode_Parser_Statement_Tokenizer_Token_Keyword
57
    {
58
        if($this->regexToken instanceof Mailcode_Parser_Statement_Tokenizer_Token_Keyword)
59
        {
60
            return $this->regexToken;
61
        }
62
63
        return null;
64
    }
65
}
66