Conditions | 15 |
Paths | 48 |
Total Lines | 59 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
87 | public function render($data, $citationNumber = null): string |
||
88 | { |
||
89 | $lang = (isset($data->language) && $data->language != 'en') ? $data->language : 'en'; |
||
90 | |||
91 | if (empty($this->variable) || empty($data->{$this->variable})) { |
||
92 | return ""; |
||
93 | } |
||
94 | $number = $data->{$this->variable}; |
||
95 | $decimalNumber = $this->toDecimalNumber($number); |
||
96 | switch ($this->form) { |
||
97 | case 'ordinal': |
||
98 | if (preg_match(self::PATTERN_ORDINAL, $decimalNumber, $matches)) { |
||
99 | $num1 = self::ordinal($matches[1]); |
||
100 | $num2 = self::ordinal($matches[3]); |
||
101 | $text = $this->buildNumberRangeString($num1, $num2, $matches[2]); |
||
102 | } else { |
||
103 | $text = self::ordinal($decimalNumber); |
||
104 | } |
||
105 | break; |
||
106 | case 'long-ordinal': |
||
107 | if (preg_match(self::PATTERN_LONG_ORDINAL, $decimalNumber, $matches)) { |
||
108 | if ($this->textCase === "capitalize-first" || $this->textCase === "sentence") { |
||
109 | $num1 = self::longOrdinal($matches[1]); |
||
110 | $num2 = self::longOrdinal($matches[3]); |
||
111 | } else { |
||
112 | $num1 = $this->applyTextCase(self::longOrdinal($matches[1])); |
||
113 | $num2 = $this->applyTextCase(self::longOrdinal($matches[3])); |
||
114 | } |
||
115 | $text = $this->buildNumberRangeString($num1, $num2, $matches[2]); |
||
116 | } else { |
||
117 | $text = self::longOrdinal($decimalNumber); |
||
118 | } |
||
119 | break; |
||
120 | case 'roman': |
||
121 | if (preg_match(self::PATTERN_ROMAN, $decimalNumber, $matches)) { |
||
122 | $num1 = Util\NumberHelper::dec2roman($matches[1]); |
||
123 | $num2 = Util\NumberHelper::dec2roman($matches[3]); |
||
124 | $text = $this->buildNumberRangeString($num1, $num2, $matches[2]); |
||
125 | } else { |
||
126 | $text = Util\NumberHelper::dec2roman($decimalNumber); |
||
127 | } |
||
128 | break; |
||
129 | case 'numeric': |
||
130 | default: |
||
131 | /* |
||
132 | During the extraction, numbers separated by a hyphen are stripped of intervening spaces (“2 - 4” |
||
133 | becomes “2-4”). Numbers separated by a comma receive one space after the comma (“2,3” and “2 , 3” |
||
134 | become “2, 3”), while numbers separated by an ampersand receive one space before and one after the |
||
135 | ampersand (“2&3” becomes “2 & 3”). |
||
136 | */ |
||
137 | $decimalNumber = $data->{$this->variable}; |
||
138 | if (preg_match(self::PATTERN_NUMERIC_DEFAULT, $decimalNumber, $matches)) { |
||
139 | $text = $this->buildNumberRangeString($matches[1], $matches[3], $matches[2]); |
||
140 | } else { |
||
141 | $text = $decimalNumber; |
||
142 | } |
||
143 | break; |
||
144 | } |
||
145 | return $this->wrapDisplayBlock($this->addAffixes($this->format($this->applyTextCase($text, $lang)))); |
||
146 | } |
||
226 |