MapSovereigntyUpdater::update()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 18
rs 9.4285
c 1
b 0
f 1
cc 2
eloc 12
nc 2
nop 2
1
<?php
2
namespace Tarioch\EveapiFetcherBundle\Component\EveApi\NoKey;
3
4
use JMS\DiExtraBundle\Annotation as DI;
5
use Doctrine\ORM\EntityManager;
6
use Tarioch\EveapiFetcherBundle\Component\EveApi\NoKeyApi;
7
use Tarioch\EveapiFetcherBundle\Entity\ApiCall;
8
use Pheal\Pheal;
9
use Tarioch\EveapiFetcherBundle\Entity\MapSovereignty;
10
11
/**
12
 * @DI\Service("tarioch.eveapi.map.Sovereignty")
13
 */
14
class MapSovereigntyUpdater implements NoKeyApi
15
{
16
    private $entityManager;
17
18
    /**
19
     * @DI\InjectParams({
20
     * "entityManager" = @DI\Inject("doctrine.orm.eveapi_entity_manager")
21
     * })
22
     */
23
    public function __construct(EntityManager $entityManager)
24
    {
25
        $this->entityManager = $entityManager;
26
    }
27
28
    /**
29
     * @inheritdoc
30
     */
31
    public function update(ApiCall $call, Pheal $pheal)
32
    {
33
        $this->entityManager->createQuery('delete from TariochEveapiFetcherBundle:MapSovereignty')->execute();
34
35
        $api = $pheal->mapScope->Sovereignty();
36
        foreach ($api->solarSystems as $solarSystem) {
37
            $mapSov = new MapSovereignty(
38
                $solarSystem->solarSystemID,
39
                $solarSystem->allianceID,
40
                $solarSystem->corporationID,
41
                $solarSystem->factionID,
42
                $solarSystem->solarSystemName
43
            );
44
            $this->entityManager->persist($mapSov);
45
        }
46
47
        return $api->cached_until;
48
    }
49
}
50