Passed
Push — master ( 1515ff...7c0b30 )
by Sebastian
04:21
created

getValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 11
rs 10
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Traits_Commands_Validation_Value} trait.
4
 *
5
 * @package Mailcode
6
 * @subpackage Validation
7
 * @see Mailcode_Traits_Commands_Validation_Value
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
/**
15
 * Command validation drop-in: checks for the presence
16
 * of a value type token (string literal, number...). 
17
 * Will accept the first value type token it finds.
18
 *
19
 * @package Mailcode
20
 * @subpackage Validation
21
 * @author Sebastian Mordziol <[email protected]>
22
 *
23
 * @property Mailcode_Parser_Statement_Validator $validator
24
 */
25
trait Mailcode_Traits_Commands_Validation_Value
26
{
27
   /**
28
    * @var Mailcode_Parser_Statement_Tokenizer_ValueInterface|NULL
29
    */
30
    protected $valueToken;
31
    
32
    protected function validateSyntax_value() : void
33
    {
34
        $var = $this->validator->createValue();
35
        
36
        if($var->isValid())
37
        {
38
            $this->valueToken = $var->getToken();
39
        }
40
        else
41
        {
42
            $this->validationResult->makeError(
43
                t('No variable has been specified.'),
44
                Mailcode_Commands_CommonConstants::VALIDATION_VALUE_MISSING
45
            );
46
        }
47
    }
48
    
49
   /**
50
    * Retrieves the variable being compared.
51
    *
52
    * @return string
53
    */
54
    public function getValue() : string
55
    {
56
        if($this->valueToken instanceof Mailcode_Parser_Statement_Tokenizer_ValueInterface)
57
        {
58
            return $this->valueToken->getValue();
59
        }
60
        
61
        throw new Mailcode_Exception(
62
            'No value available',
63
            null,
64
            Mailcode_Commands_CommonConstants::ERROR_NO_VALUE_AVAILABLE
65
        );
66
    }
67
}
68