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
Push — master ( e4483b...da1094 )
by Henrique
03:01
created

Validator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
eloc 10
dl 0
loc 56
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A check() 0 10 4
A __callStatic() 0 3 1
A create() 0 3 1
A __call() 0 3 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
declare(strict_types=1);
13
14
namespace Respect\Validation;
15
16
use finfo;
17
use Respect\Validation\Exceptions\ComponentException;
18
use Respect\Validation\Exceptions\ValidationException;
19
use Respect\Validation\Rules\AllOf;
20
use Respect\Validation\Rules\Key;
21
22
/**
23
 * @method static Validator allOf(Validatable ...$rule)
24
 * @method static Validator alnum(string $additionalChars = null)
25
 * @method static Validator alpha(string $additionalChars = null)
26
 * @method static Validator alwaysInvalid()
27
 * @method static Validator alwaysValid()
28
 * @method static Validator anyOf()
29
 * @method static Validator arrayType()
30
 * @method static Validator arrayVal()
31
 * @method static Validator attribute(string $reference, Validatable $validator = null, bool $mandatory = true)
32
 * @method static Validator base()
33
 * @method static Validator base64()
34
 * @method static Validator between($minimum, $maximum)
35
 * @method static Validator bic(string $countryCode)
36
 * @method static Validator boolType()
37
 * @method static Validator boolVal()
38
 * @method static Validator bsn()
39
 * @method static Validator call()
40
 * @method static Validator callableType()
41
 * @method static Validator callback(callable $callback)
42
 * @method static Validator charset(string ...$charset)
43
 * @method static Validator cnh()
44
 * @method static Validator cnpj()
45
 * @method static Validator consonant(string $additionalChars = null)
46
 * @method static Validator contains($containsValue, bool $identical = false)
47
 * @method static Validator countable()
48
 * @method static Validator countryCode(string $set = null)
49
 * @method static Validator currencyCode()
50
 * @method static Validator cpf()
51
 * @method static Validator creditCard(string $brand = null)
52
 * @method static Validator date(string $format = 'Y-m-d')
53
 * @method static Validator dateTime(string $format = null)
54
 * @method static Validator digit(string $additionalChars = null)
55
 * @method static Validator directory()
56
 * @method static Validator domain(bool $tldCheck = true)
57
 * @method static Validator each(Validatable $rule)
58
 * @method static Validator email()
59
 * @method static Validator endsWith($endValue, bool $identical = false)
60
 * @method static Validator equals($compareTo)
61
 * @method static Validator equivalent($compareTo)
62
 * @method static Validator even()
63
 * @method static Validator executable()
64
 * @method static Validator exists()
65
 * @method static Validator extension(string $extension)
66
 * @method static Validator factor(int $dividend)
67
 * @method static Validator falseVal()
68
 * @method static Validator fibonacci()
69
 * @method static Validator file()
70
 * @method static Validator filterVar(int $filter, $options = null)
71
 * @method static Validator finite()
72
 * @method static Validator floatVal()
73
 * @method static Validator floatType()
74
 * @method static Validator graph(string $additionalChars = null)
75
 * @method static Validator greaterThan($compareTo)
76
 * @method static Validator hexRgbColor()
77
 * @method static Validator identical($value)
78
 * @method static Validator identityCard(string $countryCode)
79
 * @method static Validator image(finfo $fileInfo = null)
80
 * @method static Validator imei()
81
 * @method static Validator in($haystack, bool $compareIdentical = false)
82
 * @method static Validator infinite()
83
 * @method static Validator instance(string $instanceName)
84
 * @method static Validator intVal()
85
 * @method static Validator intType()
86
 * @method static Validator ip($ipOptions = null)
87
 * @method static Validator iterableType()
88
 * @method static Validator json()
89
 * @method static Validator key(string $reference, Validatable $referenceValidator = null, bool $mandatory = true)
90
 * @method static Validator keyNested(string $reference, Validatable $referenceValidator = null, bool $mandatory = true)
91
 * @method static Validator keySet(Key ...$rule)
92
 * @method static Validator keyValue(string $comparedKey, string $ruleName, string $baseKey)
93
 * @method static Validator languageCode(string $set)
94
 * @method static Validator leapDate(string $format)
95
 * @method static Validator leapYear()
96
 * @method static Validator length(int $min = null, int $max = null, bool $inclusive = true)
97
 * @method static Validator lowercase()
98
 * @method static Validator lessThan($compareTo)
99
 * @method static Validator luhn()
100
 * @method static Validator macAddress()
101
 * @method static Validator max($compareTo)
102
 * @method static Validator maxAge(int $age, string $format = null)
103
 * @method static Validator mimetype(string $mimetype)
104
 * @method static Validator min($compareTo)
105
 * @method static Validator minAge(int $age, string $format = null)
106
 * @method static Validator multiple(int $multipleOf)
107
 * @method static Validator negative()
108
 * @method static Validator nif()
109
 * @method static Validator no($useLocale = false)
110
 * @method static Validator noneOf(Validatable ...$rule)
111
 * @method static Validator not(Validatable $rule)
112
 * @method static Validator notBlank()
113
 * @method static Validator notEmpty()
114
 * @method static Validator notOptional()
115
 * @method static Validator noWhitespace()
116
 * @method static Validator nullable(Validatable $rule)
117
 * @method static Validator nullType()
118
 * @method static Validator number()
119
 * @method static Validator numericVal()
120
 * @method static Validator objectType()
121
 * @method static Validator odd()
122
 * @method static Validator oneOf(Validatable ...$rule)
123
 * @method static Validator optional(Validatable $rule)
124
 * @method static Validator perfectSquare()
125
 * @method static Validator pesel()
126
 * @method static Validator phone()
127
 * @method static Validator phpLabel()
128
 * @method static Validator pis()
129
 * @method static Validator positive()
130
 * @method static Validator postalCode(string $countryCode)
131
 * @method static Validator primeNumber()
132
 * @method static Validator printable(string $additionalChars = null)
133
 * @method static Validator punct(string $additionalChars = null)
134
 * @method static Validator readable()
135
 * @method static Validator regex(string $regex)
136
 * @method static Validator resourceType()
137
 * @method static Validator roman()
138
 * @method static Validator scalarVal()
139
 * @method static Validator sf(string $name, array $params = null)
140
 * @method static Validator size(string $minSize = null, string $maxSize = null)
141
 * @method static Validator slug()
142
 * @method static Validator space(string $additionalChars = null)
143
 * @method static Validator startsWith($startValue, bool $identical = false)
144
 * @method static Validator stringType()
145
 * @method static Validator stringVal()
146
 * @method static Validator subdivisionCode(string $countryCode)
147
 * @method static Validator subset(array $superset)
148
 * @method static Validator symbolicLink()
149
 * @method static Validator time(string $format = 'H:i:s')
150
 * @method static Validator tld()
151
 * @method static Validator trueVal()
152
 * @method static Validator type(string $type)
153
 * @method static Validator unique()
154
 * @method static Validator uploaded()
155
 * @method static Validator uppercase()
156
 * @method static Validator url()
157
 * @method static Validator uuid()
158
 * @method static Validator vatin(string $countryCode)
159
 * @method static Validator version()
160
 * @method static Validator videoUrl(string $service = null)
161
 * @method static Validator vowel()
162
 * @method static Validator when(Validatable $if, Validatable $then, Validatable $when = null)
163
 * @method static Validator writable()
164
 * @method static Validator xdigit(string $additionalChars = null)
165
 * @method static Validator yes($useLocale = false)
166
 * @method static Validator zend($validator, array $params = null)
167
 */
