Conditions | 11 |
Paths | 128 |
Total Lines | 45 |
Code Lines | 29 |
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 |
||
17 | public function IsPickValidForAdd(Draft $draft, Pick $pick) { |
||
18 | $valid = true; |
||
19 | $errors = array(); |
||
20 | $teams = $this->app['phpdraft.DraftDataRepository']->GetTeams($draft->draft_sport); |
||
21 | $positions = $this->app['phpdraft.DraftDataRepository']->GetPositions($draft->draft_sport); |
||
22 | |||
23 | if (empty($pick->first_name) |
||
24 | || empty($pick->last_name) |
||
25 | || empty($pick->team) |
||
26 | || empty($pick->position)) { |
||
27 | $errors[] = "One or more missing fields."; |
||
28 | $valid = false; |
||
29 | } |
||
30 | |||
31 | if ($pick->draft_id != $draft->draft_id) { |
||
32 | $errors[] = "Pick does not belong to draft #$draft->draft_id."; |
||
33 | $valid = false; |
||
34 | } |
||
35 | |||
36 | if (strlen($pick->first_name) > 255) { |
||
37 | $errors[] = "First name is above maximum length."; |
||
38 | $valid = false; |
||
39 | } |
||
40 | |||
41 | if (strlen($pick->last_name) > 255) { |
||
42 | $errors[] = "Last name is above maximum length."; |
||
43 | $valid = false; |
||
44 | } |
||
45 | |||
46 | if ($draft->draft_current_pick != $pick->player_pick) { |
||
47 | $errors[] = "Pick #$pick->player_pick is not the current pick for draft #$draft->draft_id."; |
||
48 | $valid = false; |
||
49 | } |
||
50 | |||
51 | if (!array_key_exists($pick->team, $teams)) { |
||
52 | $errors[] = "Team $pick->team is an invalid value."; |
||
53 | $valid = false; |
||
54 | } |
||
55 | |||
56 | if (!array_key_exists($pick->position, $positions)) { |
||
57 | $errors[] = "Position $pick->position is an invalid value."; |
||
58 | $valid = false; |
||
59 | } |
||
60 | |||
61 | return $this->app['phpdraft.ResponseFactory']($valid, $errors); |
||
62 | } |
||
117 | } |