Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Nov 15, 2023
1 parent 13e8e93 commit 30ec1bc
Show file tree
Hide file tree
Showing 16 changed files with 128 additions and 141 deletions.
47 changes: 18 additions & 29 deletions src/BaseListView.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Yiisoft\Data\Paginator\KeysetPaginator;
use Yiisoft\Data\Paginator\OffsetPaginator;
use Yiisoft\Data\Paginator\PaginatorInterface;
use Yiisoft\Data\Reader\ReadableDataInterface;
use Yiisoft\Definitions\Exception\CircularReferenceException;
use Yiisoft\Definitions\Exception\InvalidConfigException;
use Yiisoft\Definitions\Exception\NotInstantiableException;
Expand All @@ -28,7 +29,7 @@ abstract class BaseListView extends Widget
private string $layout = "{header}\n{toolbar}";
private string $layoutGridTable = "{items}\n{summary}\n{pager}";
private string $pagination = '';
protected ?PaginatorInterface $paginator = null;
protected ?ReadableDataInterface $dataReader = null;
private SimpleMessageFormatter|null $simpleMessageFormatter = null;
private array $sortLinkAttributes = [];
private string $summary = 'dataview.summary';
Expand Down Expand Up @@ -95,13 +96,13 @@ public function emptyTextAttributes(array $values): static
return $new;
}

public function getPaginator(): PaginatorInterface
public function getDataReader(): PaginatorInterface

Check failure on line 99 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.0-ubuntu-latest

InvalidReturnType

