Completed
Push — master ( 919af8 )
by mehdi
03:33 queued 01:46
created

DayOf::lastDayMonth()   C

Complexity

Conditions 7
Paths 9

Size

Total Lines 35
Code Lines 19

Duplication

Lines 16
Ratio 45.71 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 16
loc 35
rs 6.7272
cc 7
eloc 19
nc 9
nop 0
1
<?php
2
3
namespace OpenCafe\Tools;
4
5
/**
6
 * Define Day of current date.
7
 */
8
class DayOf
9
{
10
	/**
11
     * @var object
12
     */
13
    protected $date_time;
14
15
	/**
16
     * @var array
17
     */
18
    protected $config;
19
20
	/**
21
	 * @var string
22
	 */
23
	protected $calendar_type;
24
25
	/**
26
   	 * Constructor of DayOf class
27
     */
28
    public function __construct($date_time, $calendar_type = 'gregorian')
29
    {
30
31
		$this->config = include __DIR__.'/CalendarSettings/' . ucfirst($calendar_type) . '.php';
32
33
		$this->calendar_type = $calendar_type;
34
35
        $this->date_time = $date_time;
36
37
        return $this;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
38
39
    }
40
41
    /**
42
   * Which day of year is current day.
43
   *
44
   * @since  Aug, 03 2015
45
   * @return integer
46
   */
47
    public function year()
48
    {
49
50
        return $this->config[ 'day_of_year' ]( $this->date_time );
51
52
    }
53
54
55
    /**
56
   * Which day of week is current day.
57
   *
58
   * @since  Aug, 09 2015
59
   * @return integer
60
   */
61
    public function week()
62
    {
63
64
        return $this->config[ 'day_of_week' ]( $this->date_time );
65
66
    }
67
68
	/**
69
	 * Return last day of current month
70
	 *
71
	 * @since  Oct, 18 2016
72
	 * @return integer
73
	 */
74
	public function lastDayMonth() {
75
76
		$days = 0;
0 ignored issues
show
Unused Code introduced by
$days 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...
77
78
		switch ( $this->calendar_type ) {
79
80 View Code Duplication
			case 'gregorian':
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...
81
82
				$days = ( intval( $this->date_time->format( 'm' ) ) == 2 &&
83
				      	$this->config[ 'leap_year' ]( $this->date_time->format( 'Y' )) ) ?
84
						$this->config[ 'month_days_number' ][ intval( $this->date_time->format( 'm' ) ) ] + 1 :
85
						$this->config[ 'month_days_number' ][ intval( $this->date_time->format( 'm' ) ) ];
86
87
				break;
88
89 View Code Duplication
			case 'jalali':
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...
90
91
				$days = ( intval( $this->date_time->format( 'm' ) ) == 12 &&
92
				  		$this->config[ 'leap_year' ]( $this->date_time->format( 'Y' )) ) ?
93
				 	 	$this->config[ 'month_days_number' ][ intval( $this->date_time->format( 'm' ) ) ] + 1 :
94
					 	$this->config[ 'month_days_number' ][ intval( $this->date_time->format( 'm' ) ) ];
95
96
			  	break;
97
98
		  default:
99
100
			$days = $this->config[ 'month_days_number' ][ intval( $this->date_time->format( 'm' ) ) ];
101
102
			break;
103
104
		}
105
106
		return $days;
107
108
	}
109
}
110