Forbidden::passes()   B
last analyzed

Complexity

Conditions 7
Paths 4

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 7
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 15
rs 8.8333
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Validation\Rules;
6
7
use Countable;
8
use Opulence\Validation\Rules\IRule;
9
10
/**
11
 * Defines the required rule
12
 */
13
class Forbidden implements IRule
14
{
15
    /**
16
     * @inheritdoc
17
     */
18
    public function getSlug(): string
19
    {
20
        return 'forbidden';
21
    }
22
23
    /**
24
     * @inheritdoc
25
     */
26
    public function passes($value, array $allValues = []): bool
27
    {
28
        if ($value === null) {
29
            return true;
30
        }
31
32
        if (is_string($value) && $value === '') {
33
            return true;
34
        }
35
36
        if ((is_array($value) || $value instanceof Countable) && count($value) === 0) {
37
            return true;
38
        }
39
40
        return false;
41
    }
42
}
43