Passed
Push — master ( e25032...62cd3f )
by Alexander
03:44 queued 01:09
created

WhenMissing   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 11
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\EmptyCriteria;
6
7
/**
8
 * Empty criteria is a callable returning `true` if a value must be considered empty.
9
 *
10
 * With `WhenMissing` a rule is considered empty only when the value is missing. With regard to validation process, a
11
 * corresponding rule is skipped only if this condition is met and `WhenMissing` 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::$defaultSkipOnEmptyCriteria}).
16
 *
17
 * There is no shortcut for this criteria, because it's considered less used. Use new instance directly:
18
 * `new WhenMissing()`.
19
 */
20
final class WhenMissing
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 $isAttributeMissing;
31
    }
32
}
33