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

Model   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 22
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSchema() 0 4 1
A fromJsonFile() 0 7 2
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