Completed
Push — master ( e2d746...b1dbfd )
by Sebastian
02:51
created

Str::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 0
cts 5
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Linna Filter
5
 *
6
 * @author Sebastian Rapetti <[email protected]>
7
 * @copyright (c) 2018, 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
/**
15
 * Check if provided value is a string.
16
 *
17
 */
18
class Str extends AbstractString implements RuleSanitizeInterface
19
{
20
    /**
21
     * @var array Rule properties
22
     */
23
    public static $config = [
24
        'class' => 'Str1ng',
25
        'full_class' => __CLASS__,
26
        'alias' => ['string', 'str', 's'],
27
        'args_count' => 0,
28
        'args_type' => [],
29
        'has_validate' => true,
30
        'has_sanitize' => true
31
    ];
32
33
    /**
34
     * @var string Error message
35
     */
36
    private $message = '';
37
38
    /**
39
     * Validate.
40
     *
41
     * @param mixed $received
42
     *
43
     * @return bool
44
     */
45
    public function validate($received): bool
46
    {
47
        if (!is_string($received)) {
48
            $this->message = "Received value is not a string";
49
            return true;
50
        }
51
52
        return false;
53
    }
54
55
    /**
56
     * Return error message.
57
     *
58
     * @return string Error message
59
     */
60
    public function getMessage(): string
61
    {
62
        return $this->message;
63
    }
64
}
65