Conditions | 11 |
Paths | 169 |
Total Lines | 53 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
77 | private function getProblemStatusFromDB($userID, $contestID = null, Carbon $till = null) |
||
78 | { |
||
79 | if (filled($contestID)) { |
||
80 | try { |
||
81 | $endedAt = Carbon::parse(Contest::findOrFail($contestID)->endedAt); |
||
82 | } catch (Exception $e) { |
||
83 | return null; |
||
84 | } |
||
85 | } |
||
86 | |||
87 | // Get the very first AC record |
||
88 | |||
89 | $acRecords = $this->submissions()->where([ |
||
90 | 'uid' => $userID, |
||
91 | 'cid' => $contestID, |
||
92 | 'verdict' => 'Accepted' |
||
93 | ]); |
||
94 | if (filled($contestID)) { |
||
95 | $acRecords = $acRecords->where("submission_date", "<", $endedAt->timestamp); |
||
96 | } |
||
97 | if (filled($till)) { |
||
98 | $acRecords = $acRecords->where("submission_date", "<", $till->timestamp); |
||
99 | } |
||
100 | $acRecords = $acRecords->orderBy('submission_date', 'desc')->first(); |
||
101 | if (blank($acRecords)) { |
||
102 | $pacRecords = $this->submissions()->where([ |
||
103 | 'uid' => $userID, |
||
104 | 'cid' => $contestID, |
||
105 | 'verdict' => 'Partially Accepted' |
||
106 | ]); |
||
107 | if (filled($contestID)) { |
||
108 | $pacRecords = $pacRecords->where("submission_date", "<", $endedAt->timestamp); |
||
109 | } |
||
110 | if (filled($till)) { |
||
111 | $pacRecords = $pacRecords->where("submission_date", "<", $till->timestamp); |
||
112 | } |
||
113 | $pacRecords = $pacRecords->orderBy('submission_date', 'desc')->first(); |
||
114 | if (blank($pacRecords)) { |
||
115 | $otherRecords = $this->submissions()->where([ |
||
116 | 'uid' => $userID, |
||
117 | 'cid' => $contestID |
||
118 | ]); |
||
119 | if (filled($contestID)) { |
||
120 | $otherRecords = $otherRecords->where("submission_date", "<", $endedAt->timestamp); |
||
121 | } |
||
122 | if (filled($till)) { |
||
123 | $otherRecords = $otherRecords->where("submission_date", "<", $till->timestamp); |
||
124 | } |
||
125 | return $otherRecords->orderBy('submission_date', 'desc')->first(); |
||
126 | } |
||
127 | return $pacRecords; |
||
128 | } else { |
||
129 | return $acRecords; |
||
130 | } |
||
176 |