Validator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 2
c 1
b 0
f 1
dl 0
loc 6
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jellyfish\JsonSchemaOpis;
6
7
use Jellyfish\JsonSchema\ValidatorInterface;
8
use Opis\JsonSchema\ISchema as OpisSchemaInterface;
9
use Opis\JsonSchema\IValidator as OpisValidatorInterface;
10
11
class Validator implements ValidatorInterface
12
{
13
    /**
14
     * @var \Opis\JsonSchema\IValidator
15
     */
16
    protected $opisValidator;
17
18
    /**
19
     * @var \Opis\JsonSchema\ISchema
20
     */
21
    protected $opisSchema;
22
23
    /**
24
     * @param \Opis\JsonSchema\IValidator $opisValidator
25
     * @param \Opis\JsonSchema\ISchema $opisSchema
26
     */
27
    public function __construct(
28
        OpisValidatorInterface $opisValidator,
29
        OpisSchemaInterface $opisSchema
30
    ) {
31
        $this->opisValidator = $opisValidator;
32
        $this->opisSchema = $opisSchema;
33
    }
34
35
    /**
36
     * @param string $json
37
     *
38
     * @return bool
39
     */
40
    public function validate(string $json): bool
41
    {
42
        $result = $this->opisValidator->schemaValidation(\json_decode($json), $this->opisSchema);
43
44
        return $result->isValid();
45
    }
46
}
47