CurrentApiCallFactory::createCurrentApiCallMap()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 9.2
cc 4
eloc 11
nc 5
nop 1
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