MagicTrait::fill()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 9
ccs 0
cts 6
cp 0
crap 12
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Eduardokum\CorreiosPhp\Traits;
3
4
trait MagicTrait
5
{
6
7
    /**
8
     * @param array $params
9
     * @return $this;
10
     */
11
    public function fill(array $params)
12
    {
13
        foreach ($params as $param => $value) {
14
            $param = str_replace(' ', '', ucwords(str_replace('_', ' ', $param)));
15
            if (method_exists($this, 'set' . ucwords($param))) {
16
                $this->{'set' . ucwords($param)}($value);
17
            }
18
        }
19
        return $this;
20
    }
21
22
    /**
23
     * @param array $params
24
     *
25
     * @return self
26
     */
27
    public static function create(array $params)
28
    {
29
        $obj = new self();
30
        return $obj->fill($params);
31
    }
32
}
33