Completed
Pull Request — master (#430)
by Anton
04:46
created

AbstractRule::getDescription()   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\Proxy\Translator;
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
    abstract public function validate($input): bool;
33
34
    /**
35
     * @inheritdoc
36
     */
37 196
    public function getDescription() : string
38
    {
39 196
        return Translator::translate($this->description);
0 ignored issues
show
Bug introduced by
The call to translate() misses a required argument $...$text.

This check looks for function calls that miss required arguments.

Loading history...
40
    }
41
42
    /**
43
     * @inheritdoc
44
     */
45 2
    public function setDescription(string $description)
46
    {
47 2
        $this->description = $description;
48 2
        return $this;
49
    }
50
51
    /**
52
     * @inheritdoc
53
     */
54 1
    public function __invoke($input): bool
55
    {
56 1
        return $this->validate($input);
57
    }
58
59
    /**
60
     * @inheritdoc
61
     */
62 436
    public function __toString()
63
    {
64 436
        return $this->getDescription();
65
    }
66
}
67