Pattern   A
last analyzed

Coupling/Cohesion

Components 0
Dependencies 2

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 14 3
1
<?php
2
3
namespace League\JsonGuard\Constraint\DraftFour;
4
5
use League\JsonGuard;
6
use League\JsonGuard\Assert;
7
use League\JsonGuard\ConstraintInterface;
8
use League\JsonGuard\Validator;
9
use function League\JsonGuard\error;
10
11
final class Pattern implements ConstraintInterface
12
{
13
    const KEYWORD = 'pattern';
14
15
    /**
16
     * {@inheritdoc}
17
     */
18 4
    public function validate($value, $parameter, Validator $validator)
19
    {
20 4
        Assert::type($parameter, 'string', self::KEYWORD, $validator->getSchemaPath());
21
22 2
        if (!is_string($value)) {
23 2
            return null;
24
        }
25
26 2
        if (preg_match(JsonGuard\delimit_pattern($parameter), $value) === 1) {
27 2
            return null;
28
        }
29
30 2
        return error('The string must match the pattern {parameter}.', $validator);
31
    }
32
}
33