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

Validator::validate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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