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