Test Failed
Push — main ( 5edb73...d2cb63 )
by Fractal
02:48
created

ObjectHelper::isArrayHasAllPropertiesFromClass()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 4
nop 2
dl 0
loc 17
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
    public static function isArrayHasAllPropertiesFromClass(array $array, string $class): bool
13
    {
14
        try {
15
            $rClass = new \ReflectionClass($class);
16
        } catch (\ReflectionException) {
17
            return false;
18
        }
19
20
        foreach ($rClass->getProperties() as $property) {
21
            $propertyValue = $array[$property->getName()] ?? $array[StringHelper::toSnakeCase($property->getName())] ?? null;
22
23
            if (!$propertyValue) {
24
                return false;
25
            }
26
        }
27
28
        return true;
29
    }
30
}
31