EsiAttributeValidator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 23
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A validate() 0 10 2
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
}