Completed
Push — master ( e29bde...b161c3 )
by ARCANEDEV
61:50 queued 53:50
created

Rule::withMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 6
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arcanedev\Support\Validation;
6
7
use Illuminate\Contracts\Validation\Rule as RuleContract;
8
9
/**
10
 * Class     Rule
11
 *
12
 * @author   ARCANEDEV <[email protected]>
13
 */
14
abstract class Rule implements RuleContract
15
{
16
    /* -----------------------------------------------------------------
17
     |  Properties
18
     | -----------------------------------------------------------------
19
     */
20
21
    /**
22
     * The message that should be used when validation fails.
23
     *
24
     * @var string|array
25
     */
26
    protected $message;
27
28
    /* -----------------------------------------------------------------
29
     |  Getters & Setters
30
     | -----------------------------------------------------------------
31
     */
32
33
    /**
34
     * Set the message that should be used when the rule fails.
35
     *
36
     * @param  string|array  $message
37
     *
38
     * @return $this
39
     */
40
    public function withMessage($message)
41
    {
42
        $this->message = $message;
43
44
        return $this;
45
    }
46
47
    /**
48
     * Get the validation error message.
49
     *
50
     * @return string|array
51
     */
52
    public function message()
53
    {
54
        return $this->message;
55
    }
56
57
    /* -----------------------------------------------------------------
58
     |  Other Methods
59
     | -----------------------------------------------------------------
60
     */
61
62
    /**
63
     * Fail if the validation rule.
64
     *
65
     * @param  string|array  $message
66
     *
67
     * @return bool
68
     */
69
    protected function fail($message): bool
70
    {
71
        $this->withMessage($message);
72
73
        return false;
74
    }
75
}
76