| Total Complexity | 5 |
| Total Lines | 47 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | trait FromArray |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @param array $array |
||
| 11 | * |
||
| 12 | * @throws MethodDoesNotExistsException |
||
| 13 | * |
||
| 14 | * @return static |
||
| 15 | */ |
||
| 16 | 16 | public static function fromArray(array $array): self |
|
| 17 | { |
||
| 18 | 16 | $self = new static(); |
|
| 19 | |||
| 20 | 16 | foreach ($array as $property => $value) { |
|
| 21 | 16 | $method = $self->setMethod($property); |
|
| 22 | 13 | $self->$method($value); |
|
| 23 | } |
||
| 24 | |||
| 25 | 13 | return $self; |
|
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @param string $property |
||
| 30 | * |
||
| 31 | * @throws MethodDoesNotExistsException |
||
| 32 | * |
||
| 33 | * @return string |
||
| 34 | */ |
||
| 35 | 16 | private function setMethod(string $property): string |
|
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @param string $string |
||
| 48 | * |
||
| 49 | * @return string |
||
| 50 | */ |
||
| 51 | 16 | private function snakeCaseToCamelCase(string $string): string |
|
| 54 | } |
||
| 55 | } |
||
| 56 |