| Conditions | 4 |
| Paths | 4 |
| Total Lines | 19 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 4 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 18 | 75 | public static function fromArray(array $properties = []): static |
|
| 19 | { |
||
| 20 | 75 | $object = new static(); |
|
| 21 | /** @psalm-var mixed $value */ |
||
| 22 | 75 | foreach ($properties as $property => $value) { |
|
| 23 | /** @psalm-var string $property */ |
||
| 24 | 75 | if (property_exists(static::class, $property)) { |
|
| 25 | 75 | $method = SetterMethodName::fromSnakeCasePropertyName($property)->getName(); |
|
| 26 | 75 | if (\is_callable([$object, $method])) { |
|
| 27 | 75 | $object->{$method}($value); |
|
| 28 | |||
| 29 | 73 | continue; |
|
| 30 | } |
||
| 31 | |||
| 32 | 1 | $object->{$property} = $value; |
|
| 33 | } |
||
| 34 | } |
||
| 35 | |||
| 36 | 73 | return $object; |
|
| 37 | } |
||
| 39 |