168
final class Validator extends AllOf
169
{
170
    /**
171
     * {@inheritdoc}
172
     */
173 154
    public function check($input): void
174
    {
175
        try {
176 154
            parent::check($input);
177 129
        } catch (ValidationException $exception) {
178 129
            if (1 == count($this->getRules()) && $this->template) {
179 1
                $exception->updateTemplate($this->template);
180
            }
181
182 129
            throw $exception;
183
        }
184 29
    }
185
186
    /**
187
     * Creates a new Validator instance with a rule that was called on the static method.
188
     *
189
     * @param string $ruleName
190
     * @param array $arguments
191
     *
192
     * @throws ComponentException
193
     *
194
     * @return self
195
     */
196 217
    public static function __callStatic(string $ruleName, array $arguments): self
197
    {
198 217
        return self::create()->__call($ruleName, $arguments);
199
    }
200
201
    /**
202
     * Create a new rule by the name of the method and adds the rule to the chain.
203
     *
204
     * @param string $ruleName
205
     * @param array $arguments
206
     *
207
     * @throws ComponentException
208
     *
209
     * @return self
210
     */
211 218
    public function __call(string $ruleName, array $arguments): self
212
    {
213 218
        return $this->addRule(Factory::getDefaultInstance()->rule($ruleName, $arguments));
214
    }
215
216
    /**
217
     * Create instance validator.
218
     *
219
     * @return Validator
220
     */
221 218
    public static function create(): self
222
    {
223 218
        return new self();
224
    }
225
}
226