Conditions | 10 |
Paths | 66 |
Total Lines | 27 |
Code Lines | 16 |
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 |
||
32 | public function render() |
||
33 | { |
||
34 | $iface = '\Aimeos\Base\View\Iface'; |
||
35 | $view = $this->templateVariableContainer->get('_aimeos_view'); |
||
36 | |||
37 | if (!is_object($view) || !($view instanceof $iface)) { |
||
38 | throw new Exception('Aimeos view object is missing'); |
||
39 | } |
||
40 | |||
41 | if (!isset($this->arguments['singular'])) { |
||
42 | throw new Exception('Attribute "singular" missing for Aimeos translate view helper'); |
||
43 | } |
||
44 | |||
45 | $singular = $this->arguments['singular']; |
||
46 | $plural = (isset($this->arguments['plural']) ? $this->arguments['plural'] : ''); |
||
47 | $number = (isset($this->arguments['number']) ? $this->arguments['number'] : 1); |
||
48 | $escape = (isset($this->arguments['escape']) ? $this->arguments['escape'] : true); |
||
49 | $domain = (isset($this->arguments['domain']) ? $this->arguments['domain'] : 'client'); |
||
50 | $values = (isset($this->arguments['arguments']) ? $this->arguments['arguments'] : []); |
||
51 | |||
52 | $string = vsprintf($view->translate($domain, $singular, $plural, $number), (array) $values); |
||
53 | |||
54 | if ($escape === false) { |
||
55 | return $string; |
||
56 | } |
||
57 | |||
58 | return $view->encoder()->html($string); |
||
59 | } |
||
60 | } |