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 |
|||||||||||
2 | /** |
|||||||||||
3 | * Created by PhpStorm. |
|||||||||||
4 | * User: ignatenkov |
|||||||||||
5 | * Date: 21.08.15 |
|||||||||||
6 | * Time: 1:28 |
|||||||||||
7 | */ |
|||||||||||
8 | ||||||||||||
9 | namespace YaWeather\Models; |
|||||||||||
10 | ||||||||||||
11 | ||||||||||||
12 | class Day{ |
|||||||||||
13 | ||||||||||||
14 | const TYPE_MORNING = 1; |
|||||||||||
15 | const TYPE_DAY = 2; |
|||||||||||
16 | const TYPE_EVENING = 3; |
|||||||||||
17 | const TYPE_NIGHT = 4; |
|||||||||||
18 | const TYPE_DAY_SHORT = 5; |
|||||||||||
19 | const TYPE_NIGHT_SHORT = 6; |
|||||||||||
20 | ||||||||||||
21 | const HOUR_NIGHT = 6; |
|||||||||||
22 | const HOUR_MORNING = 12; |
|||||||||||
23 | const HOUR_DAY = 18; |
|||||||||||
24 | const HOUR_EVENING = 23; |
|||||||||||
25 | ||||||||||||
26 | ||||||||||||
27 | public $sunrise; |
|||||||||||
28 | public $sunset; |
|||||||||||
29 | public $moon_phase; |
|||||||||||
30 | ||||||||||||
31 | public $morning; |
|||||||||||
32 | public $day; |
|||||||||||
33 | public $evening; |
|||||||||||
34 | public $night; |
|||||||||||
35 | public $day_short; |
|||||||||||
36 | public $night_short; |
|||||||||||
37 | ||||||||||||
38 | /** |
|||||||||||
39 | * |
|||||||||||
40 | * @param $value |
|||||||||||
41 | * @param bool $weekend |
|||||||||||
42 | * @return bool |
|||||||||||
43 | */ |
|||||||||||
44 | public static function CheckWeekend($value, $weekend = false) |
|||||||||||
45 | { |
|||||||||||
46 | $dayNumber = date('w', strtotime($value)); |
|||||||||||
47 | if($weekend && ($dayNumber == 0 || $dayNumber == 6)) |
|||||||||||
48 | return true; |
|||||||||||
49 | elseif ($weekend == false && $dayNumber == 0) |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
50 | return true; |
|||||||||||
51 | else |
|||||||||||
52 | return false; |
|||||||||||
53 | } |
|||||||||||
54 | ||||||||||||
55 | public static function getDayNumber($value) { |
|||||||||||
56 | return $str = date('j', strtotime($value)); |
|||||||||||
0 ignored issues
–
show
$str is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
||||||||||||
57 | } |
|||||||||||
58 | ||||||||||||
59 | public static function getMonthName($value) { |
|||||||||||
60 | $listMonths = ['','января','февраля','марта','апреля','мая','июня','июля','августа','сентября','октября','ноября','декабря']; |
|||||||||||
61 | return $listMonths[date("n", strtotime($value))]; |
|||||||||||
62 | } |
|||||||||||
63 | ||||||||||||
64 | public static function getDayName($value) { |
|||||||||||
65 | $str = ""; |
|||||||||||
0 ignored issues
–
show
$str is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
||||||||||||
66 | ||||||||||||
67 | $listDays = ['вс','пн', 'вт', 'ср', 'чт', 'пт', 'сб']; |
|||||||||||
68 | ||||||||||||
69 | $date = Date('d.m.Y', strtotime("+1 days")); |
|||||||||||
70 | $match_date = date('d.m.Y', strtotime($value)); |
|||||||||||
71 | ||||||||||||
72 | if($date == $match_date) |
|||||||||||
73 | $str = "Завтра"; |
|||||||||||
74 | else { |
|||||||||||
75 | $str = $listDays[date("w", strtotime($value))]; |
|||||||||||
76 | ||||||||||||
77 | //return $this->days[date('w', $date)].', '.(int)date('d',$date).' '.$this->months[date('n', $date)]; |
|||||||||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
70% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
||||||||||||
78 | } |
|||||||||||
79 | ||||||||||||
80 | ||||||||||||
81 | return $str; |
|||||||||||
82 | ||||||||||||
83 | } |
|||||||||||
84 | ||||||||||||
85 | public function AdditionalState() |
|||||||||||
86 | { |
|||||||||||
87 | $arrAdditionWeather = []; |
|||||||||||
88 | $hour = date("G"); |
|||||||||||
89 | View Code Duplication | if ($hour > self::HOUR_EVENING OR $hour <= self::HOUR_NIGHT) { |
||||||||||
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() Comprehensibility
Best Practice
introduced
by
Using logical operators such as
or instead of || is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
90 | $arrAdditionWeather["Утром"] = $this->morning; |
|||||||||||
91 | $arrAdditionWeather["Днём"] = $this->day; |
|||||||||||
92 | } |
|||||||||||
93 | View Code Duplication | if ($hour > self::HOUR_NIGHT && $hour <= self::HOUR_MORNING) { |
||||||||||
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
||||||||||||
94 | $arrAdditionWeather["Днём"] = $this->day; |
|||||||||||
95 | $arrAdditionWeather["Вечером"] = $this->evening; |
|||||||||||
96 | } |
|||||||||||
97 | View Code Duplication | if ($hour > self::HOUR_MORNING && $hour <= self::HOUR_DAY) { |
||||||||||
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
||||||||||||
98 | $arrAdditionWeather["Вечером"] = $this->evening; |
|||||||||||
99 | $arrAdditionWeather["Ночью"] = $this->night; |
|||||||||||
100 | } |
|||||||||||
101 | View Code Duplication | if ($hour > self::HOUR_DAY && $hour <= self::HOUR_EVENING) { |
||||||||||
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
||||||||||||
102 | $arrAdditionWeather["Ночью"] = $this->night; |
|||||||||||
103 | $arrAdditionWeather["Утром"] = $this->morning; |
|||||||||||
104 | } |
|||||||||||
105 | ||||||||||||
106 | return $arrAdditionWeather; |
|||||||||||
107 | } |
|||||||||||
108 | ||||||||||||
109 | public function getListDetail() { |
|||||||||||
110 | return ["Утром" => $this->morning, "Днём" => $this->day, "Вечером" => $this->evening, "Ночью" => $this->night]; |
|||||||||||
111 | } |
|||||||||||
112 | ||||||||||||
113 | } |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.