Passed
Push — master ( c607f7...8242ff )
by Peter
02:25
created

Forbidden::passes()   B

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
namespace AbterPhp\Framework\Validation\Rules;
4
5
use Countable;
6
use Opulence\Validation\Rules\IRule;
7
8
/**
9
 * Defines the required rule
10
 */
11
class Forbidden implements IRule
12
{
13
    /**
14
     * @inheritdoc
15
     */
16
    public function getSlug(): string
17
    {
18
        return 'forbidden';
19
    }
20
21
    /**
22
     * @inheritdoc
23
     */
24
    public function passes($value, array $allValues = []): bool
25
    {
26
        if ($value === null) {
27
            return true;
28
        }
29
30
        if (is_string($value) && $value === '') {
31
            return true;
32
        }
33
34
        if ((is_array($value) || $value instanceof Countable) && count($value) === 0) {
35
            return true;
36
        }
37
38
        return false;
39
    }
40
}
41