Factory::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
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