| Conditions | 5 |
| Paths | 4 |
| Total Lines | 23 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | protected function incrementLoginDays($uid) |
||
| 8 | { |
||
| 9 | if (!$uid) { |
||
| 10 | return false; |
||
| 11 | } |
||
| 12 | |||
| 13 | $redis = Yii::app()->redis->getClient(); |
||
|
|
|||
| 14 | $key = "counter:login:days:".$uid; |
||
| 15 | $yesterday = array( |
||
| 16 | 'start' => mktime(0, 0, 0, date('m'), date('d')-1, date('Y')), |
||
| 17 | 'end' => mktime(0, 0, -1, date('m'), date('d'), date('Y')), |
||
| 18 | ); |
||
| 19 | |||
| 20 | $cnt = 0; |
||
| 21 | $last = $redis->hGet($key, 'last'); |
||
| 22 | if ($last >= $yesterday['start'] && $last <= $yesterday['end']) { //yesterday |
||
| 23 | $cnt = $redis->hIncrBy($key, 'cnt', 1); |
||
| 24 | } elseif ($last < $yesterday['start']) { //more than 1 day ago |
||
| 25 | $redis->hSet($key, 'cnt', 0); |
||
| 26 | } |
||
| 27 | $redis->hSet($key, 'last', time()); |
||
| 28 | return $cnt; |
||
| 29 | } |
||
| 30 | } |
||
| 31 |
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.