DataTransferObjectTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
c 1
b 0
f 0
dl 0
loc 16
ccs 6
cts 6
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
1
<?php
2
3
//----------------------------------------------------------------------
4
//
5
//  Copyright (C) 2017-2020 Artem Rodygin
6
//
7
//  You should have received a copy of the MIT License along with
8
//  this file. If not, see <http://opensource.org/licenses/MIT>.
9
//
10
//----------------------------------------------------------------------
11
12
namespace Webinarium;
13
14
/**
15
 * Trait to initialize Data Transfer Objects right on creation.
16
 */
17
trait DataTransferObjectTrait
18
{
19
    /**
20
     * Initializes object properties with values from provided array.
21
     *
22
     * @param array $values Initial values.
23
     */
24 2
    public function __construct(?array $values = null)
25
    {
26 2
        $data = $values ?? [];
27
28 2
        $properties = array_keys(get_class_vars(static::class));
29
30 2
        foreach ($properties as $property) {
31 2
            if (array_key_exists($property, $data)) {
32 1
                $this->{$property} = $data[$property];
33
            }
34
        }
35 2
    }
36
}
37