Passed
Push — master ( 7c0b30...83b5cd )
by Sebastian
02:33
created

getSearchTerms()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Commands_Command_If_Contains} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Commands
7
 * @see Mailcode_Commands_Command_If_Contains
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
/**
15
 * Mailcode command: opening IF statement.
16
 *
17
 * @package Mailcode
18
 * @subpackage Commands
19
 * @author Sebastian Mordziol <[email protected]>
20
 * 
21
 * @property Mailcode_Parser_Statement $params
22
 * @property \AppUtils\OperationResult $validationResult
23
 * @property Mailcode_Parser_Statement_Validator $validator
24
 * @property Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral[] $searchTerms
25
 */
26
trait Mailcode_Traits_Commands_IfContains
27
{
28
    use Mailcode_Traits_Commands_Validation_Variable;
29
    use Mailcode_Traits_Commands_Validation_CaseSensitive;
30
    
31
   /**
32
    * @var Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral[]
33
    */
34
    protected $searchTerms = array();
35
    
36
    protected function getValidations() : array
37
    {
38
        return array(
39
            'variable',
40
            'case_sensitive',
41
            'search_terms'
42
        );
43
    }
44
    
45
    protected function validateSyntax_search_terms() : void
46
    {
47
        $tokens = $this->params->getInfo()->createPruner()
48
        ->limitToStringLiterals()
49
        ->getTokens();
50
        
51
        foreach($tokens as $token)
52
        {
53
            if($token instanceof Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral)
54
            {
55
                $this->searchTerms[] = $token;
56
            }
57
        }
58
        
59
        if(empty($this->searchTerms))
60
        {
61
            $this->validationResult->makeError(
62
                t('No search terms found:').' '.
63
                t('At least one search term has to be specified.'),
64
                Mailcode_Commands_CommonConstants::VALIDATION_SEARCH_TERM_MISSING
65
            );
66
        }
67
    }
68
    
69
   /**
70
    * Retrieves all search terms.
71
    * @return Mailcode_Parser_Statement_Tokenizer_Token_StringLiteral[]
72
    */
73
    public function getSearchTerms() : array
74
    {
75
        return $this->searchTerms;
76
    }
77
}
78