Conditions | 15 |
Paths | 240 |
Total Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
49 | public function process($name = 'default', $start = null, $skip = null, $direction = null, $print = null, $assign = null) |
||
50 | { |
||
51 | // init counter |
||
52 | if (!isset($this->counters[$name])) { |
||
53 | $this->counters[$name] = array( |
||
54 | 'count' => $start === null ? 1 : (int)$start, |
||
55 | 'skip' => $skip === null ? 1 : (int)$skip, |
||
56 | 'print' => $print === null ? true : (bool)$print, |
||
57 | 'assign' => $assign === null ? null : (string)$assign, |
||
58 | 'direction' => strtolower($direction) === 'down' ? - 1 : 1, |
||
59 | ); |
||
60 | } // increment |
||
61 | else { |
||
62 | // override setting if present |
||
63 | if ($skip !== null) { |
||
64 | $this->counters[$name]['skip'] = (int)$skip; |
||
65 | } |
||
66 | |||
67 | if ($direction !== null) { |
||
68 | $this->counters[$name]['direction'] = strtolower($direction) === 'down' ? - 1 : 1; |
||
69 | } |
||
70 | |||
71 | if ($print !== null) { |
||
72 | $this->counters[$name]['print'] = (bool)$print; |
||
73 | } |
||
74 | |||
75 | if ($assign !== null) { |
||
76 | $this->counters[$name]['assign'] = (string)$assign; |
||
77 | } |
||
78 | |||
79 | if ($start !== null) { |
||
80 | $this->counters[$name]['count'] = (int)$start; |
||
81 | } else { |
||
82 | $this->counters[$name]['count'] += ($this->counters[$name]['skip'] * $this->counters[$name]['direction']); |
||
83 | } |
||
84 | } |
||
85 | |||
86 | $out = $this->counters[$name]['count']; |
||
87 | |||
88 | if ($this->counters[$name]['assign'] !== null) { |
||
89 | $this->core->assignInScope($out, $this->counters[$name]['assign']); |
||
90 | } elseif ($this->counters[$name]['print'] === true) { |
||
91 | return $out; |
||
92 | } |
||
93 | } |
||
94 | } |
||
95 |