Conditions | 5 |
Paths | 4 |
Total Lines | 52 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 1 | Features | 2 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
18 | public function update(ApiCall $call, ApiKey $key, Pheal $pheal) |
||
19 | { |
||
20 | $owner = $call->getOwner(); |
||
21 | $charId = $owner->getCharacterId(); |
||
22 | |||
23 | $accountRepo = $this->entityManager->getRepository('TariochEveapiFetcherBundle:CharAccountBalance'); |
||
24 | $accounts = $accountRepo->findByOwnerId($charId); |
||
25 | |||
26 | $cached = 'now'; |
||
27 | foreach ($accounts as $account) { |
||
28 | $accountKey = $account->getAccountKey(); |
||
29 | |||
30 | $api = $pheal->charScope->WalletJournal(array( |
||
31 | 'characterID' => $charId, |
||
32 | 'rowCount' => 2560, |
||
33 | 'accountKey' => $accountKey |
||
34 | )); |
||
35 | $cached = $api->cached_until; |
||
36 | |||
37 | $repo = $this->entityManager->getRepository('TariochEveapiFetcherBundle:CharWalletJournal'); |
||
38 | foreach ($api->transactions as $entry) { |
||
39 | $refId = $entry->refID; |
||
40 | |||
41 | $entity = $repo->findOneBy(array('refId' => $refId, 'ownerId' => $charId)); |
||
42 | if ($entity === null) { |
||
43 | $entity = new CharWalletJournal($refId, $charId); |
||
44 | $this->entityManager->persist($entity); |
||
45 | |||
46 | $entity->setAccountKey($accountKey); |
||
47 | $entity->setDate(new \DateTime($entry->date)); |
||
48 | $entity->setRefTypeId($entry->refTypeID); |
||
49 | $entity->setOwnerName1($entry->ownerName1); |
||
50 | $entity->setOwnerId1($entry->ownerID1); |
||
51 | $entity->setOwnerName2($entry->ownerName2); |
||
52 | $entity->setOwnerId2($entry->ownerID2); |
||
53 | $entity->setArgName1($entry->argName1); |
||
54 | $entity->setArgId1($entry->argID1); |
||
55 | $entity->setAmount($entry->amount); |
||
56 | $entity->setBalance($entry->balance); |
||
57 | $entity->setReason($entry->reason); |
||
58 | $entity->setOwner1TypeId($entry->owner1TypeID); |
||
59 | $entity->setOwner2TypeId($entry->owner2TypeID); |
||
60 | $entity->setTaxAmount((float) $entry->taxAmount); |
||
61 | $entity->setTaxReceiverId($entry->taxReceiverID === '' ? null : $entry->taxReceiverID); |
||
62 | |||
63 | $this->entityManager->flush($entity); |
||
64 | } |
||
65 | } |
||
66 | } |
||
67 | |||
68 | return $cached; |
||
69 | } |
||
70 | } |
||
71 |