Conditions | 12 |
Paths | 192 |
Total Lines | 38 |
Code Lines | 25 |
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 |
||
24 | public function toSyntax() |
||
25 | { |
||
26 | $title = ''; |
||
27 | if ($this->attrs['title']) { |
||
28 | $title = '|' . $this->attrs['title']; |
||
29 | } |
||
30 | |||
31 | $leftAlign = ''; |
||
32 | $rightAlign = ''; |
||
33 | if ($this->attrs['align'] === 'left') { |
||
34 | $rightAlign = ' '; |
||
35 | } elseif ($this->attrs['align'] === 'right') { |
||
36 | $leftAlign = ' '; |
||
37 | } elseif ($this->attrs['align'] === 'center') { |
||
38 | $leftAlign = ' '; |
||
39 | $rightAlign = ' '; |
||
40 | } |
||
41 | |||
42 | $query = []; |
||
43 | if ($this->attrs['height']) { |
||
44 | $query[] = $this->attrs['width'] . 'x' . $this->attrs['height']; |
||
45 | } elseif ($this->attrs['width']) { |
||
46 | $query[] = $this->attrs['width']; |
||
47 | } |
||
48 | if ($this->attrs['linking'] && $this->attrs['linking'] !== 'details') { |
||
49 | $query[] = $this->attrs['linking']; |
||
50 | } |
||
51 | if ($this->attrs['cache'] && $this->attrs['cache'] !== 'cache') { |
||
52 | $query[] = $this->attrs['cache']; |
||
53 | } |
||
54 | |||
55 | $queryString = ''; |
||
56 | if (!empty($query)) { |
||
57 | $queryString = '?' . implode('&', $query); |
||
58 | } |
||
59 | |||
60 | |||
61 | return '{{' . $leftAlign . $this->attrs['id'] . $queryString . $rightAlign . $title . '}}'; |
||
62 | } |
||
181 |