Conditions | 15 |
Paths | 74 |
Total Lines | 50 |
Code Lines | 29 |
Lines | 12 |
Ratio | 24 % |
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 |
||
118 | public function displayVal($val, array $options = []) |
||
119 | { |
||
120 | if ($val === null || $val === '') { |
||
121 | return ''; |
||
122 | } |
||
123 | |||
124 | /** Parse multilingual values */ |
||
125 | if ($this->l10n()) { |
||
126 | $propertyValue = $this->l10nVal($val, $options); |
||
127 | if ($propertyValue === null) { |
||
128 | return ''; |
||
129 | } |
||
130 | } elseif ($val instanceof Translation) { |
||
131 | $propertyValue = (string)$val; |
||
132 | } else { |
||
133 | $propertyValue = $val; |
||
134 | } |
||
135 | |||
136 | $separator = $this->multipleSeparator(); |
||
137 | |||
138 | /** Parse multiple values / ensure they are of array type. */ |
||
139 | if ($this->multiple()) { |
||
140 | if (!is_array($propertyValue)) { |
||
141 | $propertyValue = explode($separator, $propertyValue); |
||
142 | } |
||
143 | } |
||
144 | |||
145 | if ($separator === ',') { |
||
146 | $separator = ', '; |
||
147 | } |
||
148 | |||
149 | if (is_array($propertyValue)) { |
||
150 | foreach ($propertyValue as &$value) { |
||
151 | View Code Duplication | if (is_string($value)) { |
|
152 | $value = $this->choiceLabel($value); |
||
153 | if (!is_string($value)) { |
||
154 | $value = $this->l10nVal($value, $options); |
||
155 | } |
||
156 | } |
||
157 | } |
||
158 | $propertyValue = implode($separator, $propertyValue); |
||
159 | View Code Duplication | } elseif (is_string($propertyValue)) { |
|
160 | $propertyValue = $this->choiceLabel($propertyValue); |
||
161 | if (!is_string($propertyValue)) { |
||
162 | $propertyValue = $this->l10nVal($propertyValue, $options); |
||
163 | } |
||
164 | } |
||
165 | |||
166 | return $propertyValue; |
||
167 | } |
||
168 | |||
220 |