Test Failed
Push — master ( 36c5b6...af11e6 )
by Sebastian
04:51
created

validateSyntax_content_id()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 16
rs 9.9332
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Mailcode;
6
7
/**
8
 * @see Mailcode_Interfaces_Commands_ProtectedContent
9
 */
10
trait Mailcode_Traits_Commands_ProtectedContent
11
{
12
    /**
13
     * @var string
14
     */
15
    protected string $content = '';
16
17
    public function getContent() : string
18
    {
19
        return $this->content;
20
    }
21
22
    public function getContentTrimmed() : string
23
    {
24
        return trim($this->content);
25
    }
26
27
    protected ?Mailcode_Parser_Statement_Tokenizer_Token_Number $contentIDToken = null;
28
29
    public function getContentIDToken() : ?Mailcode_Parser_Statement_Tokenizer_Token_Number
30
    {
31
        return $this->contentIDToken;
32
    }
33
34
    protected function validateSyntax_content_id() : void
35
    {
36
        $contentIDToken = $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

36
        $contentIDToken = $this->/** @scrutinizer ignore-call */ requireParams()
Loading history...
37
            ->getInfo()
38
            ->getTokenByIndex(0);
39
40
        if($contentIDToken instanceof Mailcode_Parser_Statement_Tokenizer_Token_Number)
41
        {
42
            $this->contentIDToken = $contentIDToken;
43
            $this->loadContent();
44
            return;
45
        }
46
47
        $this->validationResult->makeError(
48
            t('The content ID parameter is missing.'),
49
            Mailcode_Interfaces_Commands_ProtectedContent::VALIDATION_ERROR_CONTENT_ID_MISSING
50
        );
51
    }
52
53
    public function getContentID() : int
54
    {
55
        if(isset($this->contentIDToken))
56
        {
57
            return (int)$this->contentIDToken->getValue();
0 ignored issues
show
Bug introduced by
The method getValue() 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

57
            return (int)$this->contentIDToken->/** @scrutinizer ignore-call */ getValue();

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...
58
        }
59
60
        return 0;
61
    }
62
63
    private function loadContent() : void
64
    {
65
        $contentID = $this->getContentID();
66
67
        $this->content = Mailcode_Parser_PreParser::getContent($contentID);
68
69
        Mailcode_Parser_PreParser::clearContent($contentID);
70
    }
71
72
    public function getNormalized() : string
73
    {
74
        return (new Mailcode_Commands_Normalizer_ProtectedContent($this))->normalize();
0 ignored issues
show
Bug introduced by
$this of type Mailcode\Mailcode_Traits_Commands_ProtectedContent is incompatible with the type Mailcode\Mailcode_Commands_Command expected by parameter $command of Mailcode\Mailcode_Comman...dContent::__construct(). ( Ignorable by Annotation )

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

74
        return (new Mailcode_Commands_Normalizer_ProtectedContent(/** @scrutinizer ignore-type */ $this))->normalize();
Loading history...
75
    }
76
}
77