| Total Complexity | 7 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 9 | class ApiResource |
||
| 10 | { |
||
| 11 | public array $attributes = []; |
||
| 12 | |||
| 13 | protected ?OhDear $ohDear; |
||
| 14 | |||
| 15 | public function __construct(array $attributes, OhDear $ohDear = null) |
||
| 16 | { |
||
| 17 | $this->attributes = $attributes; |
||
| 18 | |||
| 19 | $this->ohDear = $ohDear; |
||
| 20 | |||
| 21 | $this->fill(); |
||
| 22 | } |
||
| 23 | |||
| 24 | protected function fill(): void |
||
| 25 | { |
||
| 26 | foreach ($this->attributes as $key => $value) { |
||
| 27 | $key = $this->camelCase($key); |
||
| 28 | |||
| 29 | $this->{$key} = $value; |
||
| 30 | } |
||
| 31 | } |
||
| 32 | |||
| 33 | protected function camelCase(string $key): string |
||
| 34 | { |
||
| 35 | $parts = explode('_', $key); |
||
| 36 | |||
| 37 | foreach ($parts as $i => $part) { |
||
| 38 | if ($i !== 0) { |
||
| 39 | $parts[$i] = ucfirst($part); |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | return str_replace(' ', '', implode(' ', $parts)); |
||
| 44 | } |
||
| 45 | |||
| 46 | public function __sleep() |
||
| 55 | } |
||
| 56 | } |
||
| 57 |