CustomJsonSerializer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 15
c 3
b 0
f 0
dl 0
loc 36
ccs 0
cts 11
cp 0
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A extractObjectData() 0 18 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\SqlParser\Tools;
6
7
use ReflectionClass;
8
use ReflectionException;
9
use Zumba\JsonSerializer\JsonSerializer;
10
11
use function in_array;
12
13
/**
14
 * Used for .out files generation
15
 */
16
class CustomJsonSerializer extends JsonSerializer
17
{
18
    public const SKIP_PROPERTIES = [
19
        'defaultDelimiter',
20
        'clauses',
21
        'statementOptions',
22
    ];
23
24
    /**
25
     * Extract the object data
26
     *
27
     * @param  object          $value
28
     * @param  ReflectionClass $ref
29
     * @param  string[]        $properties
30
     *
31
     * @return array<string,mixed>
32
     */
33
    // phpcs:ignore SlevomatCodingStandard.TypeHints
34
    protected function extractObjectData($value, $ref, $properties): array
35
    {
36
        $data = [];
37
        foreach ($properties as $property) {
38
            if (in_array($property, self::SKIP_PROPERTIES, true)) {
39
                continue;
40
            }
41
42
            try {
43
                $propRef = $ref->getProperty($property);
44
                $propRef->setAccessible(true);
45
                $data[$property] = $propRef->getValue($value);
46
            } catch (ReflectionException) {
47
                $data[$property] = $value->$property;
48
            }
49
        }
50
51
        return $data;
52
    }
53
}
54