opencafe /
datium
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php namespace OpenCafe\Tools; |
||
| 2 | |||
| 3 | /************************************************************ |
||
| 4 | * Convert Calendars types together |
||
| 5 | ************************************************************ |
||
| 6 | * |
||
| 7 | * @since Oct 27, 2015 |
||
| 8 | * |
||
| 9 | *\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ |
||
| 10 | */ |
||
| 11 | class Convert |
||
| 12 | { |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var integer |
||
| 16 | */ |
||
| 17 | protected $year; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var integer |
||
| 21 | */ |
||
| 22 | protected $month; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var $day |
||
| 26 | */ |
||
| 27 | protected $day; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var DateTime |
||
| 31 | */ |
||
| 32 | public $date_time; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var array |
||
| 36 | */ |
||
| 37 | protected $config; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var integer |
||
| 41 | */ |
||
| 42 | protected $leap; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var integer |
||
| 46 | */ |
||
| 47 | protected $temp_day; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var DateTime |
||
| 51 | */ |
||
| 52 | protected $date; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var array |
||
| 56 | */ |
||
| 57 | protected $calendar_file; |
||
| 58 | |||
| 59 | /************************************************************ |
||
| 60 | * Convert class constructor |
||
| 61 | ************************************************************ |
||
| 62 | * |
||
| 63 | * @since Oct 27, 2015 |
||
| 64 | * |
||
| 65 | *\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ |
||
| 66 | */ |
||
| 67 | public function __construct($date_time = null) |
||
| 68 | { |
||
| 69 | |||
| 70 | if ($date_time !== null) { |
||
| 71 | $this->date_time = $date_time; |
||
| 72 | } |
||
| 73 | |||
| 74 | $this->config = include __DIR__.'/Config.php'; |
||
| 75 | |||
| 76 | } |
||
| 77 | |||
| 78 | View Code Duplication | public function from($calendar) |
|
| 79 | { |
||
| 80 | |||
| 81 | $this->calendar_file = include __DIR__.'/CalendarSettings/' . ucfirst($calendar) . '.php'; |
||
| 82 | |||
| 83 | return $this->calendar_file[ 'convert_from' ]( $this->date_time ); |
||
| 84 | |||
| 85 | } |
||
| 86 | |||
| 87 | /************************************************************ |
||
| 88 | * Convert to specific calendar |
||
| 89 | ************************************************************ |
||
| 90 | * |
||
| 91 | * @since Oct 26, 2015 |
||
| 92 | * |
||
| 93 | *\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ |
||
| 94 | */ |
||
| 95 | View Code Duplication | public function to($calendar) |
|
| 96 | { |
||
| 97 | |||
| 98 | $this->calendar_file = include __DIR__.'/CalendarSettings/' . ucfirst($calendar) . '.php'; |
||
| 99 | |||
| 100 | return $this->calendar_file[ 'convert_to' ]( $this->date_time ); |
||
| 101 | |||
| 102 | } |
||
| 103 | |||
| 104 | /** |
||
| 105 | *convert jalali year to gregorian year |
||
| 106 | * |
||
| 107 | * @since Oct, 16 2015 |
||
| 108 | * @return object |
||
| 109 | */ |
||
| 110 | public function jalaliToGregorian($date_time) |
||
| 111 | { |
||
| 112 | |||
| 113 | $this->config = include __DIR__.'/Jalali.php'; |
||
| 114 | |||
| 115 | $this->date_time = $date_time; |
||
| 116 | |||
| 117 | $this->year = $this->date_time->format('Y'); |
||
| 118 | |||
| 119 | $this->month = $this->date_time->format('m'); |
||
| 120 | |||
| 121 | $this->day = $this->date_time->format('d'); |
||
| 122 | |||
| 123 | $days_of_year = 0; |
||
| 124 | |||
| 125 | foreach ($this->config[ 'month_days_number' ] as $month => $value) { |
||
| 126 | if ($this->month > $month) { |
||
| 127 | $days_of_year += $value; |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | $days_of_year += $this->day; |
||
| 132 | |||
| 133 | $days_of_leap_years = intval(( ( $this->year - 1 ) / 4 )); |
||
| 134 | |||
| 135 | $days_of_jalali_years = ( ( ( $this->year - 1 ) * 365 ) + $days_of_year + $days_of_leap_years ); |
||
| 136 | |||
| 137 | $days_of_gregorain_years = $days_of_jalali_years + 226899; |
||
| 138 | |||
| 139 | if ($this->month < 10) { |
||
| 140 | $days_of_gregorain_years = $days_of_gregorain_years - intval(( ( $this->year + 621 ) / 4 )); |
||
| 141 | } elseif (( ( 10 == $this->month ) && ( $this->day > 10 ) ) || ( $this->month > 10 )) { |
||
| 142 | $days_of_gregorain_years = $days_of_gregorain_years - intval(( ( $this->year + 622 ) / 4 )); |
||
| 143 | } |
||
| 144 | |||
| 145 | $gregorian_month = ( $days_of_gregorain_years % 365 ); |
||
| 146 | |||
| 147 | $gregorian_year = intval($days_of_gregorain_years / 365) + 1; |
||
| 148 | |||
| 149 | $this->config = include __DIR__.'/Gregorian.php'; |
||
| 150 | |||
| 151 | foreach ($this->config[ 'month_days_number' ] as $month => $value) { |
||
| 152 | if ($gregorian_month < $value) { |
||
| 153 | break; |
||
| 154 | } |
||
| 155 | |||
| 156 | $gregorian_month -= $value; |
||
| 157 | } |
||
| 158 | |||
| 159 | $gregorian_day = $gregorian_month; |
||
| 160 | |||
| 161 | $gregorian_month = $month; |
||
|
0 ignored issues
–
show
|
|||
| 162 | |||
| 163 | $this->date_time->setDate($gregorian_year, $gregorian_month, $gregorian_day); |
||
| 164 | |||
| 165 | |||
| 166 | return $this->date_time; |
||
| 167 | |||
| 168 | } |
||
| 169 | |||
| 170 | /** |
||
| 171 | *convert jalali year to hijri year |
||
| 172 | * |
||
| 173 | * @since Oct, 17 2015 |
||
| 174 | * @return object |
||
| 175 | */ |
||
| 176 | public function jalaliToHijri($date_time) |
||
| 177 | { |
||
| 178 | |||
| 179 | $this->date_time = $date_time; |
||
| 180 | |||
| 181 | $this->year = $this->date_time->format('Y'); |
||
| 182 | |||
| 183 | $this->month = $this->date_time->format('n'); |
||
| 184 | |||
| 185 | $this->day = $this->date_time->format('d'); |
||
| 186 | |||
| 187 | $this->temp_day = 0 ; |
||
| 188 | |||
| 189 | $this->config = include __DIR__.'/Jalali.php'; |
||
| 190 | |||
| 191 | for ($i = 1; $i < $this->month; $i++) { |
||
| 192 | $this->temp_day += $this->config['month_days_number'][$i]; |
||
| 193 | } |
||
| 194 | |||
| 195 | $this->temp_day += $this->day; |
||
| 196 | |||
| 197 | $this->leap = new Leap($this->year); |
||
|
0 ignored issues
–
show
It seems like
new \OpenCafe\Tools\Leap($this->year) of type object<OpenCafe\Tools\Leap> is incompatible with the declared type integer of property $leap.
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. Loading history...
|
|||
| 198 | |||
| 199 | if ($this->leap->get() && $this->month > 11) { |
||
| 200 | $this->temp_day++; |
||
| 201 | } |
||
| 202 | |||
| 203 | $_year = ( ( ( ( ( $this->year - 1 ) * 365.2422 ) + $this->temp_day ) - 119) / 354.3670 ) + 1; |
||
| 204 | |||
| 205 | $_year = explode('.', $_year); |
||
| 206 | |||
| 207 | $this->year = $_year[0]; |
||
| 208 | |||
| 209 | $_month = $_year[1]; |
||
| 210 | |||
| 211 | $var_temp = '0.0'; |
||
| 212 | |||
| 213 | for ($i = strlen($_month); $i > 2; $i--) { |
||
| 214 | $var_temp .= '0'; |
||
| 215 | } |
||
| 216 | |||
| 217 | $var_temp .= '1'; |
||
| 218 | |||
| 219 | $_month = $_month * $var_temp ; |
||
| 220 | |||
| 221 | $_month = ( $_month * 12 ) + 1; |
||
| 222 | |||
| 223 | $_month = explode('.', $_month); |
||
| 224 | |||
| 225 | $this->month = $_month[0]; |
||
| 226 | |||
| 227 | $_day = $_month[1]; |
||
| 228 | |||
| 229 | $var_temp = '0.0'; |
||
| 230 | |||
| 231 | for ($i = strlen($_day); $i > 2; $i--) { |
||
| 232 | $var_temp .= '0' ; |
||
| 233 | } |
||
| 234 | |||
| 235 | $var_temp .= '1'; |
||
| 236 | |||
| 237 | $_day = $_day * $var_temp; |
||
| 238 | |||
| 239 | $_day = ( $_day * 29.530 ); |
||
| 240 | |||
| 241 | $_day = explode('.', $_day); |
||
| 242 | |||
| 243 | $this->day = $_day[0]; |
||
| 244 | |||
| 245 | $this->date_time->setDate($this->year, $this->month, $this->day); |
||
| 246 | |||
| 247 | return $this->date_time; |
||
| 248 | |||
| 249 | } |
||
| 250 | |||
| 251 | /** |
||
| 252 | *convert hijri year to jalali year |
||
| 253 | * |
||
| 254 | * @since Oct, 17 2015 |
||
| 255 | * @return object |
||
| 256 | */ |
||
| 257 | View Code Duplication | public function hijriToJalali($date_time) |
|
| 258 | { |
||
| 259 | |||
| 260 | $this->date_time = $date_time; |
||
| 261 | |||
| 262 | $this->year = $this->date_time->format('Y'); |
||
| 263 | |||
| 264 | $this->month = $this->date_time->format('m'); |
||
| 265 | |||
| 266 | $this->day = $this->date_time->format('d'); |
||
| 267 | |||
| 268 | $days_of_year = 0; |
||
| 269 | |||
| 270 | $this->config = include __DIR__.'/Hijri.php'; |
||
| 271 | |||
| 272 | foreach ($this->config[ 'month_days_number' ] as $month => $value) { |
||
| 273 | if ($this->month > $month) { |
||
| 274 | $days_of_year += $value; |
||
| 275 | } |
||
| 276 | } |
||
| 277 | |||
| 278 | $days_of_year += $this->day; |
||
| 279 | |||
| 280 | $days_of_leap_years = intval(( ( $this->year - 1 ) / 3 )); |
||
| 281 | |||
| 282 | $days_of_hijri_years = ( ( ( $this->year - 1 ) * 354 ) + $days_of_year + $days_of_leap_years ); |
||
| 283 | |||
| 284 | $days_of_jalali_years = $days_of_hijri_years + 179; |
||
| 285 | |||
| 286 | $days_of_jalali_years = $days_of_jalali_years - intval(( ( $this->year - 43 ) / 4 )); |
||
| 287 | |||
| 288 | $jalali_month = ( $days_of_jalali_years % 365 ); |
||
| 289 | |||
| 290 | $jalali_year = intval($days_of_jalali_years / 365) + 1; |
||
| 291 | |||
| 292 | $this->config = include __DIR__.'/Jalali.php'; |
||
| 293 | |||
| 294 | foreach ($this->config[ 'month_days_number' ] as $month => $value) { |
||
| 295 | if ($jalali_month < $value) { |
||
| 296 | break; |
||
| 297 | } |
||
| 298 | |||
| 299 | $jalali_month -= $value; |
||
| 300 | } |
||
| 301 | |||
| 302 | $jalali_day = $jalali_month; |
||
| 303 | |||
| 304 | $jalali_month = $month; |
||
|
0 ignored issues
–
show
The variable
$month does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
Loading history...
|
|||
| 305 | |||
| 306 | $this->date_time->setDate($jalali_year, $jalali_month, $jalali_day); |
||
| 307 | |||
| 308 | return $this->date_time; |
||
| 309 | |||
| 310 | } |
||
| 311 | |||
| 312 | /** |
||
| 313 | * convert hijri year to gregorian year |
||
| 314 | * |
||
| 315 | * @since Oct, 17 2015 |
||
| 316 | * @return object |
||
| 317 | */ |
||
| 318 | View Code Duplication | public function hijriToGregorian($date_time) |
|
| 319 | { |
||
| 320 | |||
| 321 | $this->date_time = $date_time; |
||
| 322 | |||
| 323 | $this->year = $this->date_time->format('Y'); |
||
| 324 | |||
| 325 | $this->month = $this->date_time->format('m'); |
||
| 326 | |||
| 327 | $this->day = $this->date_time->format('d'); |
||
| 328 | |||
| 329 | $days_of_year = 0; |
||
| 330 | |||
| 331 | $this->config = include __DIR__.'/Hijri.php'; |
||
| 332 | |||
| 333 | foreach ($this->config[ 'month_days_number' ] as $month => $value) { |
||
| 334 | if ($this->month > $month) { |
||
| 335 | $days_of_year += $value; |
||
| 336 | } |
||
| 337 | } |
||
| 338 | |||
| 339 | $days_of_year += $this->day; |
||
| 340 | |||
| 341 | $days_of_leap_years = intval(( ( $this->year - 1 ) / 3 )); |
||
| 342 | |||
| 343 | $days_of_hijri_years = ( ( ( $this->year - 1 ) * 354 ) + $days_of_year + $days_of_leap_years ); |
||
| 344 | |||
| 345 | $days_of_gregorain_years = $days_of_hijri_years + 227078; |
||
| 346 | |||
| 347 | $days_of_gregorain_years = $days_of_gregorain_years - intval(( ( $this->year + 578 ) / 4 )); |
||
| 348 | |||
| 349 | $gregorian_month = ( $days_of_gregorain_years % 365 ); |
||
| 350 | |||
| 351 | $gregorian_year = intval($days_of_gregorain_years / 365) + 1; |
||
| 352 | |||
| 353 | $this->config = include __DIR__.'/Gregorian.php'; |
||
| 354 | |||
| 355 | foreach ($this->config[ 'month_days_number' ] as $month => $value) { |
||
| 356 | if ($gregorian_month < $value) { |
||
| 357 | break; |
||
| 358 | } |
||
| 359 | |||
| 360 | $gregorian_month -= $value; |
||
| 361 | } |
||
| 362 | |||
| 363 | $gregorian_day = $gregorian_month; |
||
| 364 | |||
| 365 | $gregorian_month = $month; |
||
|
0 ignored issues
–
show
The variable
$month does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
Loading history...
|
|||
| 366 | |||
| 367 | $this->date_time->setDate($gregorian_year, $gregorian_month, $gregorian_day); |
||
| 368 | |||
| 369 | return $this->date_time; |
||
| 370 | |||
| 371 | } |
||
| 372 | } |
||
| 373 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: