MailerTrait::getMailer()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Webino™ (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino for the canonical source repository
6
 * @copyright   Copyright (c) 2015-2017 Webino, s.r.o. (http://webino.sk)
7
 * @author      Peter Bačinský <[email protected]>
8
 * @license     BSD-3-Clause
9
 */
10
11
namespace WebinoAppLib\Application\Traits;
12
13
use WebinoAppLib\Application;
14
use WebinoMailLib\MailerInterface;
15
16
/**
17
 * Trait Mailer
18
 */
19
trait MailerTrait
20
{
21
    /**
22
     * @var MailerInterface
23
     */
24
    private $mailer;
25
26
    /**
27
     * Set optional service from services into application
28
     *
29
     * @param string $service Service name
30
     */
31
    abstract protected function optionalService($service);
32
33
    /**
34
     * @return MailerInterface
35
     */
36
    public function getMailer()
37
    {
38
        if (null === $this->mailer) {
39
            $this->optionalService(Application::MAILER);
40
        }
41
        return $this->mailer;
42
    }
43
44
    /**
45
     * @param MailerInterface $mailer
46
     */
47
    protected function setMailer(MailerInterface $mailer)
48
    {
49
        $this->mailer = $mailer;
50
    }
51
52
    /**
53
     * @return MailerInterface
54
     */
55
    public function mail()
56
    {
57
        return $this->getMailer();
58
    }
59
}
60