| Conditions | 15 |
| Paths | 14 |
| Total Lines | 50 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 114 | protected function writeBlade($field, int|string $name, string $body): string |
||
| 115 | { |
||
| 116 | if (!str_starts_with($name, 'tab-')) { |
||
| 117 | switch ($field['type']) { |
||
| 118 | case 'options': |
||
| 119 | case 'bloks': |
||
| 120 | $body .= "\t" . '@foreach ($block->' . $name . ' as $childBlock)' . "\n"; |
||
| 121 | $body .= "\t\t" . '{{ $childBlock->render() }}' . "\n"; |
||
| 122 | $body .= "\t" . '@endforeach' . "\n"; |
||
| 123 | break; |
||
| 124 | case 'datetime': |
||
| 125 | $body .= "\t" . '<time datetime="{{ $block->' . $name . '->content()->toIso8601String() }}">{{ $block->' . $name . ' }}</time>' . "\n"; |
||
| 126 | break; |
||
| 127 | case 'number': |
||
| 128 | case 'text': |
||
| 129 | $body .= "\t" . '<p>{{ $block->' . $name . ' }}</p>' . "\n"; |
||
| 130 | break; |
||
| 131 | case 'multilink': |
||
| 132 | $body .= "\t" . '<a href="{{ $block->' . $name . '->cached_url }}"></a>' . "\n"; |
||
| 133 | break; |
||
| 134 | case 'textarea': |
||
| 135 | case 'richtext': |
||
| 136 | $body .= "\t" . '<div>{!! $block->' . $name . ' !!}</div>' . "\n"; |
||
| 137 | break; |
||
| 138 | case 'asset': |
||
| 139 | if (array_key_exists('filetypes', $field) && in_array('images', $field['filetypes'], true)) { |
||
| 140 | $body .= "\t" . '@if ($block->' . $name . '->hasFile())' . "\n"; |
||
| 141 | $body .= "\t\t" . '<img src="{{ $block->' . $name . '->transform()->resize(100, 100) }}" alt>' . "\n"; |
||
| 142 | $body .= "\t" . '@endif' . "\n"; |
||
| 143 | } else { |
||
| 144 | $body .= "\t" . '<a href="{{ $block->' . $name . ' }}">Download</a>' . "\n"; |
||
| 145 | } |
||
| 146 | break; |
||
| 147 | case 'image': |
||
| 148 | $body .= "\t" . '@if ($block->' . $name . '->hasFile())' . "\n"; |
||
| 149 | $body .= "\t\t" . '<img src="{{ $block->' . $name . '->transform()->resize(100, 100) }}" alt>' . "\n"; |
||
| 150 | $body .= "\t" . '@endif' . "\n"; |
||
| 151 | break; |
||
| 152 | case 'file': |
||
| 153 | $body .= "\t" . '@if ($block->' . $name . '->hasFile())' . "\n"; |
||
| 154 | $body .= "\t\t" . '<a href="{{ $block->' . $name . ' }}">{{ $block->' . $name . '->filename }}</a>' . "\n"; |
||
| 155 | $body .= "\t" . '@endif' . "\n"; |
||
| 156 | break; |
||
| 157 | default: |
||
| 158 | $body .= "\t" . '{{ $block->' . $name . ' }}' . "\n"; |
||
| 159 | } |
||
| 160 | } |
||
| 161 | |||
| 162 | $body .= "\n"; |
||
| 163 | return $body; |
||
| 164 | } |
||
| 165 | } |