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
03:10
created

Validation::getMessages()   C

Complexity

Conditions 8
Paths 20

Size

Total Lines 46
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 0
Metric Value
dl 0
loc 46
ccs 0
cts 37
cp 0
rs 5.5555
c 0
b 0
f 0
cc 8
eloc 28
nc 20
nop 0
crap 72
1
<?php
2
3
/*
4
 * This file is part of Respect/Validation.
5
 *
6
 * (c) Alexandre Gomes Gaigalas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the "LICENSE.md"
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Respect\Validation;
13
14
use RecursiveIteratorIterator;
15
16
final class Validation
17
{
18
    /**
19
     * @var Result
20
     */
21
    private $result;
22
23
    /**
24
     * @var Factory
25
     */
26
    private $factory;
27
28
    public function __construct(Result $result, Factory $factory)
29
    {
30
        $this->result = $result;
31
        $this->factory = $factory;
32
    }
33
34
    public function isValid(): bool
35
    {
36
        return $this->result->isValid();
37
    }
38
39
    public function getMessages(): array
40
    {
41
        $resultIterator = new ResultIterator($this->result);
42
        $recursiveResultIterator = new RecursiveIteratorIterator(
43
            $resultIterator,
44
            RecursiveIteratorIterator::SELF_FIRST
45
        );
46
47
        $messages = [];
48
        $current = [];
49
50
        /* @var Result $childResult */
51
        $lastDepth = 0;
52
        foreach ($recursiveResultIterator as $key => $childResult) {
53
            $childMessage = $this->factory->message($childResult);
54
55
            $currentDepth = $recursiveResultIterator->getDepth();
56
            if ($currentDepth < $lastDepth) {
57
                if (count($current) === 1) {
58
                    $current = current($current);
59
                }
60
                unset($current);
61
                $current = [];
62
            }
63
64
            if ($childMessage->isIgnorable()
65
                && $recursiveResultIterator->callHasChildren()) {
66
                $messages[$key] = &$current;
67
                continue;
68
            }
69
70
            if ($currentDepth === 0) {
71
                $messages[$key] = $childMessage->__toString();
72
            } else {
73
                $current[$key] = $childMessage->__toString();
74
            }
75
76
            $lastDepth = $currentDepth;
77
        }
78
79
        if (empty($messages)) {
80
            $messages[] = $this->factory->message($this->result)->__toString();
81
        }
82
83
        return $messages;
84
    }
85
}
86