Passed
Push — main ( 6bf038...578b82 )
by Aleksandr
03:45 queued 32s
created

Fillable   A

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 146
    public function __construct(array $data = [])
10
    {
11 146
        foreach ($data as $key => $value) {
12 144
            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 144
            $this->{$key} = $value;
16
        }
17
    }
18
19
20 141
    public static function create($data = [])
21
    {
22 141
        \assert(\is_array($data));
23 141
        return new static($data);
24
    }
25
}
26