| Conditions | 21 |
| Paths | 204 |
| Total Lines | 74 |
| Code Lines | 55 |
| 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 |
||
| 51 | public function collection() |
||
| 52 | { |
||
| 53 | $maxium = $this->config['maxium'] ?? false; |
||
| 54 | $percent = $this->config['percent'] ?? false; |
||
| 55 | |||
| 56 | if($this->config['mode'] == 'contest'){ |
||
| 57 | $row_1 = ['Member','Total','','','']; |
||
| 58 | $row_2 = ['','Elo','Rank','Solved','Penalty']; |
||
| 59 | foreach ($this->contest_data as $contest) { |
||
| 60 | array_push($row_1,$contest['name'],''); |
||
| 61 | array_push($row_2,'Solved','Penalty'); |
||
| 62 | } |
||
| 63 | $data = [$row_1,$row_2]; |
||
| 64 | foreach ($this->member_data as $member) { |
||
| 65 | $display_name = $member['name']; |
||
| 66 | if(!empty($member['nick_name'])){ |
||
| 67 | $display_name .= ' ('.$member['nick_name'].')'; |
||
| 68 | } |
||
| 69 | $row = [ |
||
| 70 | $display_name, |
||
| 71 | $member['elo'], |
||
| 72 | !empty($member['rank_ave']) ? round($member['rank_ave'],1) : '-', |
||
| 73 | $percent === 'true' ? ($member['problem_all'] != 0 ? round( $member['solved_all'] / $member['problem_all'] * 100 , 1) : '-'). ' %' |
||
| 74 | : ($maxium === 'true' ? $member['solved_all'] . ' / ' . $member['problem_all'] : $member['solved_all']), |
||
| 75 | round($member['penalty']), |
||
| 76 | ]; |
||
| 77 | foreach ($this->contest_data as $contest) { |
||
| 78 | if(in_array($contest['cid'] , array_keys($member['contest_detial']))){ |
||
| 79 | $contest_detial = $member['contest_detial'][$contest['cid']]; |
||
| 80 | array_push( |
||
| 81 | $row, |
||
| 82 | $percent === 'true' ? (round($contest_detial['solved'] / $contest_detial['problems'] * 100,1) . ' %') |
||
| 83 | : ($maxium === 'true' ? $contest_detial['solved'].' / '.$contest_detial['problems'] : $contest_detial['solved']), |
||
| 84 | round($contest_detial['penalty']) |
||
| 85 | ); |
||
| 86 | }else{ |
||
| 87 | array_push( |
||
| 88 | $row, |
||
| 89 | $percent === 'true' ? '- %' |
||
| 90 | : ($maxium === 'true' ? '- / -' : ' - '), |
||
| 91 | 0 |
||
| 92 | ); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | array_push($data,$row); |
||
| 96 | } |
||
| 97 | }else{ |
||
| 98 | $row_1 = ['Member']; |
||
| 99 | $row_2 = ['']; |
||
| 100 | foreach ($this->tag_problems as $tag => $tag_problem_set) { |
||
| 101 | array_push($row_1,$tag); |
||
| 102 | array_push($row_2,'Solved'); |
||
| 103 | } |
||
| 104 | $data = [$row_1,$row_2]; |
||
| 105 | foreach ($this->member_data as $member) { |
||
| 106 | $display_name = $member['name']; |
||
| 107 | if(!empty($member['nick_name'])){ |
||
| 108 | $display_name .= ' ('.$member['nick_name'].')'; |
||
| 109 | } |
||
| 110 | $row = [ |
||
| 111 | $display_name, |
||
| 112 | ]; |
||
| 113 | foreach($member['completion'] as $tag => $tag_completion){ |
||
| 114 | $count = count($tag_completion); |
||
| 115 | $solved = eval('return '.join('+',array_values($tag_completion)).';'); |
||
|
|
|||
| 116 | array_push( |
||
| 117 | $row, |
||
| 118 | $percent === 'true' ? (round($solved / $count * 100,1) . ' %') : ($maxium === 'true' ? $solved .' / '.$count : $solved) |
||
| 119 | ); |
||
| 120 | } |
||
| 121 | array_push($data,$row); |
||
| 122 | } |
||
| 123 | } |
||
| 124 | return collect($data); |
||
| 125 | } |
||
| 159 |