Conditions | 12 |
Paths | 12 |
Total Lines | 40 |
Code Lines | 34 |
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 |
||
102 | protected function writeBlade($field, int|string $name, string $body): string |
||
103 | { |
||
104 | if (!str_starts_with($name, 'tab-')) { |
||
105 | switch ($field['type']) { |
||
106 | case 'options': |
||
107 | case 'bloks': |
||
108 | $body .= "\t" . '@foreach ($block->' . $name . ' as $childBlock)' . "\n"; |
||
109 | $body .= "\t\t" . '{{ $childBlock->render() }}' . "\n"; |
||
110 | $body .= "\t" . '@endforeach' . "\n"; |
||
111 | break; |
||
112 | case 'datetime': |
||
113 | $body .= "\t" . '<time datetime="{{ $block->' . $name . '->content()->toIso8601String() }}">{{ $block->' . $name . ' }}</time>' . "\n"; |
||
114 | break; |
||
115 | case 'number': |
||
116 | case 'text': |
||
117 | $body .= "\t" . '<p>{{ $block->' . $name . ' }}</p>' . "\n"; |
||
118 | break; |
||
119 | case 'multilink': |
||
120 | $body .= "\t" . '<a href="{{ $block->' . $name . '->cached_url }}"></a>' . "\n"; |
||
121 | break; |
||
122 | case 'textarea': |
||
123 | case 'richtext': |
||
124 | $body .= "\t" . '<div>{!! $block->' . $name . ' !!}</div>' . "\n"; |
||
125 | break; |
||
126 | case 'asset': |
||
127 | if (in_array('images', $field['filetypes'], true)) { |
||
128 | $body .= "\t" . '@if ($block->' . $name . '->hasFile())' . "\n"; |
||
129 | $body .= "\t\t" . '<img src="{{ $block->' . $name . '->transform()->resize(100, 100) }}" alt>' . "\n"; |
||
130 | $body .= "\t" . '@endif' . "\n"; |
||
131 | } else { |
||
132 | $body .= "\t" . '{{ $block->' . $name . ' }}' . "\n"; |
||
133 | } |
||
134 | break; |
||
135 | default: |
||
136 | $body .= "\t" . '{{ $block->' . $name . ' }}' . "\n"; |
||
137 | } |
||
138 | } |
||
139 | |||
140 | $body .= "\n"; |
||
141 | return $body; |
||
142 | } |
||
144 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.