Skip to content

Commit b46276a

Browse files
committed
update: strict define methods return type
1 parent 148e1ac commit b46276a

30 files changed

+182
-209
lines changed

src/AbstractValidation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function __construct(
6363
*
6464
* @return AbstractValidation
6565
*/
66-
public static function quick(array $data, string $scene = '', bool $startValidate = false)
66+
public static function quick(array $data, string $scene = '', bool $startValidate = false): AbstractValidation
6767
{
6868
return new static($data, [], [], $scene, $startValidate);
6969
}

src/Filter/FilteringTrait.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ protected function callStringCallback(string $filter, ...$args)
121121
*
122122
* @return callable|null
123123
*/
124-
public function getFilter(string $name)
124+
public function getFilter(string $name): ?callable
125125
{
126126
return $this->_filters[$name] ?? null;
127127
}
@@ -141,9 +141,9 @@ public function addFilter(string $name, callable $filter): self
141141
* @param string $name
142142
* @param callable $filter
143143
*
144-
* @return FilteringTrait
144+
* @return $this
145145
*/
146-
public function setFilter(string $name, callable $filter)
146+
public function setFilter(string $name, callable $filter): self
147147
{
148148
if ($name = trim($name)) {
149149
$this->_filters[$name] = $filter;
@@ -155,7 +155,7 @@ public function setFilter(string $name, callable $filter)
155155
/**
156156
* @param string $name
157157
*/
158-
public function delFilter(string $name)
158+
public function delFilter(string $name): void
159159
{
160160
if (isset($this->_filters[$name])) {
161161
unset($this->_filters[$name]);
@@ -165,7 +165,7 @@ public function delFilter(string $name)
165165
/**
166166
* clear filters
167167
*/
168-
public function clearFilters()
168+
public function clearFilters(): void
169169
{
170170
$this->_filters = [];
171171
}
@@ -181,15 +181,15 @@ public function getFilters(): array
181181
/**
182182
* @param array $filters
183183
*/
184-
public function addFilters(array $filters)
184+
public function addFilters(array $filters): void
185185
{
186186
$this->setFilters($filters);
187187
}
188188

189189
/**
190190
* @param array $filters
191191
*/
192-
public function setFilters(array $filters)
192+
public function setFilters(array $filters): void
193193
{
194194
foreach ($filters as $name => $filter) {
195195
$this->setFilter($name, $filter);

src/Filter/Filters.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ final class Filters
8787
*
8888
* @return bool
8989
*/
90-
public static function boolean($val, $nullAsFalse = false)
90+
public static function boolean($val, $nullAsFalse = false): bool
9191
{
9292
if ($val !== null && !is_scalar($val)) {
9393
return (bool)$val;
@@ -102,7 +102,7 @@ public static function boolean($val, $nullAsFalse = false)
102102
* @see Validators::boolean()
103103
* {@inheritdoc}
104104
*/
105-
public static function bool($val, $nullAsFalse = false)
105+
public static function bool($val, $nullAsFalse = false): bool
106106
{
107107
return self::boolean($val, $nullAsFalse);
108108
}

src/Filter/UserFilters.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class UserFilters
2424
*
2525
* @return null|callable
2626
*/
27-
public static function get(string $name)
27+
public static function get(string $name): ?callable
2828
{
2929
return self::$filters[$name] ?? null;
3030
}
@@ -33,7 +33,7 @@ public static function get(string $name)
3333
* @param string $name
3434
* @param callable $filter
3535
*/
36-
public static function add(string $name, callable $filter)
36+
public static function add(string $name, callable $filter): void
3737
{
3838
if (!isset(self::$filters[$name])) {
3939
self::$filters[$name] = $filter;
@@ -44,7 +44,7 @@ public static function add(string $name, callable $filter)
4444
* @param string $name
4545
* @param callable $filter
4646
*/
47-
public static function set(string $name, callable $filter)
47+
public static function set(string $name, callable $filter): void
4848
{
4949
if ($name) {
5050
self::$filters[$name] = $filter;
@@ -72,7 +72,7 @@ public static function getFilters(): array
7272
/**
7373
* @param array $filters
7474
*/
75-
public static function setFilters(array $filters)
75+
public static function setFilters(array $filters): void
7676
{
7777
foreach ($filters as $name => $filter) {
7878
self::set($name, $filter);
@@ -82,7 +82,7 @@ public static function setFilters(array $filters)
8282
/**
8383
* @param string $name
8484
*/
85-
public static function remove(string $name)
85+
public static function remove(string $name): void
8686
{
8787
if (isset(self::$filters[$name])) {
8888
unset(self::$filters[$name]);
@@ -92,7 +92,7 @@ public static function remove(string $name)
9292
/**
9393
* clear all filters
9494
*/
95-
public static function removeAll()
95+
public static function removeAll(): void
9696
{
9797
self::$filters = [];
9898
}

src/Helper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
*/
4242
class Helper
4343
{
44-
const IS_TRUE = '|yes|on|1|true|';
45-
const IS_FALSE = '|no|off|0|false|';
46-
const IS_BOOL = '|yes|on|1|true|no|off|0|false|';
44+
public const IS_TRUE = '|yes|on|1|true|';
45+
public const IS_FALSE = '|no|off|0|false|';
46+
public const IS_BOOL = '|yes|on|1|true|no|off|0|false|';
4747

4848
/**
4949
* known image mime types
@@ -258,7 +258,7 @@ public static function call($cb, ...$args)
258258
}
259259

260260
if (is_array($cb)) {
261-
list($obj, $mhd) = $cb;
261+
[$obj, $mhd] = $cb;
262262

263263
return is_object($obj) ? $obj->$mhd(...$args) : $obj::$mhd(...$args);
264264
}

src/Traits/ErrorMessageTrait.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ trait ErrorMessageTrait
6060
*/
6161
private $_prettifyName = true;
6262

63-
protected function prepareValidation()
63+
protected function prepareValidation(): void
6464
{
6565
// error message
6666
$this->_messages = array_merge($this->messages(), $this->_messages);
@@ -97,15 +97,6 @@ public function isFail(): bool
9797
return count($this->_errors) > 0;
9898
}
9999

100-
/**
101-
* @return bool
102-
* @deprecated will delete, please use isFail() instead
103-
*/
104-
public function fail(): bool
105-
{
106-
return $this->isFail();
107-
}
108-
109100
/**
110101
* @return bool
111102
*/
@@ -169,7 +160,7 @@ public function inError(string $field): bool
169160
* @param string $field
170161
* @param string $msg
171162
*/
172-
public function addError(string $field, string $msg)
163+
public function addError(string $field, string $msg): void
173164
{
174165
$this->_errors[] = [
175166
'name' => $field,
@@ -201,7 +192,7 @@ public function getErrors(string $field = ''): array
201192
/**
202193
* clear errors
203194
*/
204-
public function clearErrors()
195+
public function clearErrors(): void
205196
{
206197
$this->_errors = [];
207198
}
@@ -270,7 +261,7 @@ public function isStopOnError(): bool
270261
* @param string $key
271262
* @param string|array $message
272263
*/
273-
public function setMessage(string $key, $message)
264+
public function setMessage(string $key, $message): void
274265
{
275266
if ($key && $message) {
276267
$this->_messages[$key] = $message;
@@ -456,7 +447,7 @@ public function isPrettifyName(): bool
456447
/**
457448
* @param bool $prettifyName
458449
*/
459-
public function setPrettifyName(bool $prettifyName = true)
450+
public function setPrettifyName(bool $prettifyName = true): void
460451
{
461452
$this->_prettifyName = $prettifyName;
462453
}

src/Traits/MultipleRulesTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ trait MultipleRulesTrait
4747
* @return Generator
4848
* @throws InvalidArgumentException
4949
*/
50-
protected function collectRules()
50+
protected function collectRules(): ?Generator
5151
{
5252
$scene = $this->scene;
5353

@@ -112,7 +112,7 @@ protected function parseRule(string $rule, array $row): array
112112
return $row;
113113
}
114114

115-
list($name, $args) = Filters::explode($rule, ':', 2);
115+
[$name, $args] = Filters::explode($rule, ':', 2);
116116
$args = trim($args, ', ');
117117
$row[0] = $name;
118118

@@ -128,7 +128,7 @@ protected function parseRule(string $rule, array $row): array
128128
case 'string':
129129
case 'between':
130130
if (strpos($args, ',')) {
131-
list($row['min'], $row['max']) = Filters::explode($args, ',', 2);
131+
[$row['min'], $row['max']] = Filters::explode($args, ',', 2);
132132
} else {
133133
$row['min'] = $args;
134134
}

src/Traits/NameAliasTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static function getAliases(): array
5050
/**
5151
* @param array $aliases
5252
*/
53-
public static function setAliases(array $aliases)
53+
public static function setAliases(array $aliases): void
5454
{
5555
foreach ($aliases as $name => $alias) {
5656
static::$aliases[$name] = $alias;

src/Traits/ScopedValidatorsTrait.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function setValidator(string $name, callable $callback, string $message =
9595
*
9696
* @return null|callable
9797
*/
98-
public function getValidator(string $name)
98+
public function getValidator(string $name): ?callable
9999
{
100100
return $this->_validators[$name] ?? null;
101101
}
@@ -115,7 +115,7 @@ public function hasValidator(string $name): bool
115115
*
116116
* @return $this
117117
*/
118-
public function addValidators(array $validators)
118+
public function addValidators(array $validators): self
119119
{
120120
foreach ($validators as $name => $validator) {
121121
$this->addValidator($name, $validator);
@@ -134,7 +134,7 @@ public function getValidators(): array
134134
/**
135135
* @param string $name
136136
*/
137-
public function delValidator(string $name)
137+
public function delValidator(string $name): void
138138
{
139139
if (isset($this->_validators[$name])) {
140140
unset($this->_validators[$name]);
@@ -144,7 +144,7 @@ public function delValidator(string $name)
144144
/**
145145
* clear validators
146146
*/
147-
public function clearValidators()
147+
public function clearValidators(): void
148148
{
149149
$this->_validators = [];
150150
}
@@ -194,7 +194,7 @@ public function required(string $field, $value = null): bool
194194
* - FALSE check failed
195195
* - NULL skip check the field
196196
*/
197-
public function requiredIf(string $field, $fieldVal, string $anotherField, $values)
197+
public function requiredIf(string $field, $fieldVal, string $anotherField, $values): ?bool
198198
{
199199
if (isset($this->data[$anotherField])) {
200200
$anotherVal = $this->data[$anotherField];
@@ -218,7 +218,7 @@ public function requiredIf(string $field, $fieldVal, string $anotherField, $valu
218218
* @return bool|null
219219
* @see requiredIf()
220220
*/
221-
public function requiredUnless(string $field, $fieldVal, string $anotherField, $values)
221+
public function requiredUnless(string $field, $fieldVal, string $anotherField, $values): ?bool
222222
{
223223
if (isset($this->data[$anotherField])) {
224224
$anotherVal = $this->data[$anotherField];
@@ -241,7 +241,7 @@ public function requiredUnless(string $field, $fieldVal, string $anotherField, $
241241
* @return bool|null
242242
* @see requiredIf()
243243
*/
244-
public function requiredWith(string $field, $fieldVal, $fields)
244+
public function requiredWith(string $field, $fieldVal, $fields): ?bool
245245
{
246246
foreach ((array)$fields as $name) {
247247
if ($this->required($name)) {
@@ -262,7 +262,7 @@ public function requiredWith(string $field, $fieldVal, $fields)
262262
* @return bool|null
263263
* @see requiredIf()
264264
*/
265-
public function requiredWithAll(string $field, $fieldVal, $fields)
265+
public function requiredWithAll(string $field, $fieldVal, $fields): ?bool
266266
{
267267
$allHasValue = true;
268268

@@ -286,7 +286,7 @@ public function requiredWithAll(string $field, $fieldVal, $fields)
286286
* @return bool|null
287287
* @see requiredIf()
288288
*/
289-
public function requiredWithout(string $field, $fieldVal, $fields)
289+
public function requiredWithout(string $field, $fieldVal, $fields): ?bool
290290
{
291291
$allHasValue = true;
292292

@@ -310,7 +310,7 @@ public function requiredWithout(string $field, $fieldVal, $fields)
310310
* @return bool|null
311311
* @see requiredIf()
312312
*/
313-
public function requiredWithoutAll(string $field, $fieldVal, $fields)
313+
public function requiredWithoutAll(string $field, $fieldVal, $fields): ?bool
314314
{
315315
$allNoValue = true;
316316

@@ -446,7 +446,7 @@ public function mimeTypesValidator(string $field, $types): bool
446446
*
447447
* @todo
448448
*/
449-
public function mimesValidator(string $field, $types = null)
449+
public function mimesValidator(string $field, $types = null): void
450450
{
451451
}
452452

@@ -588,7 +588,7 @@ public function inFieldValidator($val, string $anotherField): bool
588588
*
589589
* @todo
590590
*/
591-
public function intervalDayValidator($val, string $compareField, int $expected, string $op = '>=')
591+
public function intervalDayValidator($val, string $compareField, int $expected, string $op = '>='): void
592592
{
593593

594594
}
@@ -677,7 +677,7 @@ public static function isCheckRequired(string $name): bool
677677
*
678678
* @return array|null
679679
*/
680-
public function getUploadedFile(string $field)
680+
public function getUploadedFile(string $field): ?array
681681
{
682682
return $this->uploadedFiles[$field] ?? null;
683683
}

0 commit comments

Comments
 (0)