AbstractCountConstraint   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 21
c 0
b 0
f 0
wmc 3
lcom 0
cbo 3
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 15 3
1
<?php
2
3
/*
4
 * This file is part of the JVal package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace JVal\Constraint;
11
12
use JVal\Constraint;
13
use JVal\Context;
14
use JVal\Exception\Constraint\InvalidTypeException;
15
use JVal\Exception\Constraint\LessThanZeroException;
16
use JVal\Types;
17
use JVal\Walker;
18
use stdClass;
19
20
/**
21
 * Base class for constraints based on a specific number of elements.
22
 */
23
abstract class AbstractCountConstraint implements Constraint
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28 86
    public function normalize(stdClass $schema, Context $context, Walker $walker)
29
    {
30 86
        $keyword = $this->keywords()[0];
31 86
        $context->enterNode($keyword);
32
33 86
        if (!is_int($schema->{$keyword})) {
34 6
            throw new InvalidTypeException($context, Types::TYPE_INTEGER);
35
        }
36
37 80
        if ($schema->{$keyword} < 0) {
38 6
            throw new LessThanZeroException($context);
39
        }
40
41 74
        $context->leaveNode();
42 74
    }
43
}
44