| Conditions | 9 |
| Paths | 96 |
| Total Lines | 56 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 9 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 64 | public function FieldHolder($properties = []) |
||
| 65 | { |
||
| 66 | $link = $this->link; |
||
| 67 | |||
| 68 | $title = $this->getButtonTitle(); |
||
| 69 | $classes = [$this->extraClass()]; |
||
| 70 | if ($this->noAjax) { |
||
| 71 | $classes[] = 'no-ajax'; |
||
| 72 | } |
||
| 73 | |||
| 74 | if ($this->buttonIcon) { |
||
| 75 | $classes[] = "font-icon"; |
||
| 76 | $classes[] = sprintf('font-icon-%s', $this->buttonIcon); |
||
| 77 | $classes[] = "btn-mobile-collapse"; |
||
| 78 | } |
||
| 79 | |||
| 80 | $attrs = []; |
||
| 81 | |||
| 82 | // note: links with target are never submitted through ajax |
||
| 83 | if ($this->newWindow) { |
||
| 84 | $attrs[] = 'target="_blank"'; |
||
| 85 | } |
||
| 86 | if ($this->confirmation) { |
||
| 87 | /** @var string $att */ |
||
| 88 | $att = Convert::raw2htmlatt($this->confirmation); |
||
| 89 | $attrs[] = sprintf('data-message="%s"', $att); |
||
| 90 | |||
| 91 | // With no ajax or progressive, use entwine to show confirm message |
||
| 92 | if ($this->progressive || $this->getNoAjax()) { |
||
| 93 | $classes[] = "confirm"; |
||
| 94 | } else { |
||
| 95 | $attrs[] = 'onclick="return confirm(this.dataset.message);"'; |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | $lastIcon = null; |
||
| 100 | if ($this->hasLastIcon()) { |
||
| 101 | $lastIcon = $this->renderLastIcon() . ' '; |
||
| 102 | $classes[] = "btn-mobile-collapse"; |
||
| 103 | } |
||
| 104 | |||
| 105 | foreach ($this->attributes as $attributeKey => $attributeValue) { |
||
| 106 | $attrs[] = sprintf('%s="%s"', $attributeKey, $attributeValue); |
||
| 107 | } |
||
| 108 | |||
| 109 | $content = sprintf( |
||
| 110 | '<a href="%s" class="%s" %s>%s<span class="btn__title">%s</span></a>', |
||
| 111 | $link, |
||
| 112 | implode(' ', $classes), |
||
| 113 | implode(' ', $attrs), |
||
| 114 | $lastIcon, |
||
| 115 | $title |
||
| 116 | ); |
||
| 117 | $this->content = $content; |
||
| 118 | |||
| 119 | return parent::FieldHolder(); |
||
| 120 | } |
||
| 157 |