SymfonySchema   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 14
dl 0
loc 35
ccs 0
cts 14
cp 0
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 10 2
A PHPobjectHandler() 0 11 3
1
<?php
2
3
namespace Dallgoot\Yaml\Tag;
4
5
use Dallgoot\Yaml\NodeList;
6
use Dallgoot\Yaml\Nodes\Scalar;
7
8
/**
9
 *
10
 * @author  Stéphane Rebai <[email protected]>
11
 * @license Apache 2.0
12
 * @link    https://github.com/dallgoot/yaml
13
 */
14
class SymfonySchema implements SchemaInterface
15
{
16
    const SCHEMA_URI = 'tag:symfony.com,2019:';
17
    const BUILDING_NAMESPACE = "\\Symfony\\Component";
18
19
    /**
20
     *
21
     * Specific Handler for Symfony custom tag : 'php/object'
22
     *
23
     *
24
     * @throws \Exception if unserialize fails OR if its a NodeList (no support of multiple values for this tag)
25
     */
26
    public final static function PHPobjectHandler(object $node): object
27
    {
28
        if ($node instanceof Scalar) {
29
            $phpObject = unserialize($node->raw);
30
            // NOTE : we assume this is only used for Object types (if a boolean false is serialized this will FAIL)
31
            if (is_bool($phpObject)) {
32
                throw new \Exception("value for tag 'php/object' could NOT be unserialized");
33
            }
34
            return $phpObject;
35
        }
36
        throw new \Exception("tag 'php/object' value must NOT be a list");
37
    }
38
39
    public function __call($name, $arguments)
40
    {
41
        //TODO : handle 'php/object'
42
        if(in_array($name, ['php/object'])) {
43
            return match($name) {
44
                'php/object' => self::PHPobjectHandler($arguments),
45
                default => null,
46
            };
47
        }
48
        throw new \Exception("no handler for tag '$name' in " . self::class, 1);
49
    }
50
}
51