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

CountTrait::getCountVariable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
nc 2
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * File containing the {@see \Mailcode\Traits\Commands\Validation\CountTrait} trait.
4
 *
5
 * @see \Mailcode\Traits\Commands\Validation\CountTrait
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\CountInterface;
15
use Mailcode\Mailcode_Commands_Keywords;
16
use Mailcode\Mailcode_Parser_Statement_Tokenizer_Token_Variable;
17
use Mailcode\Mailcode_Variables_Variable;
18
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...
19
use function Mailcode\t;
20
21
/**
22
 * Command validation drop-in: checks for the presence
23
 * of the `count:` keyword in the command statement.
24
 *
25
 * @package Mailcode
26
 * @subpackage Validation
27
 * @author Olaf Böcker <[email protected]>
28
 *
29
 * @see CountInterface
30
 */
31
trait CountTrait
32
{
33
    private bool $countEnabled = false;
34
35
    private ?Mailcode_Parser_Statement_Tokenizer_Token_Variable $countToken = null;
36
37
    protected function validateSyntax_check_count(): void
38
    {
39
        $token = $this->requireParams()->getInfo()->getTokenForKeyword(Mailcode_Commands_Keywords::TYPE_COUNT);
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

39
        $token = $this->/** @scrutinizer ignore-call */ requireParams()->getInfo()->getTokenForKeyword(Mailcode_Commands_Keywords::TYPE_COUNT);
Loading history...
40
        if ($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_Variable) {
41
            $this->countToken = $token;
42
        }
43
44
        $val = $this->validator->createKeyword(Mailcode_Commands_Keywords::TYPE_COUNT);
45
46
        $this->countEnabled = $val->isValid();
47
48
        if ($this->countEnabled) {
49
            if (!$this->countToken instanceof Mailcode_Parser_Statement_Tokenizer_Token_Variable) {
50
                $this->validationResult->makeError(
51
                    t('Invalid count type.' . ' ' . 'Expected Variable.'),
52
                    CountInterface::VALIDATION_COUNT_CODE_WRONG_TYPE
53
                );
54
                return;
55
            }
56
        }
57
    }
58
59
    public function isCountEnabled(): bool
60
    {
61
        return $this->countEnabled;
62
    }
63
64
    public function getCountVariable(): ?Mailcode_Variables_Variable
65
    {
66
        return $this->countToken != null ? $this->countToken->getVariable() : null;
67
    }
68
}
69