Passed
Push — main ( 3e8b61...019d3e )
by Степанов
02:00
created

AbstractCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 25
ccs 12
cts 12
cp 1
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A fromArray() 0 19 4
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