Message   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A throws() 0 4 1
A valid() 0 3 1
A __construct() 0 5 1
1
<?php
2
/**
3
 * Valid message
4
 * User: moyo
5
 * Date: 2018/6/5
6
 * Time: 11:02 AM
7
 */
8
9
namespace Carno\Validator\Valid;
10
11
use Throwable;
12
use UnexpectedValueException;
13
14
class Message
15
{
16
    /**
17
     * @var string
18
     */
19
    private $tips = null;
20
21
    /**
22
     * @var string
23
     */
24
    private $exception = null;
25
26
    /**
27
     * @var int
28
     */
29
    private $code = null;
30
31
    /**
32
     * Message constructor.
33
     * @param string $tips
34
     * @param string $exception
35
     * @param int $code
36
     */
37
    public function __construct(string $tips = '', string $exception = null, int $code = null)
38
    {
39
        $this->tips = $tips;
40
        $this->exception = $exception;
41
        $this->code = $code;
42
    }
43
44
    /**
45
     * @return bool
46
     */
47
    public function valid() : bool
48
    {
49
        return ! empty($this->tips);
50
    }
51
52
    /**
53
     * @throws Throwable
54
     */
55
    public function throws() : void
56
    {
57
        $exception = $this->exception ?? UnexpectedValueException::class;
58
        throw new $exception($this->tips, $this->code ?? 0);
59
    }
60
}
61