Conditions | 15 |
Paths | 128 |
Total Lines | 44 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
37 | private function _generatorBirthdayCode($addressCode, $address, $birthday) |
||
38 | { |
||
39 | $start_year = '0001'; |
||
40 | $end_year = '9999'; |
||
41 | $year = $this->_datePad(substr($birthday, 0, 4), 'year'); |
||
42 | $month = $this->_datePad(substr($birthday, 4, 2), 'month'); |
||
43 | $day = $this->_datePad(substr($birthday, 6, 2), 'day'); |
||
44 | |||
45 | if ($year < 1800 || $year > date('Y')) { |
||
46 | $year = $this->_datePad(mt_rand(1950, date('Y') - 1), 'year'); |
||
47 | } |
||
48 | |||
49 | if (isset($this->_addressCodeTimeline[$addressCode])) { |
||
50 | $timeline = $this->_addressCodeTimeline[$addressCode]; |
||
51 | foreach ($timeline as $key => $val) { |
||
52 | if ($val['address'] == $address) { |
||
53 | $start_year = $val['start_year'] != '' ? $val['start_year'] : $start_year; |
||
54 | $end_year = $val['end_year'] != '' ? $val['end_year'] : $end_year; |
||
55 | } |
||
56 | } |
||
57 | } |
||
58 | |||
59 | if ($year < $start_year) { |
||
60 | $year = $start_year; |
||
61 | } |
||
62 | if ($year > $end_year) { |
||
63 | $year = $end_year; |
||
64 | } |
||
65 | |||
66 | if ($month < 1 || $month > 12) { |
||
67 | $month = $this->_datePad(mt_rand(1, 12), 'month'); |
||
68 | } |
||
69 | |||
70 | if ($day < 1 || $day > 31) { |
||
71 | $day = $this->_datePad(mt_rand(1, 28), 'day'); |
||
72 | } |
||
73 | |||
74 | if (!checkdate((int) $month, (int) $day, (int) $year)) { |
||
75 | $year = $this->_datePad(mt_rand(max($start_year, 1950), min($end_year, date('Y')) - 1), 'year'); |
||
76 | $month = $this->_datePad(mt_rand(1, 12), 'month'); |
||
77 | $day = $this->_datePad(mt_rand(1, 28), 'day'); |
||
78 | } |
||
79 | |||
80 | return $year.$month.$day; |
||
81 | } |
||
204 |