Completed
Push — develop ( f3c189...e92436 )
by Alejandro
08:55
created

MailResult::getMessage()   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
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
namespace AcMailer\Result;
3
4
use Exception;
5
6
/**
7
 * Object returned by send method in MailService
8
 * @see \AcMailer\Service\MailServiceInterface
9
 * @author Alejandro Celaya Alastrué
10
 * @link http://www.alejandrocelaya.com
11
 */
12
class MailResult implements ResultInterface
13
{
14
    const DEFAULT_MESSAGE = 'Success!!';
15
    
16
    /**
17
     * @var boolean
18
     */
19
    private $valid;
20
    /**
21
     * @var string
22
     */
23
    private $message;
24
    /**
25
     * @var Exception
26
     */
27
    private $exception;
28
    
29 17
    public function __construct($valid = true, $message = self::DEFAULT_MESSAGE, $exception = null)
30
    {
31 17
        $this->valid        = (bool) $valid;
32 17
        $this->message      = $message;
33 17
        $this->exception    = $exception;
34 17
    }
35
36
    /**
37
     * Returns error message when an error occurs
38
     * @return string
39
     */
40 5
    public function getMessage()
41
    {
42 5
        return $this->message;
43
    }
44
45
    /**
46
     * Tells if the MailService that produced this result was properly sent
47
     * @return bool
48
     */
49 11
    public function isValid()
50
    {
51 11
        return $this->valid;
52
    }
53
54
    /**
55
     * Tells if this Result has an exception. Usually only non-valid result should wrap an exception
56
     * @return bool
57
     */
58 3
    public function hasException()
59
    {
60 3
        return $this->exception instanceof Exception;
61
    }
62
63
    /**
64
     * Returns the exception wraped by this Result
65
     * @return \Exception
66
     */
67 3
    public function getException()
68
    {
69 3
        return $this->exception;
70
    }
71
}
72