SendJob::execute()   B
last analyzed

Complexity

Conditions 2
Paths 3

Size

Total Lines 37
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 37
rs 8.8571
cc 2
eloc 26
nc 3
nop 0
1
<?php
2
3
/**
4
 * Mailer Queue Component (http://mateuszsitek.com/projects/mailer-component-queue)
5
 *
6
 * @copyright Copyright (c) 2017 DIGITAL WOLVES LTD (http://digitalwolves.ltd) All rights reserved.
7
 * @license   http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
8
 */
9
10
namespace Aist\Mailer\Component\Queue\Job;
11
12
use Psr\Log\LoggerInterface;
13
use SlmQueue\Job\AbstractJob;
14
use Zend\Mail\Transport\TransportInterface;
15
16
/**
17
 * Class SendJob
18
 */
19
class SendJob extends AbstractJob
20
{
21
    /**
22
     * @var TransportInterface
23
     */
24
    private $mailer;
25
26
    /**
27
     * @var LoggerInterface
28
     */
29
    private $logger;
30
31
    /**
32
     * SendJob constructor.
33
     *
34
     * @param TransportInterface $mailer
35
     * @param LoggerInterface $logger
36
     */
37
    public function __construct(TransportInterface $mailer, LoggerInterface $logger)
38
    {
39
        $this->mailer = $mailer;
40
        $this->logger = $logger;
41
    }
42
43
    /** @inheritdoc */
44
    public function execute()
45
    {
46
        $payload = $this->getContent();
47
48
        try {
49
            $this->mailer->send($payload['message']);
0 ignored issues
show
Documentation introduced by
$payload['message'] is of type string, but the function expects a object<Zend\Mail\Message>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
50
51
            $this->logger->info(
52
                self::class,
53
                [
54
                    'email' => $payload['email'],
55
                    'subject' => $payload['subject'],
56
                ]
57
            );
58
            echo 'Subject <info>' .
59
                $payload['subject'] .
60
                '</info> email <info>' .
61
                $payload['email'] .
62
                '</info>' .
63
                PHP_EOL;
64
        } catch (\RuntimeException $e) {
65
            $this->logger->error(
66
                self::class,
67
                [
68
                    'email' => $payload['email'],
69
                    'subject' => $payload['subject'],
70
                    'error' => $e->getMessage(),
71
                ]
72
            );
73
            echo '<error>' . $e->getMessage() . '</error> Subject <info>' .
74
                $payload['subject'] .
75
                '</info> email <info>' .
76
                $payload['email'] .
77
                '</info>' .
78
                PHP_EOL;
79
        }
80
    }
81
}
82