Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different types in NoopSerializer #193

Open
konstmal opened this issue Mar 16, 2023 · 9 comments
Open

Different types in NoopSerializer #193

konstmal opened this issue Mar 16, 2023 · 9 comments

Comments

@konstmal
Copy link

Flugg\Responder\Serializers\NoopSerializer::null(): Return value must be of type array, null returned at /var/www/html/vendor/flugger/laravel-responder/src/Serializers/NoopSerializer.php:51)

In NoopSerializer returned type of null() function is array, but function always returns null

@SachinBahukhandi
Copy link
Contributor

SachinBahukhandi commented Mar 19, 2023

How were you able to get this error? PHP version, laravel version?

@konstmal
Copy link
Author

PHP v 8.0.1
Laravel v8.83.27

@SachinBahukhandi
Copy link
Contributor

SachinBahukhandi commented Mar 20, 2023

PHP v 8.0.1 Laravel v8.83.27

Sorry, forgot to mention, what is the pacakge-version?
Also, could you please add a minimum reproducable example?

@konstmal
Copy link
Author

I caught the error in 3.3.0 version, where was added type hint for functions
In 3.2.0 there are no problems

@SachinBahukhandi
Copy link
Contributor

I caught the error in 3.3.0 version, where was added type hint for functions In 3.2.0 there are no problems

I tried using this code snippet:

 return $transformation->resource(User::all())->serializer(NoopSerializer::class)->transform();

But it did not break.

@konstmal
Copy link
Author

$anyUser = User::query()->first(); return [ 'other' => transformation($anyUser, new UserTransformer())->transform(), ];

This is my code, and the error exists where $anyUser has some null fields

@ivanich274
Copy link

same problem, reverted back to v3.2.0

@zdravstvuy1714
Copy link

+1

@morhi
Copy link

morhi commented May 12, 2023

Would be nice to have a fix for this.. this code is obviously not working:

    public function null(): array
    {
        return null; # Cannot return null if type must be array
    }

I guess the type definition for this method should be ?array, because null must be returned for relationships, that cannot be resolved, so that they actually return null instead of [].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants