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.

ValidationAnnotation::validateParameter()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 14
c 0
b 0
f 0
nc 8
nop 1
dl 0
loc 23
ccs 15
cts 15
cp 1
crap 4
rs 9.7998
1
<?php declare(strict_types = 1);
2
3
namespace Andresmeireles\RespectAnnotation;
4
5
use Andresmeireles\RespectAnnotation\Annotation\RuleValidator;
6
7
/**
8
 * Class ValidationAnnotation
9
 * @Annotation
10
 * @Target("PROPERTY"):
11
 */
12
final class ValidationAnnotation
13
{
14
    /**
15
     * @var array
16
     */
17
    private $rules;
18
19
    /**
20
     * @var array|null
21
     */
22
    private $optionalRules;
23
24
    /**
25
     * @var array|null
26
     */
27
    private $notRules;
28
29
    /**
30
     * @var array
31
     */
32
    private $validationErrors = ['errors' => null, 'allErrors' => null];
33
34 69
    public function __construct(?array $validationParameters)
35
    {
36 69
        $validationParameters = array_change_key_case($validationParameters, CASE_LOWER);
37 69
        $this->rules = $validationParameters['rules'] ?? null;
38 69
        $this->optionalRules = $validationParameters['optrules'] ?? null;
39 69
        $this->notRules = $validationParameters['notrules'] ?? null;
40 69
    }
41
42
    /**
43
     * @param array $parameter
44
     * @return array
45
     */
46 69
    public function validateParameter(array $parameter): array
47
    {
48 69
        $validator = new RuleValidator();
49
50 69
        if ($this->rules !== null) {
51 39
            $validator->useRules($this->rules);
52 39
            $validator->executeDefaultValidationInParameter($parameter);
53 39
            $this->addErrorsIfExists($validator);
54
        }
55
56 69
        if ($this->optionalRules !== null) {
57 18
            $validator->useRules($this->optionalRules);
58 18
            $validator->executeOptionalValidationInParameter($parameter);
59 18
            $this->addErrorsIfExists($validator);
60
        }
61
62 69
        if ($this->notRules !== null) {
63 21
            $validator->useRules($this->notRules);
64 21
            $validator->executeNotValidationInParameter($parameter);
65 21
            $this->addErrorsIfExists($validator);
66
        }
67
68 69
        return $this->validationErrors;
69
    }
70
71
    /**
72
     * @param RuleValidator $validator
73
     */
74 69
    private function addErrorsIfExists(RuleValidator $validator): void
75
    {
76 69
        $error = $validator->getValidationErrors();
77 69
        $allErrors = $validator->getAllValidationErrors();
78
79 69
        if ($error !== null) {
80 45
            $this->validationErrors['errors'] = $error;
81
        }
82
83 69
        if ($allErrors !== null) {
84 45
            $this->validationErrors['allErrors'] = $allErrors;
85
        }
86 69
    }
87
}
88