Passed
Push — main ( a5f538...a74a35 )
by Fractal
03:00
created

ObjectHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 19
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A isArrayHasAllPropertiesFromClass() 0 17 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FRZB\Component\RequestMapper\Helper;
6
7
/**
8
 * @internal
9
 */
10
final class ObjectHelper
11
{
12 9
    public static function isArrayHasAllPropertiesFromClass(array $array, string $class): bool
13
    {
14
        try {
15 9
            $rClass = new \ReflectionClass($class);
16 1
        } catch (\ReflectionException) {
17 1
            return false;
18
        }
19
20 8
        foreach ($rClass->getProperties() as $property) {
21 8
            $propertyValue = $array[$property->getName()] ?? $array[StringHelper::toSnakeCase($property->getName())] ?? null;
22
23 8
            if (!$propertyValue) {
24 2
                return false;
25
            }
26
        }
27
28 6
        return true;
29
    }
30
}
31