YamlUriRetriever::loadSchema()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.0078

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 14
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.0078
1
<?php
2
namespace ElevenLabs\Api\JsonSchema\Uri;
3
4
use JsonSchema\Uri\UriRetriever;
5
use Symfony\Component\Yaml\Yaml;
6
7
/**
8
 * Load Schema From a YAML file
9
 */
10
class YamlUriRetriever extends UriRetriever
11
{
12
    /**
13
     * @var array|object[]
14
     * @see loadSchema
15
     */
16
    private $schemaCache = array();
17
18 2
    protected function loadSchema($fetchUri)
19
    {
20 2
        if (isset($this->schemaCache[$fetchUri])) {
21
            return $this->schemaCache[$fetchUri];
22
        }
23
24 2
        $contents = $this->getUriRetriever()->retrieve($fetchUri);
25
26 2
        $contents = Yaml::parse($contents);
27 2
        $jsonSchema = json_decode(json_encode($contents));
28
29 2
        $this->schemaCache[$fetchUri] = $jsonSchema;
30
31 2
        return $jsonSchema;
32
    }
33
}
34