Conditions | 5 |
Paths | 7 |
Total Lines | 101 |
Code Lines | 69 |
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 |
||
26 | public function reset() { |
||
27 | $this->_log .= "user: {$this->_user}<br/>"; |
||
28 | $this->_log .= "uid: {$this->_uid}<br/>"; |
||
29 | if (!$this->_uid) { |
||
30 | return false; |
||
31 | } |
||
32 | |||
33 | $this->_log .= 'cleaning MySQL data:<br/>'; |
||
34 | |||
35 | //get details |
||
36 | $p = Yii::app()->db->createCommand() |
||
37 | ->select('*') |
||
38 | ->from('main') |
||
39 | ->where('uid = :uid', [':uid'=>$this->_uid]) |
||
40 | ->queryRow(); |
||
41 | //get club ownership |
||
42 | if ($p['in_club']) { |
||
43 | $owned = Yii::app()->db->createCommand() |
||
44 | ->select('id') |
||
45 | ->from('club') |
||
46 | ->where('owner = :uid', [':uid'=>$this->_uid]) |
||
47 | ->queryScalar(); |
||
48 | if ($owned) { |
||
49 | //delete clubs forum |
||
50 | Yii::app()->db->createCommand("DELETE FROM forum WHERE club_id={$owned}")->execute(); |
||
51 | $this->_log .= ' - forum posts<br/>'; |
||
52 | |||
53 | //delete club members |
||
54 | Yii::app()->db->createCommand("UPDATE main SET in_club=0 WHERE uid IN (SELECT uid FROM club_members WHERE club_id={$owned})")->execute(); |
||
55 | Yii::app()->db->createCommand("DELETE FROM club_members WHERE club_id={$owned}")->execute(); |
||
56 | $this->_log .= ' - clubs members<br/>'; |
||
57 | |||
58 | //delete challenges |
||
59 | Yii::app()->db->createCommand("DELETE FROM challenge WHERE caller={$owned} OR opponent={$owned}")->execute(); |
||
60 | $this->_log .= ' - clubs challenges<br/>'; |
||
61 | |||
62 | //delete club |
||
63 | Yii::app()->db->createCommand("DELETE FROM club WHERE id={$owned}")->execute(); |
||
64 | $this->_log .= ' - owned club<br/>'; |
||
65 | } |
||
66 | } |
||
67 | |||
68 | Yii::app()->db->createCommand("DELETE FROM club_members WHERE uid={$this->_uid}")->execute(); |
||
69 | $this->_log .= ' - club membership<br/>'; |
||
70 | |||
71 | Yii::app()->db->createCommand("DELETE FROM duel WHERE caller={$this->_uid} OR opponent={$this->_uid}")->execute(); |
||
72 | $this->_log .= ' - duel data<br/>'; |
||
73 | |||
74 | Yii::app()->db->createCommand("DELETE FROM log WHERE uid={$this->_uid}")->execute(); |
||
75 | Yii::app()->db->createCommand("DELETE FROM log_counters WHERE uid={$this->_uid}")->execute(); |
||
76 | $this->_log .= ' - logs, counters<br/>'; |
||
77 | |||
78 | Yii::app()->db->createCommand("DELETE FROM users_baits WHERE uid={$this->_uid}")->execute(); |
||
79 | Yii::app()->db->createCommand("DELETE FROM users_items WHERE uid={$this->_uid}")->execute(); |
||
80 | Yii::app()->db->createCommand("DELETE FROM users_parts WHERE uid={$this->_uid}")->execute(); |
||
81 | $this->_log .= ' - baits, items, parts<br/>'; |
||
82 | |||
83 | Yii::app()->db->createCommand("DELETE FROM users_missions WHERE uid={$this->_uid}")->execute(); |
||
84 | $this->_log .= ' - missions<br/>'; |
||
85 | |||
86 | Yii::app()->db->createCommand("DELETE FROM visited WHERE uid={$this->_uid}")->execute(); |
||
87 | $this->_log .= ' - visited waters<br/>'; |
||
88 | |||
89 | Yii::app()->db->createCommand("DELETE FROM wall WHERE uid={$this->_uid}")->execute(); |
||
90 | $this->_log .= ' - wall<br/>'; |
||
91 | |||
92 | Yii::app()->db->createCommand("DELETE FROM main WHERE uid={$this->_uid}")->execute(); |
||
93 | $this->_log .= ' - main data<br/>'; |
||
94 | |||
95 | |||
96 | $this->_log .= 'cleaning REDIS data:<br/>'; |
||
97 | $redis = Yii::app()->redis->getClient(); |
||
98 | |||
99 | $redis->del('badges:added:'.$this->_uid); |
||
100 | $redis->del('badges:owned:'.$this->_uid); |
||
101 | $redis->zRem('badges:leaderboard',$this->_uid); |
||
102 | $this->_log .= ' - badges<br/>'; |
||
103 | |||
104 | $redis->zRem('board_p:201312', $this->_uid); |
||
105 | $redis->zRem('board_p:201311', $this->_uid); |
||
106 | $redis->zRem('board_p:201310', $this->_uid); |
||
107 | $redis->zRem('board_p:201309', $this->_uid); |
||
108 | $redis->zRem('board_p:201308', $this->_uid); |
||
109 | $redis->zRem('board_p:6month', $this->_uid); |
||
110 | $this->_log .= ' - leaderboard<br/>'; |
||
111 | |||
112 | |||
113 | $suid = (string)$this->_uid; |
||
114 | $key = 'counter:' . $suid[0] . ':' . $suid[1] . ':' .$suid[2] . ':' . $suid; |
||
115 | $redis->del($key.':all'); |
||
116 | for ($i=0; $i<100; $i++) { |
||
117 | $redis->del($key.':levels:'.$i); |
||
118 | } |
||
119 | $this->_log .= ' - counters<br/>'; |
||
120 | |||
121 | $redis->del('login:days:'.$this->_uid); |
||
122 | $this->_log .= ' - login counter<br/>'; |
||
123 | |||
124 | $redis->del('debug:setitem:'.$this->_uid); |
||
125 | $this->_log .= ' - setitem log<br/>'; |
||
126 | } |
||
127 | } |
||
128 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.