NewApiFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 1
cbo 1
dl 0
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B createNewApiMap() 0 22 4
1
<?php
2
namespace Tarioch\EveapiFetcherBundle\Component\EveApi\Account\ApiKeyInfo;
3
4
use JMS\DiExtraBundle\Annotation as DI;
5
use Doctrine\ORM\EntityManager;
6
7
/**
8
 * @DI\Service(id = "tarioch.eveapi.account.api_key_info.new_api_factory", public = false)
9
 */
10
class NewApiFactory
11
{
12
    private $entityManager;
13
14
    /**
15
     * @DI\InjectParams({
16
     * "entityManager" = @DI\Inject("doctrine.orm.eveapi_entity_manager")
17
     * })
18
     */
19
    public function __construct(EntityManager $entityManager)
20
    {
21
        $this->entityManager = $entityManager;
22
    }
23
24
    public function createNewApiMap($accessMask, $keyType, array $chars)
25
    {
26
        $apiRepo = $this->entityManager->getRepository('TariochEveapiFetcherBundle:Api');
27
        $validApis = $apiRepo->loadValidApis($accessMask, $keyType);
28
29
        $newApiMap = array();
30
        foreach ($validApis as $api) {
31
            $apiId = $api->getApiId();
32
            $newApiMap[$apiId] = array();
33
34
            $section = $api->getSection();
35
            if ($section == 'account') {
36
                $newApiMap[$apiId][0] = $api;
37
            } else {
38
                foreach ($chars as $ownerId) {
39
                    $newApiMap[$apiId][$ownerId] = $api;
40
                }
41
            }
42
        }
43
44
        return $newApiMap;
45
    }
46
}
47