Completed
Push — master ( e7a96f...060ab8 )
by Matt
02:33
created

Required::validate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 13

Duplication

Lines 20
Ratio 100 %

Code Coverage

Tests 13
CRAP Score 3.0032

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
nc 3
nop 3
dl 20
loc 20
ccs 13
cts 14
cp 0.9286
crap 3.0032
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace League\JsonGuard\Constraints;
4
5
use League\JsonGuard\ErrorCode;
6
use League\JsonGuard\ValidationError;
7
8 View Code Duplication
class Required implements PropertyConstraint
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13 6
    public static function validate($data, $parameter, $pointer = null)
14
    {
15 6
        if (!is_object($data)) {
16
            return null;
17
        }
18
19 6
        $actualProperties = array_keys(get_object_vars($data));
20 6
        $missing          = array_diff($parameter, $actualProperties);
21 6
        if (count($missing)) {
22 4
            return new ValidationError(
23 4
                'Required properties missing.',
24 4
                ErrorCode::MISSING_REQUIRED,
25 4
                $data,
26 4
                $pointer,
27 4
                ['required' => $parameter]
28 4
            );
29
        }
30
31 6
        return null;
32
    }
33
}
34