| Conditions | 7 |
| Paths | 64 |
| Total Lines | 83 |
| Code Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 26 | public function update(ApiCall $call, ApiKey $key, Pheal $pheal) |
||
| 27 | { |
||
| 28 | $charId = $call->getOwner()->getCharacterId(); |
||
| 29 | |||
| 30 | $api = $pheal->charScope->CharacterSheet(array('characterID' => $charId)); |
||
| 31 | |||
| 32 | $entity = new CharCharacterSheet($charId); |
||
| 33 | $entity->setName($api->name); |
||
| 34 | $entity->setDateOfBirth(new \DateTime($api->DoB)); |
||
| 35 | $entity->setRace($api->race); |
||
| 36 | $entity->setBloodLine($api->bloodLine); |
||
| 37 | $entity->setAncestry($api->ancestry); |
||
| 38 | $entity->setGender($api->gender); |
||
| 39 | $entity->setCorporationId($api->corporationID); |
||
| 40 | $entity->setCorporationName($api->corporationName); |
||
| 41 | $entity->setAllianceId($api->allianceID); |
||
| 42 | $entity->setAllianceName($api->allianceName); |
||
| 43 | $entity->setCloneName($api->cloneName); |
||
| 44 | $entity->setCloneSkillPoints($api->cloneSkillPoints); |
||
| 45 | $entity->setBalance($api->balance); |
||
| 46 | |||
| 47 | $attributes = new CharAttributes(); |
||
| 48 | $entity->setAttributes($attributes); |
||
| 49 | $attributesApi = $api->attributes; |
||
| 50 | $attributes->setIntelligence($attributesApi->intelligence); |
||
| 51 | $attributes->setMemory($attributesApi->memory); |
||
| 52 | $attributes->setCharisma($attributesApi->charisma); |
||
| 53 | $attributes->setPerception($attributesApi->perception); |
||
| 54 | $attributes->setWillpower($attributesApi->willpower); |
||
| 55 | |||
| 56 | foreach ($api->skills as $skillApi) { |
||
| 57 | $skill = new CharSkill($entity); |
||
| 58 | $skill->setTypeId($skillApi->typeID); |
||
| 59 | $skill->setLevel($skillApi->level); |
||
| 60 | $skill->setSkillpoints($skillApi->skillpoints); |
||
| 61 | $skill->setPublished(filter_var($skillApi->published, FILTER_VALIDATE_BOOLEAN)); |
||
| 62 | $entity->addSkill($skill); |
||
| 63 | } |
||
| 64 | |||
| 65 | foreach ($api->corporationRoles as $roleApi) { |
||
| 66 | $role = new CharCorporationRole($entity); |
||
| 67 | $role->setRoleId($roleApi->roleID); |
||
| 68 | $role->setRoleName($roleApi->roleName); |
||
| 69 | $entity->addCorporationRole($role); |
||
| 70 | } |
||
| 71 | |||
| 72 | foreach ($api->corporationRolesAtHQ as $roleApi) { |
||
| 73 | $role = new CharCorporationRoleAtHq($entity); |
||
| 74 | $role->setRoleId($roleApi->roleID); |
||
| 75 | $role->setRoleName($roleApi->roleName); |
||
| 76 | $entity->addCorporationRolesAtHq($role); |
||
| 77 | } |
||
| 78 | |||
| 79 | foreach ($api->corporationRolesAtBase as $roleApi) { |
||
| 80 | $role = new CharCorporationRoleAtBase($entity); |
||
| 81 | $role->setRoleId($roleApi->roleID); |
||
| 82 | $role->setRoleName($roleApi->roleName); |
||
| 83 | $entity->addCorporationRolesAtBase($role); |
||
| 84 | } |
||
| 85 | |||
| 86 | foreach ($api->corporationRolesAtOther as $roleApi) { |
||
| 87 | $role = new CharCorporationRoleAtOther($entity); |
||
| 88 | $role->setRoleId($roleApi->roleID); |
||
| 89 | $role->setRoleName($roleApi->roleName); |
||
| 90 | $entity->addCorporationRolesAtOther($role); |
||
| 91 | } |
||
| 92 | |||
| 93 | foreach ($api->corporationTitles as $titleApi) { |
||
| 94 | $title = new CharCorporationTitle($entity); |
||
| 95 | $title->setTitleId($titleApi->titleID); |
||
| 96 | $title->setTitleName($titleApi->titleName); |
||
| 97 | $entity->addCorporationTitle($title); |
||
| 98 | } |
||
| 99 | |||
| 100 | $query = 'delete from TariochEveapiFetcherBundle:CharCharacterSheet c where c.characterId=:characterId'; |
||
| 101 | $this->entityManager |
||
| 102 | ->createQuery($query) |
||
| 103 | ->setParameter('characterId', $charId) |
||
| 104 | ->execute(); |
||
| 105 | |||
| 106 | $this->entityManager->persist($entity); |
||
| 107 | return $api->cached_until; |
||
| 108 | } |
||
| 109 | } |
||
| 110 |