StarbaseListUpdater   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B update() 0 27 2
1
<?php
2
namespace Tarioch\EveapiFetcherBundle\Component\EveApi\Corp;
3
4
use JMS\DiExtraBundle\Annotation as DI;
5
use Tarioch\EveapiFetcherBundle\Entity\ApiCall;
6
use Pheal\Pheal;
7
use Tarioch\EveapiFetcherBundle\Entity\ApiKey;
8
use Tarioch\EveapiFetcherBundle\Entity\CorpStarbase;
9
10
/**
11
 * @DI\Service("tarioch.eveapi.corp.StarbaseList")
12
 */
13
class StarbaseListUpdater extends AbstractCorpUpdater
14
{
15
    /**
16
     * @inheritdoc
17
     */
18
    public function update(ApiCall $call, ApiKey $key, Pheal $pheal)
19
    {
20
        $owner = $call->getOwner();
21
        $corpId = $owner->getCorporationId();
22
        $api = $pheal->corpScope->StarbaseList();
23
24
        $this->entityManager
25
            ->createQuery('delete from TariochEveapiFetcherBundle:CorpStarbase cs where cs.ownerId=:ownerId')
26
            ->setParameter('ownerId', $corpId)
27
            ->execute();
28
29
        foreach ($api->starbases as $starbase) {
30
            $entity = new CorpStarbase($starbase->itemID);
31
            $entity->setOwnerId($corpId);
32
            $entity->setTypeId($starbase->typeID);
33
            $entity->setLocationId($starbase->locationID);
34
            $entity->setMoonId($starbase->moonID);
35
            $entity->setState($starbase->state);
36
            $entity->setStateTimestamp(new \DateTime($starbase->stateTimestamp));
37
            $entity->setOnlineTimestamp(new \DateTime($starbase->onlineTimestamp));
38
            $entity->setStandingOwnerId($starbase->standingOwnerID);
39
40
            $this->entityManager->persist($entity);
41
        }
42
43
        return $api->cached_until;
44
    }
45
}
46