Skip to content

Cleanup #248

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

Merged
merged 3 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions src/BaseListView.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
protected UrlParameterProviderInterface|null $urlParameterProvider = null;

private bool $ignoreMissingPage = true;
protected bool $enableMultiSort = false;
protected bool $multiSort = false;

/**
* @psalm-var PageNotFoundExceptionCallback|null
Expand All @@ -170,7 +170,7 @@

final public function ignoreMissingPage(bool $enabled): static
{
$new = clone $this;

Check warning on line 173 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "CloneRemoval": @@ @@ } final public function ignoreMissingPage(bool $enabled): static { - $new = clone $this; + $new = $this; $new->ignoreMissingPage = $enabled; return $new; }
$new->ignoreMissingPage = $enabled;
return $new;
}
Expand Down Expand Up @@ -218,15 +218,15 @@

final public function urlParameterProvider(?UrlParameterProviderInterface $provider): static
{
$new = clone $this;

Check warning on line 221 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "CloneRemoval": @@ @@ } final public function urlParameterProvider(?UrlParameterProviderInterface $provider): static { - $new = clone $this; + $new = $this; $new->urlParameterProvider = $provider; return $new; }
$new->urlParameterProvider = $provider;
return $new;
}

final public function enableMultiSort(bool $enable = true): static
final public function multiSort(bool $enable = true): static
{
$new = clone $this;
$new->enableMultiSort = $enable;
$new->multiSort = $enable;
return $new;
}

Expand Down Expand Up @@ -412,7 +412,7 @@
*/
final public function offsetPaginationConfig(array $config): static
{
$new = clone $this;

Check warning on line 415 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "CloneRemoval": @@ @@ */ final public function offsetPaginationConfig(array $config): static { - $new = clone $this; + $new = $this; $new->offsetPaginationConfig = $config; return $new; }
$new->offsetPaginationConfig = $config;
return $new;
}
Expand All @@ -425,7 +425,7 @@
*/
final public function keysetPaginationConfig(array $config): static
{
$new = clone $this;

Check warning on line 428 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "CloneRemoval": @@ @@ */ final public function keysetPaginationConfig(array $config): static { - $new = clone $this; + $new = $this; $new->keysetPaginationConfig = $config; return $new; }
$new->keysetPaginationConfig = $config;
return $new;
}
Expand Down Expand Up @@ -599,7 +599,7 @@
*
* @psalm-return list{FilterInterface[]|null,ValidationResult}
*/
protected function makeFilters(): array

Check warning on line 602 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "ProtectedVisibility": @@ @@ * * @psalm-return list{FilterInterface[]|null,ValidationResult} */ - protected function makeFilters(): array + private function makeFilters(): array { return [[], new ValidationResult()]; }
{
return [[], new ValidationResult()];
}
Expand Down Expand Up @@ -768,11 +768,11 @@
}
}

