MagicTrait::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
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