Fillable   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 17
ccs 8
cts 8
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 3
A create() 0 4 1
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