| Conditions | 4 |
| Paths | 4 |
| Total Lines | 53 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 8 | ||
| Bugs | 3 | 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 | $corpId = $owner->getCorporationId(); |
||
| 23 | |||
| 24 | $accountRepo = $this->entityManager->getRepository('TariochEveapiFetcherBundle:CorpAccountBalance'); |
||
| 25 | $accounts = $accountRepo->findByOwnerId($corpId); |
||
| 26 | |||
| 27 | $cached = 'now'; |
||
| 28 | foreach ($accounts as $account) { |
||
| 29 | $accountKey = $account->getAccountKey(); |
||
| 30 | |||
| 31 | $api = $pheal->corpScope->WalletTransactions(array( |
||
| 32 | 'characterID' => $charId, |
||
| 33 | 'rowCount' => 2560, |
||
| 34 | 'accountKey' => $accountKey |
||
| 35 | )); |
||
| 36 | $cached = $api->cached_until; |
||
| 37 | |||
| 38 | $repo = $this->entityManager->getRepository('TariochEveapiFetcherBundle:CorpWalletTransaction'); |
||
| 39 | foreach ($api->transactions as $transaction) { |
||
| 40 | $transId = $transaction->transactionID; |
||
| 41 | |||
| 42 | $criteria = array('transactionId' => $transId, 'ownerId' => $corpId, 'accountKey' => $accountKey); |
||
| 43 | $entity = $repo->findOneBy($criteria); |
||
| 44 | if ($entity === null) { |
||
| 45 | $entity = new CorpWalletTransaction($transId, $corpId, $accountKey); |
||
| 46 | $this->entityManager->persist($entity); |
||
| 47 | |||
| 48 | $entity->setJournalTransactionId($transaction->journalTransactionID); |
||
| 49 | $entity->setTransactionDateTime(new \DateTime($transaction->transactionDateTime)); |
||
| 50 | $entity->setQuantity($transaction->quantity); |
||
| 51 | $entity->setTypeName($transaction->typeName); |
||
| 52 | $entity->setTypeId($transaction->typeID); |
||
| 53 | $entity->setPrice($transaction->price); |
||
| 54 | $entity->setClientId($transaction->clientID); |
||
| 55 | $entity->setClientName($transaction->clientName); |
||
| 56 | $entity->setClientTypeId($transaction->clientTypeID); |
||
| 57 | $entity->setStationId($transaction->stationID); |
||
| 58 | $entity->setStationName($transaction->stationName); |
||
| 59 | $entity->setTransactionType($transaction->transactionType); |
||
| 60 | $entity->setTransactionFor($transaction->transactionFor); |
||
| 61 | $entity->setCharacterId($transaction->characterID); |
||
| 62 | $entity->setCharacterName($transaction->characterName); |
||
| 63 | |||
| 64 | $this->entityManager->flush($entity); |
||
| 65 | } |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | return $cached; |
||
| 70 | } |
||
| 71 | } |
||
| 72 |