MagicTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 27
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 4 1
A fill() 0 9 3
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