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

ObjectHelper::isArrayHasAllPropertiesFromClass()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 4
nop 2
dl 0
loc 17
ccs 9
cts 9
cp 1
crap 4
rs 9.9666
c 0
b 0
f 0
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