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

Immutable Collection operations not working properly #89

Open
Anticom opened this issue Jul 22, 2021 · 0 comments
Open

Immutable Collection operations not working properly #89

Anticom opened this issue Jul 22, 2021 · 0 comments

Comments

@Anticom
Copy link

Anticom commented Jul 22, 2021

Whenever the \Illuminate\Support\Collection is trying to create a new static(...), for example in the map method, since you've extended the Collection with your own something seems to go wrong.

Here's an example:

<?php

use Maclof\Kubernetes\Client;
use Maclof\Kubernetes\Models\NamespaceModel;

require __DIR__ . '/../vendor/autoload.php';

$client = new Client();
// configure client...

$client
    ->namespaces()
    ->find()
    ->map(fn(NamespaceModel $ns) => $ns->getMetadata('name'));

will result in:

PHP Fatal error:  Uncaught InvalidArgumentException: Attributes are not an array. in /path/to/repo/vendor/maclof/kubernetes-client/src/Models/Model.php:54
Stack trace:
#0 /path/to/repo/vendor/maclof/kubernetes-client/src/Collections/NamespaceCollection.php(30): Maclof\Kubernetes\Models\Model->__construct()
#1 /path/to/repo/vendor/maclof/kubernetes-client/src/Collections/NamespaceCollection.php(14): Maclof\Kubernetes\Collections\NamespaceCollection->getNamespaces()
#2 /path/to/repo/vendor/illuminate/collections/Collection.php(644): Maclof\Kubernetes\Collections\NamespaceCollection->__construct()
#3 /path/to/repo/src/index.php(17): Illuminate\Support\Collection->map()
#4 {main}
  thrown in /path/to/repo/vendor/maclof/kubernetes-client/src/Models/Model.php on line 54

I think the issue is the get<ResourceType> method in the corresponding collections.
A possible solution might be to convert the raw data to models before constructing the collection.

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

1 participant