| Conditions | 12 |
| Paths | 1 |
| Total Lines | 52 |
| Code Lines | 39 |
| 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 |
||
| 38 | public function handle() |
||
| 39 | { |
||
| 40 | $client = new \Storyblok\ManagementClient(config('storyblok.oauth_token')); |
||
| 41 | |||
| 42 | $components = collect($client->get('spaces/' . config('storyblok.space_id') . '/components/')->getBody()['components']); |
||
|
|
|||
| 43 | |||
| 44 | $components->each(function ($component) { |
||
| 45 | $path = resource_path('views/' . str_replace('.', '/', config('storyblok.view_path')) . 'blocks/'); |
||
| 46 | $filename = $component['name'] . '.blade.php'; |
||
| 47 | |||
| 48 | if ($this->option('overwrite') || !file_exists($path . $filename)) { |
||
| 49 | $content = file_get_contents(__DIR__ . '/stubs/blade.stub'); |
||
| 50 | $content = str_replace('#NAME#', $component['name'], $content); |
||
| 51 | |||
| 52 | $body = ''; |
||
| 53 | |||
| 54 | foreach ($component['schema'] as $name => $field) { |
||
| 55 | switch ($field['type']) { |
||
| 56 | case 'bloks': |
||
| 57 | $body .= "\t" . '@foreach ($block->' . $name . ' as $childBlock)' . "\n"; |
||
| 58 | $body .= "\t\t" . '{{ $childBlock->render() }}' . "\n"; |
||
| 59 | $body .= "\t" . '@endforeach' . "\n"; |
||
| 60 | break; |
||
| 61 | case 'datetime': |
||
| 62 | case 'number': |
||
| 63 | case 'text': |
||
| 64 | $body .= "\t" . '<p>{{ $block->' . $name . ' }}</p>' . "\n"; |
||
| 65 | break; |
||
| 66 | case 'multilink': |
||
| 67 | $body .= "\t" . '<a href="{{ $block->' . $name . '->cached_url }}"></a>' . "\n"; |
||
| 68 | break; |
||
| 69 | case 'options': |
||
| 70 | $body .= "\t" . '@foreach ($block->' . $name . ' as $childBlock)' . "\n"; |
||
| 71 | $body .= "\t\t\n"; |
||
| 72 | $body .= "\t" . '@endforeach' . "\n"; |
||
| 73 | break; |
||
| 74 | case 'textarea': |
||
| 75 | case 'richtext': |
||
| 76 | $body .= "\t" . '<div>{!! $block->' . $name . ' !!}</div>' . "\n"; |
||
| 77 | break; |
||
| 78 | default: |
||
| 79 | $body .= "\t" . '{{ $block->' . $name . ' }}' . "\n"; |
||
| 80 | } |
||
| 81 | |||
| 82 | $body .= "\n"; |
||
| 83 | } |
||
| 84 | |||
| 85 | $content = str_replace('#BODY#', $body, $content); |
||
| 86 | |||
| 87 | file_put_contents($path . $filename, $content); |
||
| 88 | |||
| 89 | $this->info('Created: '. $component['name'] . '.blade.php'); |
||
| 90 | } |
||
| 94 |
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.