Completed
Push — master ( 38deb0...7544ac )
by Anton
11s
created

AbstractRule   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 46
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
validate() 0 1 ?
A getDescription() 0 4 1
A setDescription() 0 5 1
A __invoke() 0 4 1
A __toString() 0 4 1
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
/**
14
 * Abstract validation rule
15
 *
16
 * @package  Bluz\Validator\Rule
17
 * @author   Anton Shevchuk
18
 */
19
abstract class AbstractRule implements RuleInterface
20
{
21
    /**
22
     * Message for error output
23
     * @var string
24
     */
25
    protected $description = 'is invalid';
26
27
    /**
28
     * @inheritdoc
29
     */
30
    abstract public function validate($input): bool;
31
32
    /**
33
     * @inheritdoc
34
     */
35 196
    public function getDescription() : string
36
    {
37 196
        return __($this->description);
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43 2
    public function setDescription(string $description)
44
    {
45 2
        $this->description = $description;
46 2
        return $this;
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52 1
    public function __invoke($input): bool
53
    {
54 1
        return $this->validate($input);
55
    }
56
57
    /**
58
     * @inheritdoc
59
     */
60 438
    public function __toString()
61
    {
62 438
        return $this->getDescription();
63
    }
64
}
65