Skip to content

Conversation

@tolry
Copy link

@tolry tolry commented Dec 19, 2024

When using cursor pagination, access to has_more and cursor are labelled as violations by phpstan or psalm, since those properties are protected on AbstractModel although they are readable publicly via __get()

sample code

$cursor = null;
do {
    $filter = ["customer_uuid" => $uuid];
    if ($cursor) {
        $filter["cursor"] = $cursor;
    }

    $collection = \ChartMogul\CustomerInvoices::all($filter);

    foreach ($collection->invoices as $invoice) {
        // do something
    }

    $cursor = $collection->cursor;
} while ($collection->has_more);

When using cursor pagination, access to `has_more` and `cursor` are labelled as violations by phpstan or psalm, since those properties are protected on `AbstractModel` although they are readable publicly via `__get()`

sample code 

```php
$cursor = null;
do {
    $filter = ["customer_uuid" => $uuid];
    if ($cursor) {
        $filter["cursor"] = $cursor;
    }

    $collection = \ChartMogul\CustomerInvoices::all($filter);

    foreach ($collection->invoices as $invoice) {
        // do something
    }

    $cursor = $collection->cursor;
} while ($collection->has_more);
```
Copy link
Contributor

@swember swember left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @tolry, thanks a lot for the contribution. Could you please provide which settings for phpstan you use. I tried to create a new project and use your code in it and I haven't got any complaints from phpstan.

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

Successfully merging this pull request may close these issues.

2 participants