Completed
Push — master ( 1fd225...0ced52 )
by Markus
11s queued 10s
created

Validator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 7
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 5 1
A __construct() 0 6 1
1
<?php
2
3
namespace Jellyfish\JsonSchemaOpis;
4
5
use Jellyfish\JsonSchema\ValidatorInterface;
6
use Opis\JsonSchema\ISchema as OpisSchemaInterface;
7
use Opis\JsonSchema\IValidator as OpisValidatorInterface;
8
9
class Validator implements ValidatorInterface
10
{
11
    /**
12
     * @var \Opis\JsonSchema\IValidator
13
     */
14
    protected $opisValidator;
15
16
    /**
17
     * @var \Opis\JsonSchema\ISchema
18
     */
19
    protected $opisSchema;
20
21
    /**
22
     * @param \Opis\JsonSchema\IValidator $opisValidator
23
     * @param \Opis\JsonSchema\ISchema $opisSchema
24
     */
25
    public function __construct(
26
        OpisValidatorInterface $opisValidator,
27
        OpisSchemaInterface $opisSchema
28
    ) {
29
        $this->opisValidator = $opisValidator;
30
        $this->opisSchema = $opisSchema;
31
    }
32
33
    /**
34
     * @param string $json
35
     *
36
     * @return bool
37
     */
38
    public function validate(string $json): bool
39
    {
40
        $result = $this->opisValidator->schemaValidation(\json_decode($json), $this->opisSchema);
41
42
        return $result->isValid();
43
    }
44
}
45