RicLeP / laravel-storyblok

Make Laravel and Storyblok work together beautifully.
https://ls.sirric.co.uk/
MIT License
58 stars 15 forks source link

Scaffolding Empty Components Errors #10

Closed chaseconey closed 3 years ago

chaseconey commented 3 years ago

Overview

When generating new components that have no items in the schema, the command errors out.

Steps to Reproduce

  1. Create new component in Storyblok with no fields (an empty schema)
  2. Run command to scaffold component like so:
php artisan ls:block EmptyComponent

Expected

I expect a class representation of the component, but with no available attributes listed.

Actual

Command errors out with the following stack:

   ErrorException

  Trying to access array offset on value of type null

  at vendor/riclep/laravel-storyblok/src/Console/BlockSyncCommand.php:154
    150▕
    151▕            $component = $components->firstWhere('name', $name);
    152▕
    153▕            $fields = [];
  ➜ 154▕            foreach ($component['schema'] as $name => $data) {
    155▕                if ( ! $this->isIgnoredType($data['type'])) {
    156▕                    $fields[$name] = $this->convertToPhpType($data['type']);
    157▕                }
    158▕            }

      +29 vendor frames
  30  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))