Conditions | 10 |
Paths | 24 |
Total Lines | 42 |
Code Lines | 21 |
Lines | 22 |
Ratio | 52.38 % |
Changes | 4 | ||
Bugs | 2 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
74 | public function toString() { |
||
75 | $text = ''; |
||
76 | $args = array(); |
||
77 | |||
78 | $start_date = FALSE; |
||
79 | $end_date = FALSE; |
||
80 | |||
81 | // Day of the week constraint variable. |
||
82 | $day_of_the_week = $this->getWeekDay($this->checkin_day); |
||
83 | |||
84 | // Date range constraint variables. |
||
85 | View Code Duplication | if ($this->start_date !== NULL && $this->start_date != (new \DateTime('1970-01-01'))) { |
|
86 | $start_date = $this->start_date->format('Y-m-d'); |
||
87 | } |
||
88 | View Code Duplication | if ($this->end_date !== NULL && $this->end_date != (new \DateTime('2999-12-31'))) { |
|
89 | $end_date = $this->end_date->format('Y-m-d'); |
||
90 | } |
||
91 | |||
92 | // Finally, build out the constraint text string adding components |
||
93 | // as necessary. |
||
94 | |||
95 | // Specify a date range constraint. |
||
96 | View Code Duplication | if ($start_date && $end_date) { |
|
97 | $text = 'From @start_date to @end_date'; |
||
98 | |||
99 | $args['@start_date'] = $start_date; |
||
100 | $args['@end_date'] = $end_date; |
||
101 | } |
||
102 | |||
103 | // Specify the day of the week constraint. |
||
104 | View Code Duplication | if ($day_of_the_week) { |
|
105 | if ($start_date && $end_date) { |
||
106 | $text = 'From @start_date to @end_date, bookings must start on @day_of_the_week'; |
||
107 | } else { |
||
108 | $text = 'Bookings must start on @day_of_the_week'; |
||
109 | } |
||
110 | |||
111 | $args['@day_of_the_week'] = $day_of_the_week; |
||
112 | } |
||
113 | |||
114 | return array('text' => $text, 'args' => $args); |
||
115 | } |
||
116 | |||
150 |
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.