Completed
Push — master ( 6a6c7b...f57853 )
by Sebastian
03:30
created

Required::test()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 4
nc 2
nop 0
dl 0
loc 9
ccs 0
cts 7
cp 0
crap 20
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Linna Filter
5
 *
6
 * @author Sebastian Rapetti <[email protected]>
7
 * @copyright (c) 2017, Sebastian Rapetti
8
 * @license http://opensource.org/licenses/MIT MIT License
9
 */
10
declare(strict_types = 1);
11
12
namespace Linna\Filter\Rules;
13
14
use \Linna\Filter\RuleInterface;
15
16
/**
17
 * Check required.
18
 */
19
class Required implements RuleInterface
20
{
21
    /**
22
     * @var mixed Received value.
23
     */
24
    private $received;
25
    
26
    /**
27
     * @var bool Expected value, not used.
28
     */
29
    private $expected;
30
31
    /**
32
     * Class constructor.
33
     *
34
     * @param mixed $received
35
     * @param bool $expected
36
     */
37
    public function __construct($received, $expected)
38
    {
39
        $this->received = $received;
40
        $this->expected = $expected;
41
    }
42
43
    /**
44
     * Test.
45
     *
46
     * @return bool
47
     */
48
    public function test(): bool
49
    {
50
        $data = $this->received;
51
        
52
        if (strlen($data) === 0 || $data === '' || $data === null) {
53
            return true;
54
        }
55
56
        return false;
57
    }
58
}
59