src/BaseListView.php:99:38: InvalidReturnType: The declared return type 'Yiisoft\Data\Paginator\PaginatorInterface' for Yiisoft\Yii\DataView\BaseListView::getDataReader is incorrect, got 'Yiisoft\Data\Reader\ReadableDataInterface' (see https://psalm.dev/011)

Check failure on line 99 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

InvalidReturnType

src/BaseListView.php:99:38: InvalidReturnType: The declared return type 'Yiisoft\Data\Paginator\PaginatorInterface' for Yiisoft\Yii\DataView\BaseListView::getDataReader is incorrect, got 'Yiisoft\Data\Reader\ReadableDataInterface' (see https://psalm.dev/011)
{
if ($this->paginator === null) {
if ($this->dataReader === null) {
throw new Exception\PaginatorNotSetException();
}

return $this->paginator;
return $this->dataReader;

Check failure on line 105 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.0-ubuntu-latest

InvalidReturnStatement

src/BaseListView.php:105:16: InvalidReturnStatement: The inferred type 'Yiisoft\Data\Reader\ReadableDataInterface' does not match the declared return type 'Yiisoft\Data\Paginator\PaginatorInterface' for Yiisoft\Yii\DataView\BaseListView::getDataReader (see https://psalm.dev/128)

Check failure on line 105 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

InvalidReturnStatement

src/BaseListView.php:105:16: InvalidReturnStatement: The inferred type 'Yiisoft\Data\Reader\ReadableDataInterface' does not match the declared return type 'Yiisoft\Data\Paginator\PaginatorInterface' for Yiisoft\Yii\DataView\BaseListView::getDataReader (see https://psalm.dev/128)
}

public function getSimpleMessageFormatter(): SimpleMessageFormatter
Expand Down Expand Up @@ -218,13 +219,12 @@ public function pagination(string $value): static
/**
* Returns a new instance with the paginator interface of the grid view, detail view, or list view.
*
* @param PaginatorInterface $value The paginator interface of the grid view, detail view, or list view.
* @param ReadableDataInterface $dataReader The paginator interface of the grid view, detail view, or list view.
*/
public function paginator(PaginatorInterface $value): static
public function dataReader(ReadableDataInterface $dataReader): static
{
$new = clone $this;
$new->paginator = $value;

$new->dataReader = $dataReader;
return $new;
}

Expand Down Expand Up @@ -332,18 +332,6 @@ public function withContainer(bool $value = true): static
return $new;
}

protected function getDataReader(): array
{
$dataReader = [];

/** @var array */
foreach ($this->getPaginator()->read() as $read) {
$dataReader[] = $read;
}

return $dataReader;
}

protected function renderEmpty(int $colspan): Td
{
$emptyTextAttributes = $this->emptyTextAttributes;
Expand All @@ -367,7 +355,7 @@ protected function renderEmpty(int $colspan): Td
protected function renderLinkSorter(string $attribute, string $label): string
{
$renderLinkSorter = '';
$paginator = $this->getPaginator();
$paginator = $this->getDataReader();
$sort = $paginator->getSort();
$linkSorter = LinkSorter::widget();

Expand All @@ -384,7 +372,7 @@ protected function renderLinkSorter(string $attribute, string $label): string
->iconDescClass('bi bi-sort-alpha-down')
->label($label)
->linkAttributes($this->sortLinkAttributes)
->pageSize($this->getPaginator()->getPageSize())
->pageSize($this->getDataReader()->getPageSize())
->urlArguments($this->urlArguments)
->urlQueryParameters($this->urlQueryParameters)
->render();
Expand All @@ -395,7 +383,7 @@ protected function renderLinkSorter(string $attribute, string $label): string

public function render(): string
{
if ($this->paginator === null) {
if ($this->dataReader === null) {
throw new Exception\PaginatorNotSetException();
}

Expand All @@ -404,27 +392,28 @@ public function render(): string

private function renderPagination(): string
{
return match ($this->getPaginator()->isRequired()) {
return match ($this->getDataReader()->isRequired()) {
true => $this->pagination,
false => '',
};
}

private function renderSummary(): string
{
if ($this->getPaginator() instanceof KeysetPaginator) {
if ($this->getDataReader() instanceof KeysetPaginator) {
return '';
}

$pageCount = count($this->getDataReader());
/** @var OffsetPaginator $paginator */
$paginator = $this->getDataReader();

$data = iterator_to_array($paginator->read());
$pageCount = count($data);

if ($pageCount <= 0) {
return '';
}

/** @var OffsetPaginator $paginator */
$paginator = $this->getPaginator();

$summary = $this->getSimpleMessageFormatter()
->format(
$this->summary,
Expand Down
8 changes: 3 additions & 5 deletions src/GridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ private function guessColumns(): array
$columns = [];

/** @psalm-var array[] */
$dataReader = $this->getDataReader();
$dataReader = iterator_to_array($this->getDataReader()->read());

Check failure on line 307 in src/GridView.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.0-ubuntu-latest

InvalidArgument

src/GridView.php:307:41: InvalidArgument: Argument 1 of iterator_to_array expects Traversable, but iterable<array-key, array<array-key, mixed>|object> provided (see https://psalm.dev/004)

Check failure on line 307 in src/GridView.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

InvalidArgument

src/GridView.php:307:41: InvalidArgument: Argument 1 of iterator_to_array expects Traversable, but iterable<array-key, array<array-key, mixed>|object> provided (see https://psalm.dev/004)
reset($dataReader);

foreach ($dataReader as $data) {
Expand Down Expand Up @@ -436,13 +436,11 @@ private function renderFilters(array $columns): string
*/
private function renderTableBody(array $columns): string
{
$data = $this->getDataReader();
$keys = array_keys($data);
$rows = [];

/** @psalm-var array<int,array> $data */
foreach ($data as $index => $value) {
$key = $keys[$index];
foreach ($this->getDataReader()->read() as $index => $value) {
$key = $index;

if ($this->beforeRow !== null) {
/** @var array */
Expand Down
2 changes: 1 addition & 1 deletion src/ListView.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ protected function renderItem(array|object $data, mixed $key, int $index): strin
*/
protected function renderItems(): string
{
$data = $this->getDataReader();
$data = iterator_to_array($this->getDataReader()->read());

Check failure on line 221 in src/ListView.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.0-ubuntu-latest

InvalidArgument

src/ListView.php:221:35: InvalidArgument: Argument 1 of iterator_to_array expects Traversable, but iterable<array-key, array<array-key, mixed>|object> provided (see https://psalm.dev/004)

Check failure on line 221 in src/ListView.php

View workflow job for this annotation

GitHub Actions / psalm / PHP 8.1-ubuntu-latest

InvalidArgument

src/ListView.php:221:35: InvalidArgument: Argument 1 of iterator_to_array expects Traversable, but iterable<array-key, array<array-key, mixed>|object> provided (see https://psalm.dev/004)
$keys = array_keys($data);
$rows = [];

Expand Down
34 changes: 17 additions & 17 deletions tests/Column/ActionColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function testContent(): void
),
)
->id('w1-grid')
->paginator($this->createOffsetPaginator($this->data, 10))
->dataReader($this->createOffsetPaginator($this->data, 10))
->render()
);
}
Expand Down Expand Up @@ -117,7 +117,7 @@ public function testContentAttributes(): void
->contentAttributes(['class' => 'text-decoration-none test.class']),
)
->id('w1-grid')
->paginator($this->createOffsetPaginator($this->data, 10))
->dataReader($this->createOffsetPaginator($this->data, 10))
->render()
);
}
Expand Down Expand Up @@ -172,7 +172,7 @@ public function testCustomButton(): void
->visibleButtons(['resend-password' => true]),
)
->id('w1-grid')
->paginator($this->createOffsetPaginator($this->data, 10))
->dataReader($this->createOffsetPaginator($this->data, 10))
->render()
);
}
Expand Down Expand Up @@ -217,7 +217,7 @@ public function testDataLabel(): void
GridView::widget()
->columns(ActionColumn::create()->dataLabel('test.label'))
->id('w1-grid')
->paginator($this->createOffsetPaginator($this->data, 10))
->dataReader($this->createOffsetPaginator($this->data, 10))
->render()
);
}
Expand Down Expand Up @@ -270,7 +270,7 @@ public function testFooterAttributes(): void
)
->footerEnabled(true)
->id('w1-grid')
->paginator($this->createOffsetPaginator($this->data, 10))
->dataReader($this->createOffsetPaginator($this->data, 10))
->render()
);
}
Expand Down Expand Up @@ -315,7 +315,7 @@ public function testLabel(): void
GridView::widget()
->columns(ActionColumn::create()->label('test.label'))
->id('w1-grid')
->paginator($this->createOffsetPaginator($this->data, 10))
->dataReader($this->createOffsetPaginator($this->data, 10))
->render()
);
}
Expand Down Expand Up @@ -360,7 +360,7 @@ public function testLabelWithMbString(): void
GridView::widget()
->columns(ActionColumn::create()->label('Ενέργειες'))
->id('w1-grid')
->paginator($this->createOffsetPaginator($this->data, 10))
->dataReader($this->createOffsetPaginator($this->data, 10))
->render()
);
}
Expand Down Expand Up @@ -405,7 +405,7 @@ public function testLabelAttributes(): void
GridView::widget()
->columns(ActionColumn::create()->label('test.label')->labelAttributes(['class' => 'test.class']))
->id('w1-grid')
->paginator($this->createOffsetPaginator($this->data, 10))
->dataReader($this->createOffsetPaginator($this->data, 10))
->render()
);
}
Expand Down Expand Up @@ -450,7 +450,7 @@ public function testName(): void
GridView::widget()
->columns(ActionColumn::create()->name('test.name'))
->id('w1-grid')
->paginator($this->createOffsetPaginator($this->data, 10))
->dataReader($this->createOffsetPaginator($this->data, 10))
->render()
);
}
Expand Down Expand Up @@ -481,7 +481,7 @@ public function testNotVisible(): void
GridView::widget()
->columns(ActionColumn::create()->visible(false))
->id('w1-grid')
->paginator($this->createOffsetPaginator($this->data, 10))
->dataReader($this->createOffsetPaginator($this->data, 10))
->render()
);
}
Expand Down Expand Up @@ -526,7 +526,7 @@ public function testPrimaryKey(): void
GridView::widget()
->columns(ActionColumn::create()->primaryKey('identity_id'))
->id('w1-grid')
->paginator(
->dataReader(
$this->createOffsetPaginator(
[
['identity_id' => 1, 'name' => 'John', 'age' => 20],
Expand Down Expand Up @@ -589,7 +589,7 @@ public function testRender(): void
ActionColumn::create(),
)
->id('w1-grid')
->paginator($this->createOffsetPaginator($this->data, 10))
->dataReader($this->createOffsetPaginator($this->data, 10))
->render()
);
}
Expand Down Expand Up @@ -634,7 +634,7 @@ public function testUrlArguments(): void
GridView::widget()
->columns(ActionColumn::create()->urlArguments(['test-arguments' => 'test.arguments']))
->id('w1-grid')
->paginator($this->createOffsetPaginator($this->data, 10))
->dataReader($this->createOffsetPaginator($this->data, 10))
->render()
);
}
Expand Down Expand Up @@ -685,7 +685,7 @@ public function testUrlCreator(): void
),
)
->id('w1-grid')
->paginator($this->createOffsetPaginator($this->data, 10))
->dataReader($this->createOffsetPaginator($this->data, 10))
->render()
);
}
Expand Down Expand Up @@ -730,7 +730,7 @@ public function testUrlQueryParameters(): void
GridView::widget()
->columns(ActionColumn::create()->urlQueryParameters(['test-param' => 'test.param']))
->id('w1-grid')
->paginator($this->createOffsetPaginator($this->data, 10))
->dataReader($this->createOffsetPaginator($this->data, 10))
->render()
);
}
Expand Down Expand Up @@ -775,7 +775,7 @@ public function testUrlParamsConfig(): void
GridView::widget()
->columns(ActionColumn::create()->urlParamsConfig(['test-param' => 'test.param']))
->id('w1-grid')
->paginator($this->createOffsetPaginator($this->data, 10))
->dataReader($this->createOffsetPaginator($this->data, 10))
->render()
);
}
Expand Down Expand Up @@ -823,7 +823,7 @@ public function testVisibleButtonsClosure(): void
),
)
->id('w1-grid')
->paginator($this->createOffsetPaginator($this->data, 10))
->dataReader($this->createOffsetPaginator($this->data, 10))
->render()
);
}
Expand Down
Loading

0 comments on commit 30ec1bc

Please sign in to comment.