Passed
Pull Request — master (#517)
by
unknown
02:51
created

WhenNull::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\EmptyCondition;
6
7
/**
8
 * Empty condition is a callable returning `true` if a value must be considered empty.
9
 *
10
 * With `WhenNull` a rule is considered empty only when the value is `null` or the attribute is missing. With regard
11
 * to validation process, a corresponding rule is skipped only if this condition is met and `WhenNull` is set:
12
 *
13
 * - At a rule level via `$skipOnEmpty` property, but only for rules implementing {@see SkipOnEmptyTrait} / including
14
 * {@see SkipOnEmptyTrait}.
15
 * - At validator level ({@see Validator::$defaultSkipOnEmptyCondition}).
16
 *
17
 * There is no shortcut for this condition, because it's considered less used. Use new instance directly:
18
 * `new WhenNull()`.
19
 */
20
final class WhenNull
21
{
22
    /**
23
     * @param mixed $value The validated value.
24
     * @param bool $isAttributeMissing A flag defining whether the attribute is missing (not used / not passed at all).
25
     *
26
     * @return bool Whether the validated value is considered empty.
27
     */
28
    public function __invoke(mixed $value, bool $isAttributeMissing): bool
29
    {
30
        return $value === null;
31
    }
32
}
33