Passed
Pull Request — master (#20)
by
unknown
09:30
created

ShortenTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 12
c 1
b 0
f 0
dl 0
loc 28
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setShortenEnabled() 0 7 1
A getShortenToken() 0 6 1
A validateSyntax_shorten() 0 2 1
A isShortenEnabled() 0 5 1
1
<?php
2
/**
3
 * File containing the {@see \Mailcode\Traits\Commands\Validation\ShortenTrait} trait.
4
 *
5
 * @see \Mailcode\Traits\Commands\Validation\ShortenTrait
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\ShortenInterface;
15
use Mailcode\Mailcode_Commands_Keywords;
16
use Mailcode\Mailcode_Parser_Statement_Tokenizer_Token_Keyword;
17
18
/**
19
 * Command validation drop-in: checks for the presence
20
 * of the `shorten:` keyword in the command statement,
21
 * and sets the shorten enabled flag accordingly.
22
 *
23
 * @package Mailcode
24
 * @subpackage Validation
25
 * @author Daniel Storch <[email protected]>
26
 *
27
 * @see ShortenInterface
28
 */
29
trait ShortenTrait
30
{
31
    public function isShortenEnabled() : bool
32
    {
33
        return $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

33
        return $this->/** @scrutinizer ignore-call */ requireParams()
Loading history...
34
            ->getInfo()
35
            ->hasKeyword(Mailcode_Commands_Keywords::TYPE_SHORTEN);
36
    }
37
38
    public function setShortenEnabled(bool $enabled) : self
39
    {
40
        $this->requireParams()
41
            ->getInfo()
42
            ->setKeywordEnabled(Mailcode_Commands_Keywords::TYPE_SHORTEN, $enabled);
43
44
        return $this;
45
    }
46
47
    public function getShortenToken() : ?Mailcode_Parser_Statement_Tokenizer_Token_Keyword
48
    {
49
        return $this->requireParams()
50
            ->getInfo()
51
            ->getKeywordsCollection()
52
            ->getByName(Mailcode_Commands_Keywords::TYPE_SHORTEN);
53
    }
54
55
    protected function validateSyntax_shorten() : void
56
    {
57
    }
58
}