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

validateSyntax_params_parse()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 12
nc 3
nop 0
dl 0
loc 25
rs 9.8666
c 1
b 0
f 0
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Traits_Commands_Validation_ParseParams} trait.
4
 *
5
 * @package Mailcode
6
 * @subpackage Validation
7
 * @see Mailcode_Traits_Commands_Validation_ParseParams
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
use AppUtils\OperationResult;
15
16
/**
17
 * Command validation drop-in: parses the command's parameters
18
 * string into its constituent parts.
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 $mailcode
27
 * @property Mailcode_Parser_Statement $params
28
 * @property Mailcode_Parser_Statement_Validator $validator
29
 */
30
trait Mailcode_Traits_Commands_Validation_ParseParams
31
{
32
    abstract public function requiresParameters() : bool;
33
34
    protected function validateSyntax_params_parse() : void
35
    {
36
        if(!$this->requiresParameters())
37
        {
38
            return;
39
        }
40
41
        $this->params = $this->mailcode->getParser()->createStatement(
42
            $this->paramsString,
43
            $this->hasFreeformParameters()
0 ignored issues
show
Bug introduced by
It seems like hasFreeformParameters() 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

43
            $this->/** @scrutinizer ignore-call */ 
44
                   hasFreeformParameters()
Loading history...
44
        );
45
46
        if(!$this->params->isValid())
47
        {
48
            $error = $this->params->getValidationResult();
49
50
            $this->validationResult->makeError(
51
                t('Invalid parameters:').' '.$error->getErrorMessage(),
52
                Mailcode_Commands_Command::VALIDATION_INVALID_PARAMS_STATEMENT
53
            );
54
55
            return;
56
        }
57
58
        $this->validator = new Mailcode_Parser_Statement_Validator($this->params);
59
    }
60
}
61