Day::CheckWeekend()   B
last analyzed

Complexity

Conditions 6
Paths 3

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 10
rs 8.8571
cc 6
eloc 8
nc 3
nop 2
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
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
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
Unused Code introduced by
$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 $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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
Unused Code introduced by
$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 $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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.

Loading history...
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
Duplication introduced by
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.

Loading history...
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):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

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-Flow

One 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 die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// 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.

Loading history...
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
Duplication introduced by
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.

Loading history...
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
Duplication introduced by
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.

Loading history...
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
Duplication introduced by
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.

Loading history...
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
}