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

Str   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 45
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 8 2
A getMessage() 0 3 1
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