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
04:41
created

Result::getChildren()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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 Respect\Validation\Exceptions\ComponentException;
15
use Respect\Validation\Rules\RuleInterface;
16
17
/**
18
 * Class to handle validation.
19
 *
20
 * @author Henrique Moody <[email protected]>
21
 */
22
final class Result implements ResultInterface
23
{
24
    /**
25
     * @var bool
26
     */
27
    private $isValid;
28
29
    /**
30
     * @var mixed
31
     */
32
    private $input;
33
34
    /**
35
     * @var RuleInterface
36
     */
37
    private $rule;
38
39
    /**
40
     * @var RuleInterface[]
41
     */
42
    private $children;
43
44
    /**
45
     * @var array
46
     */
47
    private $properties;
48
49
    /**
50
     * @param bool            $isValid
51
     * @param mixed           $input
52
     * @param RuleInterface   $rule
53
     * @param array           $properties
54
     * @param RuleInterface[] $children
55
     */
56 11
    public function __construct($isValid, $input, RuleInterface $rule, array $properties = [], array $children = [])
57
    {
58 11
        $this->checkChildrenInstance($children);
0 ignored issues
show
Documentation introduced by
$children is of type array<integer,object<Res...n\Rules\RuleInterface>>, but the function expects a array<integer,object<Res...ation\ResultInterface>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
59
60 10
        $this->isValid = $isValid;
61 10
        $this->input = $input;
62 10
        $this->rule = $rule;
63 10
        $this->properties = $properties;
64 10
        $this->children = $children;
65 10
    }
66
67
    /**
68
     * @param ResultInterface[] $children
69
     */
70 11
    private function checkChildrenInstance(array $children)
71
    {
72 11
        foreach ($children as $child) {
73 3
            if ($child instanceof ResultInterface) {
74 3
                continue;
75
            }
76
77 1
            throw new ComponentException('Every child of Result must implement ResultInterface');
78 10
        }
79 10
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84 8
    public function isValid()
85
    {
86 8
        return $this->isValid;
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92 8
    public function getInput()
93
    {
94 8
        return $this->input;
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100 8
    public function getRule()
101
    {
102 8
        return $this->rule;
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108 8
    public function getChildren()
109
    {
110 8
        return $this->children;
111
    }
112
113
    /**
114
     * {@inheritdoc}
115
     */
116 8
    public function getProperties()
117
    {
118 8
        return $this->properties;
119
    }
120
121
    /**
122
     * {@inheritdoc}
123
     */
124 7
    public function with($isValid, array $properties = [])
125
    {
126 7
        return new self(
127 7
            $isValid,
128 7
            $this->getInput(),
129 7
            $this->getRule(),
130 7
            $properties + $this->getProperties(),
131 7
            $this->getChildren()
132 7
        );
133
    }
134
}
135