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

Fixed "Attempt to read property on array" error in ArrayDataSource #1169

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/DataSource/ArrayDataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Contributte\Datagrid\Utils\DateTimeHelper;
use Contributte\Datagrid\Utils\Sorting;
use DateTime;
use DateTimeInterface;

Check failure on line 18 in src/DataSource/ArrayDataSource.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.3)

Type DateTimeInterface is not used in this file.
use Nette\Utils\Strings;

class ArrayDataSource implements IDataSource
Expand Down Expand Up @@ -116,12 +116,11 @@
$data = [];

foreach ($this->data as $item) {
if (is_object($item->$column) && $item->$column instanceof \DateTimeInterface) {
$sort_by = $item->$column->format('Y-m-d H:i:s');
} elseif (is_object($item[$column]) && $item[$column] instanceof \DateTimeInterface) {
$sort_by = $item[$column]->format('Y-m-d H:i:s');
$value = is_object($item) ? $item->$column : $item[$column];

Check failure on line 119 in src/DataSource/ArrayDataSource.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.3)

Variable property access on object.
if ($value instanceof \DateTimeInterface) {

Check failure on line 120 in src/DataSource/ArrayDataSource.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.3)

Use ternary operator.
$sort_by = $value->format('Y-m-d H:i:s');
} else {
$sort_by = (string) $item[$column];
$sort_by = (string) $value;
}

$data[$sort_by][] = $item;
Expand Down
Loading