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

Forbidden   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 28
rs 10
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
B passes() 0 15 7
A getSlug() 0 3 1
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