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
05:19
created

Result::invert()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 2
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 $child
56
     * @param Result ...$child2
57
     */
58 15
    public function __construct(bool $isValid, $input, Rule $rule, array $properties = [], Result ...$child)
0 ignored issues
show
Unused Code introduced by
The parameter $child is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
59
    {
60 15
        $this->isValid = $isValid;
61 15
        $this->input = $input;
62 15
        $this->rule = $rule;
63 15
        $this->properties = $properties;
64 15
        $this->children = $children;
0 ignored issues
show
Bug introduced by
The variable $children does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

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