Test Setup Failed
Push — master ( e4f8c2...f9e497 )
by Sebastian
03:34
created

Mailcode_Traits_Commands_Validation_ParamKeywords   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 24
rs 10
c 1
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateSyntax_params_keywords() 0 20 3
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Traits_Commands_Validation_ParamKeywords} trait.
4
 *
5
 * @package Mailcode
6
 * @subpackage Validation
7
 * @see Mailcode_Traits_Commands_Validation_ParamKeywords
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
use AppUtils\OperationResult;
15
16
/**
17
 * Command validation drop-in: parses any keywords present in
18
 * the command parameters, and validates them.
19
 *
20
 * @package Mailcode
21
 * @subpackage Validation
22
 * @author Sebastian Mordziol <[email protected]>
23
 *
24
 * @property OperationResult $validationResult
25
 * @property string $paramsString
26
 * @property Mailcode_Commands_LogicKeywords $logicKeywords
27
 */
28
trait Mailcode_Traits_Commands_Validation_ParamKeywords
29
{
30
    abstract public function supportsLogicKeywords() : bool;
31
32
    protected function validateSyntax_params_keywords() : void
33
    {
34
        if(!$this->supportsLogicKeywords())
35
        {
36
            return;
37
        }
38
39
        $this->logicKeywords = new Mailcode_Commands_LogicKeywords($this, $this->paramsString);
40
41
        if(!$this->logicKeywords->isValid())
42
        {
43
            $this->validationResult->makeError(
44
                t('Invalid parameters:').' '.$this->logicKeywords->getErrorMessage(),
45
                $this->logicKeywords->getCode()
46
            );
47
48
            return;
49
        }
50
51
        $this->paramsString = $this->logicKeywords->getMainParamsString();
52
    }
53
}
54