Completed
Push — master ( 5927eb...1e13db )
by
unknown
04:04
created

Properties   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%
Metric Value
dl 0
loc 29
ccs 15
cts 15
cp 1
rs 10
wmc 6
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B validate() 0 23 6
1
<?php
2
3
namespace League\JsonGuard\Constraints;
4
5
use League\JsonGuard\SubSchemaValidatorFactory;
6
7
class Properties implements ContainerInstanceConstraint
8
{
9
    /**
10
     * {@inheritdoc}
11
     */
12 28
    public static function validate($data, $parameter, SubSchemaValidatorFactory $validatorFactory, $pointer = null)
13
    {
14 28
        if (!is_object($data)) {
15 8
            return null;
16
        }
17
18
        // Iterate through the properties and create a new
19
        // validator for that property's schema and data.
20
        // merge the errors.
21 28
        $errors = [];
22 28
        foreach ($parameter as $property => $schema) {
23 28
            if (is_object($data) && property_exists($data, $property)) {
24 28
                $propertyData    = $data->$property;
25 28
                $propertyPointer = $pointer . '/' . $property;
26 28
                $validator       = $validatorFactory->makeSubSchemaValidator($propertyData, $schema, $propertyPointer);
27 28
                if ($validator->fails()) {
28 20
                    $errors = array_merge($errors, $validator->errors());
29 20
                }
30 26
            }
31 26
        }
32
33 26
        return $errors;
34
    }
35
}
36