Completed
Branch 09branch (1e97b6)
by Anton
02:49
created

NotEmptyTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A notEmpty() 0 8 4
1
<?php
2
/**
3
 * spiral
4
 *
5
 * @author    Wolfy-J
6
 */
7
8
namespace Spiral\Validation\Checkers\Traits;
9
10
/**
11
 * Default not empty check, shared across checkers.
12
 */
13
trait NotEmptyTrait
14
{
15
    /**
16
     * Value should not be empty.
17
     *
18
     * @param mixed $value
19
     * @param bool  $asString Cut spaces and make sure it's not empty when value is string.
20
     *
21
     * @return bool
22
     */
23
    public function notEmpty($value, bool $asString = true): bool
24
    {
25
        if ($asString && is_string($value) && strlen(trim($value)) == 0) {
26
            return false;
27
        }
28
29
        return !empty($value);
30
    }
31
}