Conditions | 7 |
Paths | 34 |
Total Lines | 57 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
62 | protected function conversion() |
||
63 | { |
||
64 | // Calculate total days from reference Nepali date |
||
65 | $total_bs_days = $this->calculateTotalNepaliDays($this->nep_year, $this->nep_month, $this->nep_day); |
||
66 | |||
67 | // Initialize with reference English date (corresponding to Nepali 2000-01-01) |
||
68 | // CORRECTED: Adjusted the reference date to fix the one-day offset |
||
69 | $initial_english_year = 1943; |
||
70 | $initial_english_month = 4; |
||
71 | $initial_english_day = 13; // Changed from 14 to 13 |
||
72 | $dayOfWeek = $this->dayOfWeek; |
||
73 | |||
74 | // Set initial values |
||
75 | $english_year = $initial_english_year; |
||
76 | $english_month = $initial_english_month; |
||
77 | $english_day = $initial_english_day; |
||
78 | |||
79 | // Process each day |
||
80 | while ($total_bs_days != 0) { |
||
81 | // Increment the English date by one day |
||
82 | $english_day++; |
||
83 | $dayOfWeek++; |
||
84 | |||
85 | // Handle day of week wraparound |
||
86 | if ($dayOfWeek > 7) { |
||
87 | $dayOfWeek = 1; |
||
88 | } |
||
89 | |||
90 | // Handle month transition |
||
91 | $days_in_month = $this->is_leap_year($english_year) ? |
||
92 | $this->leapMonths[$english_month - 1] : |
||
93 | $this->normalMonths[$english_month - 1]; |
||
94 | |||
95 | if ($english_day > $days_in_month) { |
||
96 | $english_month++; |
||
97 | $english_day = 1; |
||
98 | } |
||
99 | |||
100 | // Handle year transition |
||
101 | if ($english_month > 12) { |
||
102 | $english_year++; |
||
103 | $english_month = 1; |
||
104 | } |
||
105 | |||
106 | // Update object properties |
||
107 | $this->year = $english_year; |
||
108 | $this->month = $english_month; |
||
109 | $this->day = $english_day; |
||
110 | $this->dayOfWeek = $dayOfWeek; |
||
111 | |||
112 | $total_bs_days--; |
||
113 | } |
||
114 | $date = Carbon::create($this->year, $this->month, $this->day); |
||
115 | if ($date != false) { |
||
116 | $this->date = $date; |
||
117 | } else { |
||
118 | throw new \Exception('Invalid date'); |
||
119 | } |
||
127 |