Passed
Pull Request — master (#11)
by
unknown
03:26
created

BreakAtTrait::getBreakAtToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
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\BreakAtTrait} trait.
4
 *
5
 * @see \Mailcode\Traits\Commands\Validation\BreakAtTrait
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\BreakAtInterface;
15
use Mailcode\Mailcode_Commands_Keywords;
16
use Mailcode\Mailcode_Parser_Statement_Tokenizer_Token;
17
use Mailcode\Mailcode_Parser_Statement_Tokenizer_Token_Number;
18
use Mailcode\Mailcode_Parser_Statement_Tokenizer_Token_Variable;
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 function Mailcode\t;
21
22
/**
23
 * Command validation drop-in: checks for the presence
24
 * of the `break-at:` keyword in the command statement.
25
 *
26
 * @package Mailcode
27
 * @subpackage Validation
28
 * @author Olaf Böcker <[email protected]>
29
 *
30
 * @see BreakAtInterface
31
 */
32
trait BreakAtTrait
33
{
34
    private bool $breakAtEnabled = false;
35
36
    private ?Mailcode_Parser_Statement_Tokenizer_Token $breakAtToken = null;
37
38
    protected function validateSyntax_check_break_at(): void
39
    {
40
        $this->breakAtToken = $this->requireParams()->getInfo()->getTokenForKeyword(Mailcode_Commands_Keywords::TYPE_BREAK_AT);
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

40
        $this->breakAtToken = $this->/** @scrutinizer ignore-call */ requireParams()->getInfo()->getTokenForKeyword(Mailcode_Commands_Keywords::TYPE_BREAK_AT);
Loading history...
41
42
        $val = $this->validator->createKeyword(Mailcode_Commands_Keywords::TYPE_BREAK_AT);
43
44
        $this->breakAtEnabled = $val->isValid() && $this->breakAtToken != null;;
45
46
        if ($this->breakAtEnabled) {
47
            if (!$this->breakAtToken instanceof Mailcode_Parser_Statement_Tokenizer_Token_Number &&
48
                !$this->breakAtToken instanceof Mailcode_Parser_Statement_Tokenizer_Token_Variable) {
49
                $this->validationResult->makeError(
50
                    t('Invalid break-at type.' . ' ' . 'Expected Number or Variable.'),
51
                    BreakAtInterface::VALIDATION_BREAK_AT_CODE_WRONG_TYPE
52
                );
53
                return;
54
            }
55
        }
56
    }
57
58
    public function isBreakAtEnabled(): bool
59
    {
60
        return $this->breakAtEnabled;
61
    }
62
63
    public function getBreakAtToken(): ?Mailcode_Parser_Statement_Tokenizer_Token
64
    {
65
        return $this->breakAtToken;
66
    }
67
}
68