Completed
Push — master ( c762b0...684d44 )
by John
02:56
created

MetaSchemaValidator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php declare(strict_types = 1);
2
/*
3
 * This file is part of the KleijnWeb\ApiDescriptions package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\ApiDescriptions\Description\Document\Definition\Validator;
10
11
use KleijnWeb\ApiDescriptions\Description\Schema;
12
use KleijnWeb\ApiDescriptions\Description\Schema\Validator\SchemaValidator;
13
14
/**
15
 * @author John Kleijn <[email protected]>
16
 */
17
class MetaSchemaValidator
18
{
19
    /**
20
     * @var \stdClass
21
     */
22
    private $schema;
23
24
    /**
25
     * @var SchemaValidator
26
     */
27
    private $validator;
28
29
    /**
30
     * @var Schema\SchemaFactory
31
     */
32
    private $schemaFactory;
33
34
    /**
35
     * MetaSchemaValidator constructor.
36
     *
37
     * @param \stdClass       $schema
38
     * @param SchemaValidator $validator
39
     */
40
    public function __construct(\stdClass $schema, SchemaValidator $validator)
41
    {
42
        $this->schema        = $schema;
43
        $this->validator     = $validator;
44
        $this->schemaFactory = new Schema\SchemaFactory();
45
    }
46
47
    /**
48
     * @param \stdClass $definition
49
     */
50
    public function validate(\stdClass $definition)
51
    {
52
        if (!$this->validator->validate($this->schemaFactory->create($this->schema), $definition)->isValid()) {
53
            throw new \InvalidArgumentException("Description not valid");
54
        }
55
    }
56
}
57