ApiServiceProvider::setApiService()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Swm\Bundle\MailHookBundle\Provider;
4
5
use Swm\Bundle\MailHookBundle\ApiService\ApiServiceInterface;
6
use Symfony\Component\DependencyInjection\Exception\LogicException;
7
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
8
9
class ApiServiceProvider implements ProviderInterface
10
{
11
    /**
12
     * @var array
13
     */
14
    private $apiServiceList = array();
15
16
    /**
17
     * @param  string $apiServiceName
18
     * @return ApiServiceInterface
19
     */
20
    public function get($apiServiceName)
21
    {
22
        if (!array_key_exists($apiServiceName, $this->apiServiceList)) {
23
            throw new LogicException("This api service is not allowed");
24
        }
25
        return $this->apiServiceList[$apiServiceName];
26
    }
27
28
    /**
29
     * @param string              $apiServiceName
30
     * @param ApiServiceInterface $apiService
31
     * @return this
32
     */
33
    public function setApiService($apiServiceName, ApiServiceInterface $apiService)
34
    {
35
        $this->apiServiceList[$apiServiceName] = $apiService;
36
37
        return $this;
38
    }
39
40
    /**
41
     * @param  string $apiServiceName
42
     * @return string
43
     */
44
    private function sanitize($apiServiceName)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
45
    {
46
        return strtolower($apiServiceName);
47
    }
48
}
49