MailMotorFactory::getSubscriberGateway()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
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