SchemaBuilder   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
c 1
b 0
f 0
dl 0
loc 43
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setSchemasEndpointUrl() 0 3 1
A __construct() 0 3 1
A get() 0 9 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