Conditions | 11 |
Paths | 169 |
Total Lines | 55 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
91 | private function getProblemStatusFromDB($userID, $contestID = null, Carbon $till = null) |
||
92 | { |
||
93 | $endedAt = Carbon::now(); |
||
94 | |||
95 | if (filled($contestID)) { |
||
96 | try { |
||
97 | $endedAt = Carbon::parse(Contest::findOrFail($contestID)->endedAt); |
||
98 | } catch (Exception $e) { |
||
99 | return null; |
||
100 | } |
||
101 | } |
||
102 | |||
103 | // Get the very first AC record |
||
104 | |||
105 | $acRecords = $this->submissions()->where([ |
||
106 | 'uid' => $userID, |
||
107 | 'cid' => $contestID, |
||
108 | 'verdict' => 'Accepted' |
||
109 | ]); |
||
110 | if (filled($contestID)) { |
||
111 | $acRecords = $acRecords->where("submission_date", "<", $endedAt->timestamp); |
||
112 | } |
||
113 | if (filled($till)) { |
||
114 | $acRecords = $acRecords->where("submission_date", "<", $till->timestamp); |
||
115 | } |
||
116 | $acRecords = $acRecords->orderBy('submission_date', 'desc')->first(); |
||
117 | if (blank($acRecords)) { |
||
118 | $pacRecords = $this->submissions()->where([ |
||
119 | 'uid' => $userID, |
||
120 | 'cid' => $contestID, |
||
121 | 'verdict' => 'Partially Accepted' |
||
122 | ]); |
||
123 | if (filled($contestID)) { |
||
124 | $pacRecords = $pacRecords->where("submission_date", "<", $endedAt->timestamp); |
||
125 | } |
||
126 | if (filled($till)) { |
||
127 | $pacRecords = $pacRecords->where("submission_date", "<", $till->timestamp); |
||
128 | } |
||
129 | $pacRecords = $pacRecords->orderBy('submission_date', 'desc')->first(); |
||
130 | if (blank($pacRecords)) { |
||
131 | $otherRecords = $this->submissions()->where([ |
||
132 | 'uid' => $userID, |
||
133 | 'cid' => $contestID |
||
134 | ]); |
||
135 | if (filled($contestID)) { |
||
136 | $otherRecords = $otherRecords->where("submission_date", "<", $endedAt->timestamp); |
||
137 | } |
||
138 | if (filled($till)) { |
||
139 | $otherRecords = $otherRecords->where("submission_date", "<", $till->timestamp); |
||
140 | } |
||
141 | return $otherRecords->orderBy('submission_date', 'desc')->first(); |
||
142 | } |
||
143 | return $pacRecords; |
||
144 | } else { |
||
145 | return $acRecords; |
||
146 | } |
||
192 |