| Conditions | 10 |
| Paths | 64 |
| Total Lines | 40 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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 |
||
| 64 | public function IsPickValidForUpdate(Draft $draft, Pick $pick) { |
||
| 65 | $valid = true; |
||
| 66 | $errors = array(); |
||
| 67 | $teams = $this->app['phpdraft.DraftDataRepository']->GetTeams($draft->draft_sport); |
||
| 68 | $positions = $this->app['phpdraft.DraftDataRepository']->GetPositions($draft->draft_sport); |
||
| 69 | |||
| 70 | if (empty($pick->first_name) |
||
| 71 | || empty($pick->last_name) |
||
| 72 | || empty($pick->team) |
||
| 73 | || empty($pick->position)) { |
||
| 74 | $errors[] = "One or more missing fields."; |
||
| 75 | $valid = false; |
||
| 76 | } |
||
| 77 | |||
| 78 | if ($pick->draft_id != $draft->draft_id) { |
||
| 79 | $errors[] = "Pick does not belong to draft #$draft->draft_id."; |
||
| 80 | $valid = false; |
||
| 81 | } |
||
| 82 | |||
| 83 | if (strlen($pick->first_name) > 255) { |
||
| 84 | $errors[] = "First name is above maximum length."; |
||
| 85 | $valid = false; |
||
| 86 | } |
||
| 87 | |||
| 88 | if (strlen($pick->last_name) > 255) { |
||
| 89 | $errors[] = "Last name is above maximum length."; |
||
| 90 | $valid = false; |
||
| 91 | } |
||
| 92 | |||
| 93 | if (!array_key_exists($pick->team, $teams)) { |
||
| 94 | $errors[] = "Team $pick->team is an invalid value."; |
||
| 95 | $valid = false; |
||
| 96 | } |
||
| 97 | |||
| 98 | if (!array_key_exists($pick->position, $positions)) { |
||
| 99 | $errors[] = "Position $pick->position is an invalid value."; |
||
| 100 | $valid = false; |
||
| 101 | } |
||
| 102 | |||
| 103 | return $this->app['phpdraft.ResponseFactory']($valid, $errors); |
||
| 104 | } |
||
| 117 | } |