Factory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 13 1
A resolveTransportOptions() 0 19 4
1
<?php
2
3
namespace WebinoMailLib;
4
5
use WebinoConfigLib\Feature\FileMailer;
6
use Zend\Mail\Transport\Factory as TransportFactory;
7
8
/**
9
 * Class Factory
10
 */
11
final class Factory
12
{
13
    /**
14
     * Create a mailer
15
     *
16
     * @param array|\Traversable $options
17
     * @return MailerInterface
18
     */
19
    public function create($options = null)
20
    {
21
22
        $transport = TransportFactory::create($this->resolveTransportOptions($options));
0 ignored issues
show
Bug introduced by
It seems like $this->resolveTransportOptions($options) targeting WebinoMailLib\Factory::resolveTransportOptions() can also be of type object<Traversable>; however, Zend\Mail\Transport\Factory::create() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
23
24
        $mailer = new Mailer;
25
26
        $mailer->setTransport($transport);
27
28
        // TODO config message
29
30
        return $mailer;
31
    }
32
33
    /**
34
     * @param array|\Traversable $options
35
     * @return array|\Traversable
36
     */
37
    private function resolveTransportOptions($options = null)
38
    {
39
        // TODO optional
40
        $defaultTransport = FileMailer::class;
41
42
        // TODO constants
43
        if (null !== $options && isset($options['transports'])) {
44
            /** @var \WebinoAppLib\Application\Config $transports */
45
            $transports = $options['transports'];
46
47
            if (!empty($transports[$defaultTransport])) {
48
                return $transports[$defaultTransport];
49
            } else {
50
                return current($transports->toArray());
51
            }
52
        }
53
54
        return [];
55
    }
56
}
57