getFirstError()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 13
rs 10
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Variables_Collection} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Variables
7
 * @see Mailcode_Variables_Collection
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
use AppUtils\OperationResult;
15
16
/**
17
 * Handler for all variable-related tasks.
18
 *
19
 * @package Mailcode
20
 * @subpackage Variables
21
 * @author Sebastian Mordziol <[email protected]>
22
 */
23
class Mailcode_Variables_Collection_Invalid extends Mailcode_Variables_Collection
24
{
25
    public const ERROR_NO_FIRST_ERROR_AVAILABLE = 101701;
26
27
    public function add(Mailcode_Variables_Variable $variable) : Mailcode_Variables_Collection
28
    {
29
        if($variable->isValid())
30
        {
31
            return $this;
32
        }
33
        
34
        return parent::add($variable);
35
    }
36
    
37
    public function getFirstError() : OperationResult
38
    {
39
        $first = $this->getFirst();
40
41
        if($first)
42
        {
43
            return $first->getValidationResult();
44
        }
45
46
        throw new Mailcode_Exception(
47
            'Cannot get first error, no errors present.',
48
            '',
49
            self::ERROR_NO_FIRST_ERROR_AVAILABLE
50
        );
51
    }
52
}
53