Completed
Push — master ( 38a4e8...c04e1d )
by Vladimir
11s
created

AbstractResource::camelCase()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AcquiroPay\Paymarket\Resources;
6
7
class AbstractResource
8
{
9
    /** @var array */
10
    public $attributes = [];
11
12
    /**
13
     * @param  array $attributes
14
     */
15
    public function __construct(array $attributes)
16
    {
17
        $this->attributes = $attributes;
18
19
        $this->fill($this->attributes);
20
    }
21
22
    protected function fill(array $attributes): void
23
    {
24
        foreach ($attributes as $key => $value) {
25
            $key = $this->camelCase((string) $key);
26
27
            $this->{$key} = $value;
28
        }
29
    }
30
31
    protected function camelCase(string $key): string
32
    {
33
        $parts = explode('_', $key);
34
35
        foreach ($parts as $i => $part) {
36
            if ($i !== 0) {
37
                $parts[$i] = ucfirst($part);
38
            }
39
        }
40
41
        return str_replace(' ', '', implode(' ', $parts));
42
    }
43
}
44