MailMotorFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 9
c 3
b 0
f 0
dl 0
loc 28
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscriberGateway() 0 3 1
A setMailEngine() 0 7 3
A __construct() 0 6 1
1
<?php
2
3
namespace MailMotor\Bundle\MailMotorBundle\Factory;
4
5
use Symfony\Component\DependencyInjection\ServiceLocator;
6
use MailMotor\Bundle\MailMotorBundle\Gateway\SubscriberGateway;
7
8
/**
9
 * This is the class that loads and manages your bundle configuration
10
 *
11
 * @author Jeroen Desloovere <[email protected]>
12
 */
13
class MailMotorFactory
14
{
15
    /** @var ServiceLocator */
16
    protected $serviceLocator;
17
18
    /** @var string|null */
19
    protected $mailEngine;
20
21
    public function __construct(
22
        ServiceLocator $serviceLocator,
23
        ?string $mailEngine
24
    ) {
25
        $this->serviceLocator = $serviceLocator;
26
        $this->setMailEngine($mailEngine);
27
    }
28
29
    public function getSubscriberGateway(): SubscriberGateway
30
    {
31
        return $this->serviceLocator->get($this->mailEngine);
0 ignored issues
show
Bug introduced by
It seems like $this->mailEngine can also be of type null; however, parameter $id of Symfony\Component\Depend...n\ServiceLocator::get() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
        return $this->serviceLocator->get(/** @scrutinizer ignore-type */ $this->mailEngine);
Loading history...
32
    }
33
34
    protected function setMailEngine(?string $mailEngine): void
35
    {
36
        if ($mailEngine === null || !$this->serviceLocator->has($mailEngine)) {
37
            $mailEngine = 'not_implemented';
38
        }
39
40
        $this->mailEngine = strtolower($mailEngine);
41
    }
42
}
43