Passed
Push — master ( 294df8...cd9337 )
by Liaw
12:16 queued 11s
created

ConsistentEntity::setAttributes()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Entities;
4
5
use Entities\Exceptions\UnconsistentEntityException;
6
7
abstract class ConsistentEntity extends Entity
8
{
9 2
    protected function setAttributes(array $attributes): void
10
    {
11 2
        parent::setAttributes($attributes);
12
13 2
        if (! $this->isConsistent()) {
14 1
            throw new UnconsistentEntityException();
15
        }
16 1
    }
17
18 2
    protected function isConsistent(): bool
19
    {
20 2
        foreach (get_object_vars($this) as $key => $value) {
21 2
            if (is_null($this->$key)) {
22 1
                return false;
23
            }
24
        }
25
26 1
        return true;
27
    }
28
}
29