Completed
Pull Request — master (#2)
by Veaceslav
11:06
created

SchemaFactory::create()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
rs 9.4285
cc 2
eloc 6
nc 1
nop 1
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