MissingUnless   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 29
ccs 0
cts 9
cp 0
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A check() 0 13 3
A fillParameters() 0 6 1
1
<?php
2
3
/**
4
 * This file is part of Dimtrovich/Validation.
5
 *
6
 * (c) 2023 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Dimtrovich\Validation\Rules;
13
14
use Rakit\Validation\Rule as RakitRule;
15
16
class MissingUnless extends Missing
17
{
18
    /**
19
     * {@inheritDoc}
20
     */
21
    public function fillParameters(array $params): RakitRule
22
    {
23
        $this->params['field']  = array_shift($params);
24
        $this->params['values'] = $params;
25
26
        return $this;
27
    }
28
29
    /**
30
     * {@inheritDoc}
31
     */
32
    public function check($value): bool
33
    {
34
        $this->requireParameters(['field', 'values']);
35
36
        $anotherAttribute = $this->parameter('field');
37
        $definedValues    = $this->parameter('values');
38
        $anotherValue     = $this->getAttribute()->getValue($anotherAttribute);
39
40
        if (! in_array($anotherValue, $definedValues, is_bool($anotherValue) || null === $anotherValue)) {
41
            return parent::check($value);
42
        }
43
44
        return true;
45
    }
46
}
47