Passed
Push — master ( af11e6...9ff364 )
by Sebastian
03:46
created

NoTrackingTrait::isTrackingEnabled()   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
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * File containing the {@see \Mailcode\Traits\Commands\Validation\NoTrackingTrait} trait.
4
 *
5
 * @see \Mailcode\Traits\Commands\Validation\NoTrackingTrait
6
 * @subpackage Validation
7
 * @package Mailcode
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode\Traits\Commands\Validation;
13
14
use Mailcode\Interfaces\Commands\Validation\NoTrackingInterface;
15
use Mailcode\Mailcode_Commands_Keywords;
16
use Mailcode\Mailcode_Exception;
17
use Mailcode\Mailcode_Parser_Statement_Tokenizer_Token_Keyword;
18
use Mailcode\Mailcode_Parser_Statement_Validator;
19
use phpDocumentor\Descriptor\Interfaces\FunctionInterface;
0 ignored issues
show
Bug introduced by
The type phpDocumentor\Descriptor...faces\FunctionInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use phpDocumentor\Reflection\Utils;
21
22
/**
23
 * Command validation drop-in: checks for the presence
24
 * of the `no-tracking:` keyword in the command statement,
25
 * and sets the tracking enabled flag accordingly.
26
 *
27
 * @package Mailcode
28
 * @subpackage Validation
29
 * @author Sebastian Mordziol <[email protected]>
30
 *
31
 * @see NoTrackingInterface
32
 *
33
 * @property Mailcode_Parser_Statement_Validator $validator
34
 */
35
trait NoTrackingTrait
36
{
37
    /**
38
     * @var boolean
39
     */
40
    protected bool $trackingEnabled = true;
41
42
    /**
43
     * @var Mailcode_Parser_Statement_Tokenizer_Token_Keyword|NULL
44
     */
45
    protected ?Mailcode_Parser_Statement_Tokenizer_Token_Keyword $noTrackingToken = null;
46
47
    protected function validateSyntax_no_tracking() : void
48
    {
49
        $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

49
        $keywords = $this->/** @scrutinizer ignore-call */ requireParams()
Loading history...
50
            ->getInfo()
51
            ->getKeywords();
52
53
        // Reset the tracking values in case we are calling
54
        // this after the initial validation.
55
        $this->noTrackingToken = null;
56
        $this->trackingEnabled = true;
57
58
        foreach($keywords as $keyword)
59
        {
60
            if($keyword->getKeyword() === Mailcode_Commands_Keywords::TYPE_NO_TRACKING)
61
            {
62
                $this->noTrackingToken = $keyword;
63
                $this->trackingEnabled = false;
64
                break;
65
            }
66
        }
67
    }
68
69
    public function isTrackingEnabled() : bool
70
    {
71
        return $this->trackingEnabled;
72
    }
73
74
    /**
75
     * @param bool $enabled
76
     * @return $this
77
     * @throws Mailcode_Exception
78
     */
79
    public function setTrackingEnabled(bool $enabled) : self
80
    {
81
        $this->requireParams()
82
            ->getInfo()
83
            ->setKeywordEnabled(Mailcode_Commands_Keywords::TYPE_NO_TRACKING, !$enabled);
84
85
        $this->validateSyntax_no_tracking();
86
87
        return $this;
88
    }
89
90
    public function getNoTrackingToken() : ?Mailcode_Parser_Statement_Tokenizer_Token_Keyword
91
    {
92
        if($this->noTrackingToken instanceof Mailcode_Parser_Statement_Tokenizer_Token_Keyword)
93
        {
94
            return $this->noTrackingToken;
95
        }
96
97
        return null;
98
    }
99
}
100