Completed
Branch master (a1bb4f)
by Veaceslav
16:31 queued 03:03
created

SchemaFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 31
wmc 3
lcom 1
cbo 4
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 10 2
1
<?php
2
/**
3
 * This file is part of Rebilly.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @see http://rebilly.com
9
 */
10
11
namespace Rebilly\OpenAPI;
12
13
use JsonSchema\RefResolver;
14
use JsonSchema\Uri\UriResolver;
15
use JsonSchema\Uri\UriRetriever;
16
17
/**
18
 * Schema representation factory.
19
 */
20
final class SchemaFactory
21
{
22
    /**
23
     * @var RefResolver
24
     */
25
    private $resolver;
26
27
    /**
28
     * Constructor.
29
     */
30
    public function __construct()
31
    {
32
        $this->resolver = new RefResolver(new UriRetriever(), new UriResolver());
33
    }
34
35
    /**
36
     * @param string $uri
37
     *
38
     * @return Schema
39
     */
40
    public function create($uri)
41
    {
42
        return new Schema(
43
            $this->resolver->resolve(
44
                strpos('//', $uri) === false
45
                    ? "file://{$uri}"
46
                    : $uri
47
            )
48
        );
49
    }
50
}
51