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:50
created

Result::invert()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
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
/**
15
 * Handles validation's results.
16
 *
17
 * @author Henrique Moody <[email protected]>
18
 *
19
 * @since 2.0.0
20
 */
21
final class Result
22
{
23
    /**
24
     * @var bool
25
     */
26
    private $isValid;
27
28
    /**
29
     * @var mixed
30
     */
31
    private $input;
32
33
    /**
34
     * @var Rule
35
     */
36
    private $rule;
37
38
    /**
39
     * @var Rule[]
40
     */
41
    private $children;
42
43
    /**
44
     * @var array
45
     */
46
    private $properties;
47
48
    /**
49
     * Initializes the object.
50
     *
51
     * @param bool   $isValid
52
     * @param mixed  $input
53
     * @param Rule   $rule
54
     * @param array  $properties
55
     * @param Result $children,...
0 ignored issues
show
Documentation introduced by
There is no parameter named $children,.... Did you maybe mean $children?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
56
     */
57 15
    public function __construct(bool $isValid, $input, Rule $rule, array $properties = [], Result ...$children)
58
    {
59 15
        $this->isValid = $isValid;
60 15
        $this->input = $input;
61 15
        $this->rule = $rule;
62 15
        $this->properties = $properties;
63 15
        $this->children = $children;
0 ignored issues
show
Documentation Bug introduced by
It seems like $children of type array<integer,object<Respect\Validation\Result>> is incompatible with the declared type array<integer,object<Respect\Validation\Rule>> of property $children.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
64 15
    }
65
66
    /**
67
     * Returns whether the result is valid or not.
68
     *
69
     * @return bool
70
     */
71 3
    public function isValid(): bool
72
    {
73 3
        return $this->isValid;
74
    }
75
76
    /**
77
     * Returns the input that was used on the validation.
78
     *
79
     * @return mixed
80
     */
81 3
    public function getInput()
82
    {
83 3
        return $this->input;
84
    }
85
86
    /**
87
     * Returns the rule that performed the validation.
88
     *
89
     * @return Rule
90
     */
91 3
    public function getRule(): Rule
92
    {
93 3
        return $this->rule;
94
    }
95
96
    /**
97
     * Returns the children of the result.
98
     *
99
     * @return Result[]
100
     */
101 3
    public function getChildren(): array
102
    {
103 3
        return $this->children;
104
    }
105
106
    /**
107
     * Returns the properties of the result.
108
     *
109
     * @return array
110
     */
111 8
    public function getProperties(): array
112
    {
113 8
        return $this->properties;
114
    }
115
116
    /**
117
     * Creates a new object with the defined properties.
118
     *
119
     * @param array $properties
120
     *
121
     * @return Result
122
     */
123 6
    public function mergeProperties(array $properties): Result
124
    {
125 6
        $result = clone $this;
126 6
        $result->properties = $properties + $this->getProperties();
127
128 6
        return $result;
129
    }
130
131
    /**
132
     * Creates a new object with the inverted validation.
133
     *
134
     * @return Result
135
     */
136 6
    public function invert(): Result
137
    {
138 6
        $result = clone $this;
139 6
        $result->isValid = !$result->isValid;
140
141 6
        return $result;
142
    }
143
}
144