BlueprintUpdater   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 15 1
A addBlueprints() 0 18 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\CorpBlueprint;
9
10
/**
11
 * @DI\Service("tarioch.eveapi.corp.Blueprints")
12
 */
13
class BlueprintUpdater 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->Blueprints();
23
24
        $this->entityManager
25
            ->createQuery('delete from TariochEveapiFetcherBundle:CorpBlueprint c where c.ownerId=:ownerId')
26
            ->setParameter('ownerId', $corpId)
27
            ->execute();
28
29
        $this->addBlueprints($api->blueprints, $corpId);
30
31
        return $api->cached_until;
32
    }
33
34
    private function addBlueprints($blueprints, $corpId)
35
    {
36
        foreach ($blueprints as $blueprint) {
37
            $entity = new CorpBlueprint();
38
            $entity->setOwnerId($corpId);
39
            $entity->setLocationId($blueprint->locationID);
40
            $entity->setItemId($blueprint->itemID);
41
            $entity->setTypeId($blueprint->typeID);
42
            $entity->setTypeName($blueprint->typeName);
43
            $entity->setQuantity($blueprint->quantity);
44
            $entity->setFlag($blueprint->flagID);
45
            $entity->setRuns($blueprint->runs);
46
            $entity->setTimeEfficiency($blueprint->timeEfficiency);
47
            $entity->setMaterialEfficiency($blueprint->materialEfficiency);
48
49
            $this->entityManager->persist($entity);
50
        }
51
    }
52
}
53