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

NotEmptyTrait::notEmpty()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 4
nc 2
nop 2
dl 0
loc 8
rs 9.2
c 0
b 0
f 0
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
}