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   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 4
dl 0
loc 70
ccs 0
cts 46
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A isValid() 0 4 1
C getMessages() 0 46 8
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