Completed
Push — master ( f6fd8e...15d0ea )
by
unknown
11s
created

DayOf   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 75
Duplicated Lines 30.67 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 4
c 1
b 1
f 0
lcom 1
cbo 0
dl 23
loc 75
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A year() 8 8 1
A week() 8 8 1
A lastDayMonth() 7 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace OpenCafe\Tools;
4
5
/**
6
 * Define Day of current date.
7
 */
8
class DayOf
9
{
10
11
    protected $date_time;
12
13
    protected $month;
14
15
    protected $day;
16
17
    protected $config;
18
19
    protected $result;
20
21
    protected $calendar_type;
22
23
    protected $geregorian_DayofWeek;
24
25
    public function __construct($date_time, $calendar_type = 'gregorian')
26
    {
27
28
        $this->config = include __DIR__.'/Config.php';
29
30
        $this->date_time = $date_time;
31
32
        $this->calendar_type = $calendar_type;
33
34
        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...
35
36
    }
37
38
    /**
39
   * Which day of year is current day.
40
   *
41
   * @since  Aug, 03 2015
42
   * @return integer
43
   */
44 View Code Duplication
    public function year()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
45
    {
46
47
        $this->config = include __DIR__.'/CalendarSettings/' . ucfirst($this->calendar_type) . '.php';
48
49
        return $this->config[ 'day_of_year' ]( $this->date_time );
50
51
    }
52
53
54
    /**
55
   * Which day of week is current day.
56
   *
57
   * @since  Aug, 09 2015
58
   * @return integer
59
   */
60 View Code Duplication
    public function week()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
61
    {
62
63
        $this->config = include __DIR__.'/CalendarSettings/' . ucfirst($this->calendar_type) . '.php';
64
65
        return $this->config[ 'day_of_week' ]( $this->date_time );
66
67
    }
68
69
	/**
70
	 * Return last day of current month
71
	 *
72
	 * @since  Oct, 18 2016
73
	 * @return integer
74
	 */
75 View Code Duplication
	public function lastDayMonth() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
76
77
		$this->config = include __DIR__.'/CalendarSettings/' . ucfirst($this->calendar_type) . '.php';
78
79
		return $this->config[ 'month_days_number' ][ intval( $this->date_time->format( 'm' ) ) ];
80
81
	}
82
}
83