ArrayUpdateableTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 4
c 2
b 1
f 0
dl 0
loc 11
ccs 5
cts 5
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A setFromArray() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace midorikocak\arraytools;
6
7
use function str_replace;
8
use function ucfirst;
9
use function ucwords;
10
11
trait ArrayUpdateableTrait
12
{
13
    /**
14
     * Expects the implemented class to have matching setters with array keys
15
     */
16 1
    public function setFromArray(array $data)
17
    {
18 1
        foreach ($data as $key => $value) {
19 1
            $str = str_replace('_', '', ucwords($key, '_'));
20 1
            $methodName = 'set' . ucfirst($str);
21 1
            $this->$methodName($data[$key]);
22
        }
23 1
    }
24
}
25