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

CountTrait::validateSyntax_count()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 11
c 1
b 0
f 0
nc 6
nop 0
dl 0
loc 17
rs 9.9
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\Mailcode_Commands_CommonConstants;
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
 *
28
 * @see CountInterface
29
 */
30
trait CountTrait
31
{
32
    /**
33
     * @var boolean
34
     */
35
    private bool $countEnabled = false;
36
37
    private ?Mailcode_Parser_Statement_Tokenizer_Token_Variable $token = null;
38
39
    protected function validateSyntax_count(): void
40
    {
41
        $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

41
        $token = $this->/** @scrutinizer ignore-call */ requireParams()->getInfo()->getTokenForKeyword(Mailcode_Commands_Keywords::TYPE_COUNT);
Loading history...
42
        if ($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_Variable) {
43
            $this->token = $token;
44
        }
45
46
        $val = $this->validator->createKeyword(Mailcode_Commands_Keywords::TYPE_COUNT);
47
        $this->countEnabled = $val->isValid();
48
49
        if ($this->countEnabled) {
50
            if (!$this->token instanceof Mailcode_Parser_Statement_Tokenizer_Token_Variable) {
51
                $this->validationResult->makeError(
52
                    t('Invalid count usage'),
53
                    Mailcode_Commands_CommonConstants::VALIDATION_INVALID_COUNT_USAGE
54
                );
55
                return;
56
            }
57
        }
58
    }
59
60
    public function isCountEnabled(): bool
61
    {
62
        return $this->countEnabled;
63
    }
64
65
    public function getCountVariable(): ?Mailcode_Variables_Variable
66
    {
67
        return $this->token->getVariable();
0 ignored issues
show
Bug introduced by
The method getVariable() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

67
        return $this->token->/** @scrutinizer ignore-call */ getVariable();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
68
    }
69
70
}
71