| Conditions | 10 |
| Paths | 32 |
| Total Lines | 107 |
| Code Lines | 43 |
| Lines | 48 |
| Ratio | 44.86 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 3 |
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 namespace Datium\Tools; |
||
| 106 | |||
| 107 | $this->month = $this->date_time->format('m'); |
||
| 108 | |||
| 109 | $this->day = $this->date_time->format('d'); |
||
| 110 | |||
| 111 | $days_of_year = 0; |
||
| 112 | |||
| 113 | foreach ( $this->config['shamsi_month_days'] as $month => $value ) { |
||
| 114 | |||
| 115 | if( $this->month > $month ) $days_of_year += $value; |
||
| 116 | |||
| 117 | } |
||
| 118 | |||
| 119 | $days_of_year += $this->day; |
||
| 120 | |||
| 121 | $days_of_leap_years = intval( ( ( $this->year - 1 ) / 4 ) ); |
||
| 122 | |||
| 123 | $days_of_shamsi_years = ( ( ( $this->year - 1 ) * 365 ) + $days_of_year + $days_of_leap_years ); |
||
| 124 | |||
| 125 | $days_of_gregorain_years = $days_of_shamsi_years + 226899; |
||
| 126 | |||
| 127 | if ( $this->month < 10 ) { |
||
| 128 | |||
| 129 | $days_of_gregorain_years = $days_of_gregorain_years - intval( ( ( $this->year + 621 ) / 4 ) ); |
||
| 130 | |||
| 131 | } |
||
| 132 | |||
| 133 | elseif ( ( ( 10 == $this->month ) && ( $this->day > 10 ) ) || ( $this->month > 10 ) ) { |
||
| 134 | |||
| 135 | $days_of_gregorain_years = $days_of_gregorain_years - intval( ( ( $this->year + 622 ) / 4 ) ); |
||
| 136 | |||
| 137 | } |
||
| 138 | |||
| 139 | $gregorian_month = ( $days_of_gregorain_years % 365 ); |
||
| 140 | |||
| 141 | $gregorian_year = intval( $days_of_gregorain_years / 365 ) + 1; |
||
| 142 | |||
| 143 | foreach ($this->config['gregorian_month_days'] as $month => $value) { |
||
| 144 | |||
| 145 | if ( $gregorian_month < $value ) break; |
||
| 146 | |||
| 147 | $gregorian_month -= $value; |
||
| 148 | } |
||
| 149 | |||
| 150 | $gregorian_day = $gregorian_month; |
||
| 151 | |||
| 152 | $gregorian_month = $month; |
||
| 153 | |||
| 154 | $this->date_time->setDate( $gregorian_year, $gregorian_month, $gregorian_day ); |
||
| 155 | |||
| 156 | |||
| 157 | return $this->date_time; |
||
| 158 | |||
| 159 | } |
||
| 160 | |||
| 161 | /** |
||
| 162 | *convert shamsi year to ghamari year |
||
| 163 | * @since Oct, 17 2015 |
||
| 164 | * @return object |
||
| 165 | */ |
||
| 166 | public function shamsiToGhamari( $date_time ) { |
||
| 167 | |||
| 168 | $this->date_time = $date_time; |
||
| 169 | |||
| 170 | $this->year = $this->date_time->format('Y'); |
||
| 171 | |||
| 172 | $this->month = $this->date_time->format('n'); |
||
| 173 | |||
| 174 | $this->day = $this->date_time->format('d'); |
||
| 175 | |||
| 176 | $this->temp_day = 0 ; |
||
| 177 | |||
| 178 | for ( $i = 1 ; $i < $this->month ; $i++ ) { |
||
| 179 | |||
| 180 | $this->temp_day += $this->config['shamsi_month_days'][$i]; |
||
| 181 | |||
| 182 | } |
||
| 183 | |||
| 184 | $this->temp_day += $this->day; |
||
| 185 | |||
| 186 | $this->leap = new Leap( $this->year ); |
||
| 187 | |||
| 188 | if( $this->leap->get() && $this->month > 11 ) $this->temp_day++; |
||
| 189 | |||
| 190 | $_year = ( ( ( ( ( $this->year - 1 ) * 365.2422 ) + $this->temp_day ) - 119) / 354.3670 ) + 1; |
||
| 191 | |||
| 192 | $_year = explode( '.', $_year ); |
||
| 193 | |||
| 194 | $this->year = $_year[0]; |
||
| 195 | |||
| 196 | $_month = $_year[1]; |
||
| 197 | |||
| 198 | $var_temp = '0.0'; |
||
| 199 | |||
| 200 | for ( $i = strlen( $_month ); $i > 2; $i-- ) { |
||
| 201 | |||
| 202 | $var_temp .= '0'; |
||
| 203 | |||
| 204 | } |
||
| 205 | |||
| 206 | $var_temp .= '1'; |
||
| 207 | |||
| 208 | $_month = $_month * $var_temp ; |
||
| 209 | |||
| 210 | $_month = ( $_month * 12 ) + 1; |
||
| 211 | |||
| 212 | $_month = explode( '.', $_month ); |
||
| 213 | |||
| 352 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: