Validator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 5 1
A __construct() 0 6 1
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