EsiAttributeValidator::validate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
1
<?php
2
3
namespace CrazyGoat\Octophpus\Validator;
4
5
use Nunzion\Expect;
6
7
class EsiAttributeValidator implements ValidatorInterface
8
{
9
    /**
10
     * @var array
11
     */
12
    private $attributes;
13
14
    public function __construct(array $attributes)
15
    {
16
        $this->attributes = $attributes;
17
    }
18
19
    public function validate(): bool
20
    {
21
        Expect::that($this->attributes)->itsArrayElement('SRC')->isString()->isNotEmpty();
22
        Expect::that($this->attributes)->itsArrayElement('TIMEOUT')->isUndefinedOrFloat();
23
        if (isset($this->attributes['TIMEOUT'])) {
24
            Expect::that($this->attributes)->itsArrayElement('TIMEOUT')->isFloat()->isGreaterThan(0);
25
        }
26
27
        return true;
28
    }
29
}