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   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 29
c 3
b 1
f 0
dl 0
loc 73
ccs 28
cts 28
cp 1
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A validateParameter() 0 23 4
A addErrorsIfExists() 0 11 3
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