SchemaBuilder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the tmilos/scim-schema package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Tmilos\ScimSchema\Builder;
13
14
use Tmilos\ScimSchema\Model\Schema;
15
16
abstract class SchemaBuilder
17
{
18
    protected static $schemas = [];
19
20
    /** @var string */
21
    private $schemasEndpointUrl;
22
23
    /**
24
     * @param string $schemasEndpointUrl
25
     */
26
    public function __construct($schemasEndpointUrl)
27
    {
28
        $this->setSchemasEndpointUrl($schemasEndpointUrl);
29
    }
30
31
    /**
32
     * @param string $schemasEndpointUrl
33
     */
34
    public function setSchemasEndpointUrl($schemasEndpointUrl)
35
    {
36
        $this->schemasEndpointUrl = rtrim($schemasEndpointUrl, '/').'/';
37
    }
38
39
    /**
40
     * @param string $schemaId
41
     *
42
     * @return \Tmilos\ScimSchema\Model\v1\Schema|\Tmilos\ScimSchema\Model\v2\Schema|Schema
43
     */
44
    public function get($schemaId)
45
    {
46
        $class = $this->getSchemaClass();
47
        $data = static::$schemas[$schemaId];
48
        /** @var Schema $schema */
49
        $schema = call_user_func([$class, 'deserializeObject'], $data);
50
        $schema->getMeta()->setLocation($this->schemasEndpointUrl.$schemaId);
51
52
        return $schema;
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    abstract protected function getSchemaClass();
59
}
60