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

IsEmpty::evaluate()   A

Complexity

Conditions 6
Paths 4

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 6
eloc 7
c 2
b 0
f 0
nc 4
nop 2
dl 0
loc 15
rs 9.2222
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