Passed
Push — master ( d04c5a...d84490 )
by Mathias
24:28 queued 14:22
created

MailJob::fromMailSpec()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
/**
4
 * YAWIK
5
 *
6
 * @see       https://github.com/cross-solution/YAWIK for the canonical source repository
7
 * @copyright https://github.com/cross-solution/YAWIK/blob/master/COPYRIGHT
8
 * @license   https://github.com/cross-solution/YAWIK/blob/master/LICENSE
9
 */
10
11
declare(strict_types=1);
12
13
namespace Core\Queue\Job;
14
15
use Laminas\Mail\Message;
16
17
/**
18
 * TODO: description
19
 *
20
 * @author Mathias Gelhausen
21
 * TODO: write tests
22
 */
23
class MailJob extends MongoJob implements MailSenderInterface
24
{
25
26
    private $mail;
27
28
    public static function create($payload = null)
29
    {
30
        if ($payload instanceof Message) {
31
            return static::fromMessage($payload);
32
        }
33
34
        return parent::create($payload);
35
    }
36
37
    public static function fromMessage(Message $mail)
38
    {
39
        $payload = $mail->toString();
40
41
        return parent::create($payload);
42
    }
43
44
    public static function fromMailSpec(string $mailServiceName, $options = null)
45
    {
46
        return parent::create([$mailServiceName, $options]);
47
    }
48
49
    public function execute()
50
    {
51
        $mail = $this->getContent();
52
53
        if (is_string($mail)) {
54
            $mail = Message::fromString($mail);
55
        }
56
57
        $this->mail = $mail;
58
    }
59
60
    public function getMail()
61
    {
62
        return $this->mail;
63
    }
64
}
65