SectionApiFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
namespace Tarioch\EveapiFetcherBundle\Component\Section;
3
4
use JMS\DiExtraBundle\Annotation as DI;
5
use Tarioch\EveapiFetcherBundle\Entity\ApiCall;
6
use Tarioch\EveapiFetcherBundle\Entity\Api;
7
8
/**
9
 * @DI\Service(public=false)
10
 */
11
class SectionApiFactory
12
{
13
    private static $keySections = array('account', 'char', 'corp');
14
15
    private $keySectionApi;
16
    private $noKeySectionApi;
17
18
    /**
19
     * @DI\InjectParams({
20
     * "keySectionApi" = @DI\Inject("tarioch.eveapi_fetcher_bundle.component.section.key_section_api"),
21
     * "noKeySectionApi" = @DI\Inject("tarioch.eveapi_fetcher_bundle.component.section.no_key_section_api")
22
     * })
23
     */
24
    public function __construct(KeySectionApi $keySectionApi, NoKeySectionApi $noKeySectionApi)
25
    {
26
        $this->keySectionApi = $keySectionApi;
27
        $this->noKeySectionApi = $noKeySectionApi;
28
    }
29
30
    /**
31
     *
32
     * @param ApiCall $call
33
     * @return SectionApi
34
     */
35
    public function create(ApiCall $call)
36
    {
37
        $section = $call->getApi()->getSection();
38
        if (in_array($section, self::$keySections)) {
39
            return $this->keySectionApi;
40
        } else {
41
            return $this->noKeySectionApi;
42
        }
43
    }
44
}
45