Code

< 40 %
40-60 %
> 60 %
1
<?php
2
3
namespace CfdiUtils\Validate;
4
5
class Assert
6
{
7
    /** @var string */
8
    private $title;
9
10
    /** @var Status */
11
    private $status;
12
13
    /** @var string */
14
    private $explanation;
15
16
    /** @var string */
17
    private $code;
18
19
    /**
20
     * Assert constructor.
21
     * @param string $code
22
     * @param string $title
23
     * @param Status|null $status If null the status will be NONE
24
     * @param string $explanation
25
     */
26 443
    public function __construct(string $code, string $title = '', Status $status = null, string $explanation = '')
27
    {
28 443
        if ('' === $code) {
29 1
            throw new \UnexpectedValueException('Code cannot be an empty string');
30
        }
31 442
        $this->code = $code;
32 442
        $this->title = $title;
33 442
        $this->setStatus($status ?: Status::none());
34 442
        $this->explanation = $explanation;
35
    }
36
37 7
    public function getTitle(): string
38
    {
39 7
        return $this->title;
40
    }
41
42 434
    public function getStatus(): Status
43
    {
44 434
        return $this->status;
45
    }
46
47 35
    public function getExplanation(): string
48
    {
49 35
        return $this->explanation;
50
    }
51
52 437
    public function getCode(): string
53
    {
54 437
        return $this->code;
55
    }
56
57 50
    public function setTitle(string $title)
58
    {
59 50
        $this->title = $title;
60
    }
61
62 442
    public function setStatus(Status $status, string $explanation = null)
63
    {
64 442
        $this->status = $status;
65 442
        if (null !== $explanation) {
66 77
            $this->setExplanation($explanation);
67
        }
68
    }
69
70 207
    public function setExplanation(string $explanation)
71
    {
72 207
        $this->explanation = $explanation;
73
    }
74
75 1
    public function __toString()
76
    {
77 1
        return sprintf('%s: %s - %s', $this->status, $this->code, $this->title);
78
    }
79
}
80