Passed
Push — main ( 34003d...d34036 )
by Breno
02:09
created

IsEmpty   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 18
rs 10
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A evaluate() 0 15 6
1
<?php
2
declare(strict_types=1);
3
4
namespace BrenoRoosevelt\Validation\Rules;
5
6
use Attribute;
7
use BrenoRoosevelt\Validation\AbstractRule;
8
9
#[Attribute(Attribute::TARGET_PROPERTY|Attribute::TARGET_METHOD)]
10
class IsEmpty extends AbstractRule
11
{
12
    protected function evaluate($input, array $context = []): bool
13
    {
14
        if (is_object($input)) {
15
            return false;
16
        }
17
18
        if (is_array($input) && empty($input)) {
19
            return true;
20
        }
21
22
        if (is_string($input) && mb_strlen(trim($input)) === 0) {
23
            return true;
24
        }
25
26
        return false;
27
    }
28
}
29