DispatcherFactory::createAsyncMessageDispatcher()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
/**
4
 * This file is part of the theroadbunch/mandrill-sdk package.
5
 *
6
 * (c) Dan McAdams <[email protected]>
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 RoadBunch\Mandrill;
13
14
use RoadBunch\Mandrill\Message as Message;
15
16
17
/**
18
 * Class DispatcherFactory
19
 *
20
 * @author  Dan McAdams
21
 * @package RoadBunch\Mandrill
22
 */
23
class DispatcherFactory
24
{
25
    /**
26
     * @var \Mandrill $service
27
     */
28
    protected $service;
29
30
    /**
31
     * DispatcherFactory constructor.
32
     *
33
     * If no api key is provided, Mandrill will check for an environment variable MANDRILL_APIKEY
34
     * If those don't exits, Mandrill will look for ~/.mandrill.key or /etc/mandrill.key
35
     *
36
     * @param string $apiKey
37
     * @throws \Mandrill_Error
38
     */
39
    public function __construct(string $apiKey = null)
40
    {
41
        $this->service = new \Mandrill($apiKey);
42
    }
43
44
    /**
45
     * @return Message\Dispatcher
46
     */
47
    public function createMessageDispatcher()
48
    {
49
        return new Message\Dispatcher($this->service->messages);
50
    }
51
52
    /**
53
     * @return Message\AsyncDispatcher
54
     */
55
    public function createAsyncMessageDispatcher()
56
    {
57
        return new Message\AsyncDispatcher($this->service->messages);
58
    }
59
}
60