| Conditions | 13 |
| Paths | 13 |
| Total Lines | 74 |
| Code Lines | 50 |
| Lines | 43 |
| Ratio | 58.11 % |
| Changes | 1 | ||
| 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 |
||
| 41 | public function get() { |
||
| 42 | |||
| 43 | // Seconds |
||
| 44 | if($this->second <= 60) { |
||
| 45 | return Lang::get($this->language, "just-now" ); |
||
| 46 | } |
||
| 47 | //Minutes |
||
| 48 | else if($this->minute <=60){ |
||
| 49 | View Code Duplication | if($this->minute==1){ |
|
| 50 | return Lang::get($this->language, 'one-minute') . " " . |
||
| 51 | Lang::get($this->language, 'ago'); |
||
| 52 | } |
||
| 53 | else{ |
||
| 54 | return "$this->minute " . Lang::get($this->language, 'minutes') |
||
| 55 | . " " . |
||
| 56 | Lang::get($this->language, 'ago'); |
||
| 57 | } |
||
| 58 | } |
||
| 59 | //Hours |
||
| 60 | else if($this->hour <=24){ |
||
| 61 | View Code Duplication | if($this->hour==1){ |
|
| 62 | return Lang::get($this->language, 'an-hour') . " " . |
||
| 63 | Lang::get($this->language, 'ago'); |
||
| 64 | }else{ |
||
| 65 | return "$this->hour " . Lang::get($this->language, 'hours') |
||
| 66 | . " " . |
||
| 67 | Lang::get($this->language, 'ago'); |
||
| 68 | } |
||
| 69 | } |
||
| 70 | //Days |
||
| 71 | else if($this->day <= 7){ |
||
| 72 | if($this->day==1){ |
||
| 73 | return Lang::get($this->language, 'yesterday'); |
||
| 74 | }else{ |
||
| 75 | return "$this->day " . Lang::get($this->language, 'days') |
||
| 76 | . " " . |
||
| 77 | Lang::get($this->language, 'ago'); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | //Weeks |
||
| 81 | else if($this->week <= 4.3){ |
||
| 82 | View Code Duplication | if($this->week==1){ |
|
| 83 | return Lang::get($this->language, 'a-week') . " " . |
||
| 84 | Lang::get($this->language, 'ago'); |
||
| 85 | }else{ |
||
| 86 | return "$this->week " . Lang::get($this->language, 'weeks') |
||
| 87 | . " " . |
||
| 88 | Lang::get($this->language, 'ago'); |
||
| 89 | } |
||
| 90 | } |
||
| 91 | //Months |
||
| 92 | else if($this->month <=12){ |
||
| 93 | View Code Duplication | if($this->month==1){ |
|
| 94 | return Lang::get($this->language, 'a-month') . " " . |
||
| 95 | Lang::get($this->language, 'ago'); |
||
| 96 | }else{ |
||
| 97 | return "$this->month " . Lang::get($this->language, 'months') |
||
| 98 | . " " . |
||
| 99 | Lang::get($this->language, 'ago'); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | //Years |
||
| 103 | View Code Duplication | else{ |
|
| 104 | if($this->year==1){ |
||
| 105 | return Lang::get($this->language, 'one-year') . " " . |
||
| 106 | Lang::get($this->language, 'ago'); |
||
| 107 | }else{ |
||
| 108 | return "$this->year " . Lang::get($this->language, 'years') |
||
| 109 | . " " . |
||
| 110 | Lang::get($this->language, 'ago'); |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | } |
||
| 115 | |||
| 117 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.