Passed
Push — master ( 16f676...c127b0 )
by Radu
01:55
created

FromArrayTrait::fromArray()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 3
nc 3
nop 1
1
<?php
2
namespace WebServCo\Framework\Traits;
3
4
trait FromArrayTrait
5
{
6
    /**
7
    * Returns an instance of the current class
8
    */
9
    public static function fromArray($data)
10
    {
11
        $object = new static();
12
        foreach (get_object_vars($object) as $property => $default) {
13
            if (array_key_exists($property, $data)) {
14
                $object->{$property} = $data[$property];
15
            }
16
        }
17
        return $object;
18
    }
19
}
20