Completed
Push — master ( 03348d...edfc47 )
by Michał
08:06
created

Mail::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php namespace nyx\notify\transports;
2
3
// External dependencies
4
use nyx\utils;
5
6
// Internal dependencies
7
use nyx\notify\interfaces;
8
9
/**
10
 * Mail Transport
11
 *
12
 * @package     Nyx\Notify
13
 * @version     0.1.0
14
 * @author      Michal Chojnacki <[email protected]>
15
 * @copyright   2012-2017 Nyx Dev Team
16
 * @link        https://github.com/unyx/nyx
17
 */
18
class Mail implements interfaces\Transport
19
{
20
    /**
21
     * @var mail\interfaces\Mailer  The Mailer in use for sending out Messages.
22
     */
23
    protected $mailer;
24
25
    /**
26
     * Creates a new Mail Transport instance.
27
     *
28
     * @param   mail\interfaces\Mailer  $mailer The Mailer to use for sending out Messages.
29
     */
30
    public function __construct(mail\interfaces\Mailer $mailer)
31
    {
32
        $this->mailer = $mailer;
33
    }
34
35
    /**
36
     * {@inheritDoc}
37
     */
38
    public function send(interfaces\Notifiable $notifiable, interfaces\Notification $notification)
39
    {
40
        /* @var mail\interfaces\Mailable $notification */
41
        if (!$this->supports($notification)) {
0 ignored issues
show
Documentation introduced by
$notification is of type object<nyx\notify\transp...il\interfaces\Mailable>, but the function expects a object<nyx\notify\interfaces\Notification>.

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...
42
            throw new \InvalidArgumentException('The given Notification is not supported (did you forget to implement the Mailable Interface?).');
43
        }
44
45
        if (false === $notifiable->routeNotification('mail', $message = $notification->toMail($notifiable))) {
46
            return;
47
        }
48
49
        // The Notification might have built a subject during the toMail() call, but that's optional.
50
        // If no subject is available, we are going to use the humanized name of the Notification's class.
51
        if (empty($message->getSubject())) {
52
            $message->setSubject(utils\str\Cases::title(utils\str\Cases::delimit(class_basename($notification), ' ')));
53
        }
54
55
        // And finally - just send the message.
56
        $this->mailer->send($message);
57
    }
58
59
    /**
60
     * {@inheritDoc}
61
     */
62
    public function supports(interfaces\Notification $notification) : bool
63
    {
64
        return ($notification instanceof mail\interfaces\Mailable);
65
    }
66
}
67