Completed
Push — master ( 6f2bb4...6400d0 )
by Anton
11s
created

AbstractRule::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Bluz Framework Component
4
 *
5
 * @copyright Bluz PHP Team
6
 * @link      https://github.com/bluzphp/framework
7
 */
8
9
declare(strict_types=1);
10
11
namespace Bluz\Validator\Rule;
12
13
use Bluz\Validator\Exception\ValidatorException;
14
15
/**
16
 * Abstract validation rule
17
 *
18
 * @package  Bluz\Validator\Rule
19
 * @author   Anton Shevchuk
20
 */
21
abstract class AbstractRule implements RuleInterface
22
{
23
    /**
24
     * Message for error output
25
     * @var string
26
     */
27
    protected $description = 'is invalid';
28
29
    /**
30
     * @inheritdoc
31
     */
32 7
    public function assert($input) : void
33
    {
34 7
        if (!$this->validate($input)) {
35 7
            throw new ValidatorException($this->description);
36
        }
37
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42 14
    public function __invoke($input) : bool
43
    {
44 14
        return $this->validate($input);
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50 440
    public function __toString() : string
51
    {
52 440
        return $this->getDescription();
53
    }
54
55
    /**
56
     * @inheritdoc
57
     */
58 197
    public function getDescription() : string
59
    {
60 197
        return __($this->description);
61
    }
62
63
    /**
64
     * @inheritdoc
65
     */
66 4
    public function setDescription(string $description) : RuleInterface
67
    {
68 4
        $this->description = $description;
69 4
        return $this;
70
    }
71
}
72