Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#678)
by Henrique
02:51
created

Validation::getMessages()   C

Complexity

Conditions 8
Paths 20

Size

Total Lines 46
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 46
c 0
b 0
f 0
rs 5.5555
cc 8
eloc 28
nc 20
nop 0
1
<?php
2
3
namespace Respect\Validation;
4
5
use RecursiveIteratorIterator;
6
7
final class Validation
8
{
9
    /**
10
     * @var Result
11
     */
12
    private $result;
13
14
    /**
15
     * @var Factory
16
     */
17
    private $factory;
18
19
    public function __construct(Result $result, Factory $factory)
20
    {
21
        $this->result = $result;
22
        $this->factory = $factory;
23
    }
24
25
    public function isValid(): bool
26
    {
27
        return $this->result->isValid();
28
    }
29
30
    public function getMessages(): array
31
    {
32
        $resultIterator = new ResultIterator($this->result);
33
        $recursiveResultIterator = new RecursiveIteratorIterator(
34
            $resultIterator,
35
            RecursiveIteratorIterator::SELF_FIRST
36
        );
37
38
        $messages = [];
39
        $current = [];
40
41
        /* @var Result $childResult */
42
        $lastDepth = 0;
43
        foreach ($recursiveResultIterator as $key => $childResult) {
44
            $childMessage = $this->factory->message($childResult);
45
46
            $currentDepth = $recursiveResultIterator->getDepth();
47
            if ($currentDepth < $lastDepth) {
48
                if (count($current) === 1) {
49
                    $current = current($current);
50
                }
51
                unset($current);
52
                $current = [];
53
            }
54
55
            if ($childMessage->isIgnorable()
56
                && $recursiveResultIterator->callHasChildren()) {
57
                $messages[$key] =& $current;
58
                continue;
59
            }
60
61
            if ($currentDepth === 0) {
62
                $messages[$key] = $childMessage->__toString();
63
            } else {
64
                $current[$key] = $childMessage->__toString();
65
            }
66
67
            $lastDepth = $currentDepth;
68
        }
69
70
        if (empty($messages)) {
71
            $messages[] = $this->factory->message($this->result)->__toString();
72
        }
73
74
        return $messages;
75
    }
76
}
77