CurrentApiCallFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createCurrentApiCallMap() 0 18 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
use Tarioch\EveapiFetcherBundle\Entity\ApiKey;
7
8
/**
9
 * @DI\Service(id = "tarioch.eveapi.account.api_key_info.current_api_call_factory", public = false)
10
 */
11
class CurrentApiCallFactory
12
{
13
    private $entityManager;
14
15
    /**
16
     * @DI\InjectParams({
17
     * "entityManager" = @DI\Inject("doctrine.orm.eveapi_entity_manager")
18
     * })
19
     */
20
    public function __construct(EntityManager $entityManager)
21
    {
22
        $this->entityManager = $entityManager;
23
    }
24
25
    public function createCurrentApiCallMap(ApiKey $key)
26
    {
27
        $apiCallRepo = $this->entityManager->getRepository('TariochEveapiFetcherBundle:ApiCall');
28
        $currentApiCalls = $apiCallRepo->findNormalCallsByKey($key);
29
30
        $currentApiCallMap = array();
31
        foreach ($currentApiCalls as $apiCall) {
32
            $apiId = $apiCall->getApi()->getApiId();
33
            if (!isset($currentApiCallMap[$apiId])) {
34
                $currentApiCallMap[$apiId] = array();
35
            }
36
37
            $owner = $apiCall->getOwner();
38
            $currentApiCallMap[$apiId][$owner === null ? 0 : $owner->getId()] = $apiCall;
39
        }
40
41
        return $currentApiCallMap;
42
    }
43
}
44