GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#65)
by Ha
04:16
created

Schema::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 2
eloc 3
nc 2
nop 2
crap 2
1
<?php declare (strict_types=1);
2
3
namespace OpenStack\Common\JsonSchema;
4
5
use JsonSchema\Validator;
6
7
class Schema
8
{
9
    /** @var object */
10
    private $body;
11
12 4
    /** @var Validator */
13
    private $validator;
14 4
15 4
    public function __construct($body, Validator $validator = null)
16 4
    {
17
        $this->body = (object) $body;
18 1
        $this->validator = $validator ?: new Validator();
19
    }
20 1
21
    public function getPropertyPaths(): array
22 1
    {
23 1
        $paths = [];
24 1
25
        foreach ($this->body->properties as $propertyName => $property) {
26 1
            $paths[] = sprintf("/%s", $propertyName);
27
        }
28
29 2
        return $paths;
30
    }
31 2
32
    public function normalizeObject($subject, array $aliases): \stdClass
33 2
    {
34 2
        $out = new \stdClass;
35 2
36 2
        foreach ($this->body->properties as $propertyName => $property) {
37 2
            $name = isset($aliases[$propertyName]) ? $aliases[$propertyName] : $propertyName;
38 2
            if (isset($property->readOnly) && $property->readOnly === true) {
39 2
                continue;
40 1
            } elseif (property_exists($subject, $name)) {
41 1
                $out->$propertyName = $subject->$name;
42 2
            } elseif (property_exists($subject, $propertyName)) {
43
                $out->$propertyName = $subject->$propertyName;
44 2
            }
45
        }
46
47 2
        return $out;
48
    }
49 2
50 2
    public function validate($data)
51
    {
52 2
        $this->validator->check($data, $this->body);
53
    }
54 2
55
    public function isValid(): bool
56
    {
57 3
        return $this->validator->isValid();
58
    }
59 3
60
    public function getErrors(): array
61
    {
62 2
        return $this->validator->getErrors();
63
    }
64 2
65
    public function getErrorString(): string
66 2
    {
67 2
        $msg = "Provided values do not validate. Errors:\n";
68 2
69
        foreach ($this->getErrors() as $error) {
70 2
            $msg .= sprintf("[%s] %s\n", $error['property'], $error['message']);
71
        }
72
73
        return $msg;
74
    }
75
}
76