Completed
Push — master ( 1d4c38...4c420b )
by Mehmet
09:19 queued 52s
created

Model::getSchema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Selami\Entity;
5
6
use Opis\JsonSchema\Schema;
7
use Selami\Entity\Exception\UnexpectedValueException;
8
9
final class Model
10
{
11
    private $schema;
12
13
    public function __construct(string $jsonSchema)
14
    {
15
        $this->schema = Schema::fromJsonString($jsonSchema);
16
    }
17
18
    public function getSchema()  : Schema
19
    {
20
        return $this->schema;
21
    }
22
23
    public static function fromJsonFile(string $filePath) : Model
24
    {
25
        if (!file_exists($filePath)) {
26
            throw new UnexpectedValueException(sprintf('Model definition file (%s) does not exist!', $filePath));
27
        }
28
        return new static(file_get_contents($filePath));
29
    }
30
}
31