Passed
Push — master ( cee3e6...16d2f0 )
by William
11:48 queued 12s
created

CustomJsonSerializer::extractObjectData()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 11
nc 6
nop 3
dl 0
loc 18
rs 9.9
c 1
b 0
f 0
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
        'ALLOWED_KEYWORDS',
20
        'GROUP_OPTIONS',
21
        'END_OPTIONS',
22
        'KEYWORD_PARSERS',
23
        'STATEMENT_PARSERS',
24
        'KEYWORD_NAME_INDICATORS',
25
        'OPERATOR_NAME_INDICATORS',
26
        'DEFAULT_DELIMITER',
27
        'PARSER_METHODS',
28
        'OPTIONS',
29
        'CLAUSES',
30
        'DB_OPTIONS',
31
        'DELIMITERS',
32
        'JOINS',
33
        'FIELDS_OPTIONS',
34
        'LINES_OPTIONS',
35
        'TRIGGER_OPTIONS',
36
        'FUNC_OPTIONS',
37
        'TABLE_OPTIONS',
38
        'FIELD_OPTIONS',
39
        'DATA_TYPE_OPTIONS',
40
        'REFERENCES_OPTIONS',
41
        'KEY_OPTIONS',
42
        'VIEW_OPTIONS',
43
        'EVENT_OPTIONS',
44
        'USER_OPTIONS',
45
        'asciiMap',
46
    ];
47
48
    /**
49
     * Extract the object data
50
     *
51
     * @param  object          $value
52
     * @param  ReflectionClass $ref
53
     * @param  string[]        $properties
54
     *
55
     * @return array<string,mixed>
56
     */
57
    protected function extractObjectData($value, $ref, $properties)
58
    {
59
        $data = [];
60
        foreach ($properties as $property) {
61
            if (in_array($property, self::SKIP_PROPERTIES, true)) {
62
                continue;
63
            }
64
65
            try {
66
                $propRef = $ref->getProperty($property);
67
                $propRef->setAccessible(true);
68
                $data[$property] = $propRef->getValue($value);
69
            } catch (ReflectionException $e) {
70
                $data[$property] = $value->$property;
71
            }
72
        }
73
74
        return $data;
75
    }
76
}
77