MailResult   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 67
c 0
b 0
f 0
rs 10
ccs 13
cts 13
cp 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A hasException() 0 4 1
A getException() 0 4 1
A __construct() 0 6 1
A isValid() 0 4 1
A getEmail() 0 4 1
A isCancelled() 0 4 2
1
<?php
2
declare(strict_types=1);
3
4
namespace AcMailer\Result;
5
6
use AcMailer\Model\Email;
7
8
/**
9
 * Object returned by send method in MailService
10
 * @see \AcMailer\Service\MailServiceInterface
11
 * @author Alejandro Celaya Alastrué
12
 * @link http://www.alejandrocelaya.com
13
 */
14
class MailResult implements ResultInterface
15
{
16
    /**
17
     * @var bool
18
     */
19
    private $valid;
20
    /**
21
     * @var Email
22
     */
23
    private $email;
24
    /**
25
     * @var \Throwable
26
     */
27
    private $exception;
28
29 18
    public function __construct(Email $email, bool $valid = true, \Throwable $exception = null)
30
    {
31 18
        $this->email = $email;
32 18
        $this->valid = $valid;
33 18
        $this->exception = $exception;
34 18
    }
35
36
    /**
37
     * Returns the email that was tried to be sent
38
     * @return Email
39
     */
40 5
    public function getEmail(): Email
41
    {
42 5
        return $this->email;
43
    }
44
45
    /**
46
     * Tells if the MailService that produced this result was properly sent
47
     * @return bool
48
     */
49 11
    public function isValid(): bool
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(): bool
59
    {
60 3
        return $this->exception !== null;
61
    }
62
63
    /**
64
     * Returns the exception wrapped by this Result if any, or null otherwise
65
     * @return \Throwable|null
66
     */
67 3
    public function getException()
68
    {
69 3
        return $this->exception;
70
    }
71
72
    /**
73
     * Tells if the email sending was cancelled, usually by a preSend listener
74
     * @return bool
75
     */
76
    public function isCancelled(): bool
77
    {
78
        return ! $this->isValid() && ! $this->hasException();
79
    }
80
}
81