Passed
Push — main ( 33432d...c8bc71 )
by Breno
01:35
created

IsEmpty::evaluate()   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
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_array($input) && empty($input)) {
15
            return true;
16
        }
17
18
        if (is_iterable($input) && iterator_count($input) === 0) {
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