FromArrayTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 19
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromArray() 0 11 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WebServCo\Framework\Traits;
6
7
trait FromArrayTrait
8
{
9
    /**
10
    * Returns an instance of the current class
11
    *
12
    * @param array<string,mixed> $data
13
    * @return mixed
14
    */
15
    public static function fromArray(array $data = [])
16
    {
17
        $object = new static();
18
        foreach (\get_object_vars($object) as $property => $default) {
19
            if (!\array_key_exists($property, $data)) {
20
                continue;
21
            }
22
23
            $object->{$property} = $data[$property];
24
        }
25
        return $object;
26
    }
27
}
28