Fillable::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DalliSDK\Traits;
6
7
trait Fillable
8
{
9 191
    public function __construct(array $data = [])
10
    {
11 191
        foreach ($data as $key => $value) {
12 188
            if (!\property_exists($this, $key)) {
13 1
                throw new \InvalidArgumentException(\sprintf('The class "%s" does not have the property "%s"', static::class, $key));
14
            }
15 188
            $this->{$key} = $value;
16
        }
17
    }
18
19
20 185
    public static function create($data = [])
21
    {
22 185
        \assert(\is_array($data));
23 185
        return new static($data);
24
    }
25
}
26