Client::getAvailableTransports()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of Jitamin.
5
 *
6
 * Copyright (C) Jitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Jitamin\Foundation\Mail;
13
14
use Jitamin\Bus\Job\EmailJob;
15
use Jitamin\Foundation\Base;
16
use Pimple\Container;
17
18
/**
19
 * Mail Client.
20
 */
21
class Client extends Base
22
{
23
    /**
24
     * Mail transport instances.
25
     *
26
     * @var \Pimple\Container
27
     */
28
    private $transports;
29
30
    /**
31
     * Constructor.
32
     *
33
     * @param \Pimple\Container $container
34
     */
35
    public function __construct(Container $container)
36
    {
37
        parent::__construct($container);
38
        $this->transports = new Container();
39
    }
40
41
    /**
42
     * Send a HTML email.
43
     *
44
     * @param string $email
45
     * @param string $name
46
     * @param string $subject
47
     * @param string $html
48
     *
49
     * @return Client
50
     */
51
    public function send($email, $name, $subject, $html)
52
    {
53
        if (!empty($email)) {
54
            $this->queueManager->push(EmailJob::getInstance($this->container)
0 ignored issues
show
Documentation introduced by
The property queueManager does not exist on object<Jitamin\Foundation\Mail\Client>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
55
                ->withParams($email, $name, $subject, $html, $this->getAuthor())
56
            );
57
        }
58
59
        return $this;
60
    }
61
62
    /**
63
     * Get email author.
64
     *
65
     * @return string
66
     */
67
    public function getAuthor()
68
    {
69
        $author = 'Jitamin';
70
71
        if ($this->userSession->isLogged()) {
0 ignored issues
show
Documentation introduced by
The property userSession does not exist on object<Jitamin\Foundation\Mail\Client>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
72
            $author = l('%s via Jitamin', $this->helper->user->getFullname());
0 ignored issues
show
Documentation introduced by
The property helper does not exist on object<Jitamin\Foundation\Mail\Client>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
73
        }
74
75
        return $author;
76
    }
77
78
    /**
79
     * Get mail transport instance.
80
     *
81
     * @param string $transport
82
     *
83
     * @return ClientInterface
84
     */
85
    public function getTransport($transport)
86
    {
87
        return $this->transports[$transport];
88
    }
89
90
    /**
91
     * Add a new mail transport.
92
     *
93
     * @param string $transport
94
     * @param string $class
95
     *
96
     * @return Client
97
     */
98
    public function setTransport($transport, $class)
99
    {
100
        $container = $this->container;
101
102
        $this->transports[$transport] = function () use ($class, $container) {
103
            return new $class($container);
104
        };
105
106
        return $this;
107
    }
108
109
    /**
110
     * Return the list of registered transports.
111
     *
112
     * @return array
113
     */
114
    public function getAvailableTransports()
115
    {
116
        $availableTransports = $this->transports->keys();
117
118
        return array_combine($availableTransports, $availableTransports);
119
    }
120
}
121