if (!empty($sort) && $dataReader->isSortable()) {

Check warning on line 771 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "LogicalAndSingleSubExprNegation": @@ @@ $dataReader = $dataReader->withToken(PageToken::previous($previousPage)); } } - if (!empty($sort) && $dataReader->isSortable()) { + if (!empty($sort) && !$dataReader->isSortable()) { $sortObject = $dataReader->getSort(); if ($sortObject !== null) { $order = OrderHelper::stringToArray($sort);
$sortObject = $dataReader->getSort();
if ($sortObject !== null) {
$order = OrderHelper::stringToArray($sort);
if (!$this->enableMultiSort) {
if (!$this->multiSort) {
$order = array_slice($order, 0, 1, true);
}
$dataReader = $dataReader->withSort(
Expand All @@ -783,7 +783,7 @@
}
}

if (!empty($filters) && $dataReader->isFilterable()) {

Check warning on line 786 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "LogicalAnd": @@ @@ $dataReader = $dataReader->withSort($sortObject->withOrder($this->prepareOrder($order))); } } - if (!empty($filters) && $dataReader->isFilterable()) { + if (!empty($filters) || $dataReader->isFilterable()) { $dataReader = $dataReader->withFilter(new All(...$filters)); } return $dataReader;

Check warning on line 786 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "LogicalAndNegation": @@ @@ $dataReader = $dataReader->withSort($sortObject->withOrder($this->prepareOrder($order))); } } - if (!empty($filters) && $dataReader->isFilterable()) { + if (!(!empty($filters) && $dataReader->isFilterable())) { $dataReader = $dataReader->withFilter(new All(...$filters)); } return $dataReader;

Check warning on line 786 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "LogicalAndSingleSubExprNegation": @@ @@ $dataReader = $dataReader->withSort($sortObject->withOrder($this->prepareOrder($order))); } } - if (!empty($filters) && $dataReader->isFilterable()) { + if (!empty($filters) && !$dataReader->isFilterable()) { $dataReader = $dataReader->withFilter(new All(...$filters)); } return $dataReader;
$dataReader = $dataReader->withFilter(new All(...$filters));
}

Expand Down Expand Up @@ -927,7 +927,7 @@
$currentPage = $dataReader->getCurrentPage();

// The starting row number (1-based) currently being displayed
$begin = ($currentPage - 1) * $dataReader->getPageSize() + 1;

Check warning on line 930 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": @@ @@ // The page number (1-based) current being displayed $currentPage = $dataReader->getCurrentPage(); // The starting row number (1-based) currently being displayed - $begin = ($currentPage - 1) * $dataReader->getPageSize() + 1; + $begin = ($currentPage - 0) * $dataReader->getPageSize() + 1; // The number of rows currently being displayed $count = $dataReader->getCurrentPageSize(); // The ending row number (1-based) currently being displayed

// The number of rows currently being displayed
$count = $dataReader->getCurrentPageSize();
Expand Down
8 changes: 4 additions & 4 deletions src/Column/Base/HeaderContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final class HeaderContext
* @param string|null $sortableLinkDescClass CSS class for descending sort links.
* @param PageToken|null $pageToken Current page token for pagination.
* @param int|null $pageSize Number of items per page.
* @param bool $enableMultiSort Whether multiple column sorting is enabled.
* @param bool $multiSort Whether multiple column sorting is enabled.
* @param UrlConfig $urlConfig URL configuration settings.
* @param UrlCreator|null $urlCreator Callback for creating sort URLs.
* @param TranslatorInterface $translator Translator service for header content.
Expand Down Expand Up @@ -75,7 +75,7 @@ public function __construct(
public readonly ?string $sortableLinkDescClass,
private readonly ?PageToken $pageToken,
private readonly int|null $pageSize,
private readonly bool $enableMultiSort,
private readonly bool $multiSort,
private readonly UrlConfig $urlConfig,
private $urlCreator,
private readonly TranslatorInterface $translator,
Expand Down Expand Up @@ -177,7 +177,7 @@ private function getLinkSortValue(
$order = $sort->getOrder();

if (isset($order[$property])) {
if ($this->enableMultiSort) {
if ($this->multiSort) {
if ($order[$property] === 'asc') {
$order[$property] = 'desc';
} elseif (!empty($originalOrder) && count($order) === 1) {
Expand All @@ -196,7 +196,7 @@ private function getLinkSortValue(
} else {
unset($order[$property]);
}
} elseif ($this->enableMultiSort) {
} elseif ($this->multiSort) {
$order[$property] = 'asc';
} else {
$order = [$property => 'asc'];
Expand Down
12 changes: 6 additions & 6 deletions src/GridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ final class GridView extends BaseListView
/**
* @var bool Whether column grouping is enabled.
*/
private bool $isColumnGroupingEnabled = false;
private bool $columnGrouping = false;

/**
* @var string HTML content for empty cells.
Expand Down Expand Up @@ -398,10 +398,10 @@ public function columns(ColumnInterface ...$columns): self
*
* @return self New instance with the column grouping enabled.
*/
public function enableColumnGrouping(bool $enabled = true): self
public function columnGrouping(bool $enabled = true): self
{
$new = clone $this;
$new->isColumnGroupingEnabled = $enabled;
$new->columnGrouping = $enabled;
return $new;
}

Expand Down Expand Up @@ -444,7 +444,7 @@ public function emptyCellAttributes(array $attributes): self
*
* @return self New instance with the footer section visibility setting.
*/
public function enableFooter(bool $enabled): self
public function enableFooter(bool $enabled = true): self
{
$new = clone $this;
$new->isFooterEnabled = $enabled;
Expand Down Expand Up @@ -814,7 +814,7 @@ protected function renderItems(
$filterRow = null;
}

if ($this->isColumnGroupingEnabled) {
if ($this->columnGrouping) {
$tags = [];
foreach ($columns as $i => $column) {
$cell = $renderers[$i]->renderColumn($column, new Cell(), $globalContext);
Expand Down Expand Up @@ -842,7 +842,7 @@ protected function renderItems(
$this->sortableLinkDescClass,
$this->keepPageOnSort ? $pageToken : null,
$pageSize,
$this->enableMultiSort,
$this->multiSort,
$this->urlConfig,
$this->urlCreator,
$this->translator,
Expand Down
2 changes: 1 addition & 1 deletion tests/Column/DataColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ public function testColumnClasses(): void
bodyClass: 'bodyClass'
),
)
->enableColumnGrouping()
->columnGrouping()
->dataReader(new IterableDataReader($this->data))
->render()
);
Expand Down
4 changes: 2 additions & 2 deletions tests/GridView/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function testColumnGroupEnabled(): void
new DataColumn(property: 'id', columnAttributes: ['class' => 'bg-primary']),
new DataColumn(property: 'name', columnAttributes: ['class' => 'bg-success']),
)
->enableColumnGrouping()
->columnGrouping()
->id('w1-grid')
->dataReader($this->createOffsetPaginator($this->data, 10))
->render()
Expand Down Expand Up @@ -171,7 +171,7 @@ public function testColumnGroupEnabledEmpty(): void
new DataColumn(property: 'name'),
new DataColumn(property: 'age'),
)
->enableColumnGrouping()
->columnGrouping()
->id('w1-grid')
->dataReader($this->createOffsetPaginator($this->data, 10))
->render()
Expand Down
2 changes: 1 addition & 1 deletion tests/GridView/ImmutableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function testGridView(): void
$this->assertNotSame($gridView, $gridView->afterRow(null));
$this->assertNotSame($gridView, $gridView->beforeRow(null));
$this->assertNotSame($gridView, $gridView->columns(new DataColumn()));
$this->assertNotSame($gridView, $gridView->enableColumnGrouping(false));
$this->assertNotSame($gridView, $gridView->columnGrouping(false));
$this->assertNotSame($gridView, $gridView->emptyCell(''));
$this->assertNotSame($gridView, $gridView->enableFooter(false));
$this->assertNotSame($gridView, $gridView->footerRowAttributes([]));
Expand Down
Loading