AbstractCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Atlance\HttpDbalFilter\Dto;
6
7
use Atlance\HttpDbalFilter\Utils\SetterMethodName;
8
9
/**
10
 * @psalm-suppress MixedArgumentTypeCoercion
11
 */
12
abstract class AbstractCommand
13
{
14 75
    final public function __construct()
15
    {
16 75
    }
17
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
    }
38
}
39