Passed
Push — master ( 724f49...5f1981 )
by Smoren
02:38
created

ContainerRule::hasIndex()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Smoren\Validator\Rules;
6
7
use Smoren\Validator\Factories\Checks\ContainerCheckFactory;
8
use Smoren\Validator\Interfaces\MixedRuleInterface;
9
use Smoren\Validator\Interfaces\ContainerRuleInterface;
10
use Smoren\Validator\Interfaces\IntegerRuleInterface;
11
12
class ContainerRule extends MixedRule implements ContainerRuleInterface
13
{
14
    /**
15
     * ContainerRule constructor.
16
     */
17 61
    public function __construct(string $name)
18
    {
19 61
        parent::__construct($name);
20 61
        $this->check(ContainerCheckFactory::getNumericCheck(), true);
21
    }
22
23
    /**
24
     * {@inheritDoc}
25
     *
26
     * @return static
27
     */
28 9
    public function array(bool $stopOnViolation = true): self
29
    {
30 9
        return $this->check(ContainerCheckFactory::getArrayCheck(), $stopOnViolation);
31
    }
32
33
    /**
34
     * {@inheritDoc}
35
     *
36
     * @return static
37
     */
38 2
    public function indexedArray(bool $stopOnViolation = true): self
39
    {
40 2
        return $this->check(ContainerCheckFactory::getIndexedArrayCheck(), $stopOnViolation);
41
    }
42
43
    /**
44
     * {@inheritDoc}
45
     *
46
     * @return static
47
     */
48 1
    public function associativeArray(bool $stopOnViolation = true): self
49
    {
50 1
        return $this->check(ContainerCheckFactory::getAssociativeArrayCheck(), $stopOnViolation);
51
    }
52
53
    /**
54
     * {@inheritDoc}
55
     *
56
     * @return static
57
     */
58 2
    public function arrayAccessible(bool $stopOnViolation = true): self
59
    {
60 2
        return $this->check(ContainerCheckFactory::getArrayAccessibleCheck(), $stopOnViolation);
61
    }
62
63
    /**
64
     * {@inheritDoc}
65
     *
66
     * @return static
67
     */
68 2
    public function iterable(bool $stopOnViolation = true): self
69
    {
70 2
        return $this->check(ContainerCheckFactory::getIterableCheck(), $stopOnViolation);
71
    }
72
73
    /**
74
     * {@inheritDoc}
75
     *
76
     * @return static
77
     */
78 2
    public function countable(bool $stopOnViolation = true): self
79
    {
80 2
        return $this->check(ContainerCheckFactory::getCountableCheck(), $stopOnViolation);
81
    }
82
83
    /**
84
     * {@inheritDoc}
85
     *
86
     * @return static
87
     */
88 2
    public function object(bool $stopOnViolation = true): self
89
    {
90 2
        return $this->check(ContainerCheckFactory::getObjectCheck(), $stopOnViolation);
91
    }
92
93
    /**
94
     * {@inheritDoc}
95
     *
96
     * @return static
97
     */
98 3
    public function stdObject(bool $stopOnViolation = true): self
99
    {
100 3
        return $this->check(ContainerCheckFactory::getStdObjectCheck(), $stopOnViolation);
101
    }
102
103
    /**
104
     * {@inheritDoc}
105
     *
106
     * @return static
107
     */
108 3
    public function instanceOf(string $class, bool $stopOnViolation = true): self
109
    {
110 3
        return $this->check(ContainerCheckFactory::getInstanceOfCheck($class), $stopOnViolation);
111
    }
112
113
    /**
114
     * {@inheritDoc}
115
     *
116
     * @return static
117
     */
118 2
    public function empty(): self
119
    {
120 2
        return $this->check(ContainerCheckFactory::getEmptyCheck());
121
    }
122
123
    /**
124
     * {@inheritDoc}
125
     *
126
     * @return static
127
     */
128 2
    public function notEmpty(): self
129
    {
130 2
        return $this->check(ContainerCheckFactory::getNotEmptyCheck());
131
    }
132
133
    /**
134
     * {@inheritDoc}
135
     *
136
     * @return static
137
     */
138 9
    public function lengthIs(IntegerRuleInterface $rule): self
139
    {
140 9
        return $this->check(ContainerCheckFactory::getLengthIsCheck($rule));
141
    }
142
143
    /**
144
     * {@inheritDoc}
145
     *
146
     * @return static
147
     */
148 21
    public function hasAttribute(string $name, ?MixedRuleInterface $rule = null): self
149
    {
150 21
        if ($rule === null) {
151 2
            return $this->check(ContainerCheckFactory::getHasAttributeCheck($name));
152
        }
153
154 19
        return $this->check(ContainerCheckFactory::getAttributeIsCheck($name, $rule));
155
    }
156
157
    /**
158
     * {@inheritDoc}
159
     *
160
     * @return static
161
     */
162 2
    public function hasOptionalAttribute(string $name, MixedRuleInterface $rule): self
163
    {
164 2
        return $this->check(ContainerCheckFactory::getHasOptionalAttributeCheck($name, $rule));
165
    }
166
167
    /**
168
     * {@inheritDoc}
169
     *
170
     * @return static
171
     */
172 5
    public function hasIndex(int $index, ?MixedRuleInterface $rule = null): self
173
    {
174 5
        if ($rule === null) {
175 2
            return $this->check(ContainerCheckFactory::getHasIndexCheck($index));
176
        }
177
178 3
        return $this->check(ContainerCheckFactory::getValueByIndexCheck($index, $rule));
179
    }
180
181
    /**
182
     * {@inheritDoc}
183
     *
184
     * @return static
185
     */
186 5
    public function allKeysAre(MixedRuleInterface $rule): self
187
    {
188 5
        return $this->check(ContainerCheckFactory::getAllKeysAreCheck($rule));
189
    }
190
191
    /**
192
     * {@inheritDoc}
193
     *
194
     * @return static
195
     */
196 11
    public function allValuesAre(MixedRuleInterface $rule): self
197
    {
198 11
        return $this->check(ContainerCheckFactory::getAllValuesAreCheck($rule));
199
    }
200
}
201