Completed
Pull Request — master (#108)
by Matt
19:10
created

Not::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 3
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace League\JsonGuard\Constraints\DraftFour;
4
5
use League\JsonGuard\Assert;
6
use League\JsonGuard\Constraint;
7
use League\JsonGuard\Validator;
8
use function League\JsonGuard\error;
9
10
class Not implements Constraint
11
{
12
    const KEYWORD = 'not';
13
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function validate($value, $parameter, Validator $validator)
18
    {
19
        Assert::type($parameter, 'object', self::KEYWORD, $validator->getSchemaPath());
20
21
        $subValidator = $validator->makeSubSchemaValidator($value, $parameter);
22
        if ($subValidator->passes()) {
23
            return error('The data must not match the schema.', $validator);
24
        }
25
        return null;
26
    }
27
}
28