| Conditions | 10 |
| Paths | 66 |
| Total Lines | 27 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 47 | public function render() |
||
| 48 | { |
||
| 49 | $iface = '\Aimeos\MW\View\Iface'; |
||
| 50 | $view = $this->templateVariableContainer->get( '_aimeos_view' ); |
||
| 51 | |||
| 52 | if( !is_object( $view ) || !( $view instanceof $iface ) ) { |
||
| 53 | throw new Exception( 'Aimeos view object is missing' ); |
||
| 54 | } |
||
| 55 | |||
| 56 | if( !isset( $this->arguments['singular'] ) ) { |
||
| 57 | throw new Exception( 'Attribute "singular" missing for Aimeos translate view helper' ); |
||
| 58 | } |
||
| 59 | |||
| 60 | $singular = $this->arguments['singular']; |
||
| 61 | $plural = ( isset( $this->arguments['plural'] ) ? $this->arguments['plural'] : '' ); |
||
| 62 | $number = ( isset( $this->arguments['number'] ) ? $this->arguments['number'] : 1 ); |
||
| 63 | $escape = ( isset( $this->arguments['escape'] ) ? $this->arguments['escape'] : true ); |
||
| 64 | $domain = ( isset( $this->arguments['domain'] ) ? $this->arguments['domain'] : 'client' ); |
||
| 65 | $values = ( isset( $this->arguments['arguments'] ) ? $this->arguments['arguments'] : array() ); |
||
| 66 | |||
| 67 | $string = vsprintf( $view->translate( $domain, $singular, $plural, $number ), (array) $values ); |
||
| 68 | |||
| 69 | if( $escape === false ) { |
||
| 70 | return $string; |
||
| 71 | } |
||
| 72 | |||
| 73 | return $view->encoder()->html( $string ); |
||
| 74 | } |
||
| 75 | } |