Skip to content

Commit

Permalink
Merge remote-tracking branch 'yiisoft/master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
glpzzz committed Mar 2, 2024
2 parents b57587b + 833901b commit 7ed40cd
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/BaseListView.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,15 @@ public function getDataReader(): ReadableDataInterface
}

/**
* @psalm-return list{FilterInterface[],ValidationResult}
* @return array The array with format:
* ```
* [
* FilterInterface[]|null, // Array of filters or `null` if there are definitely no entries for the current filter
* ValidationResult, // Validation result of the filter
* ]
* ```
*
* @psalm-return list{FilterInterface[]|null,ValidationResult}
*/
protected function makeFilters(): array

Check warning on line 256 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

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

Check warning on line 256 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

Escaped Mutant for Mutator "ProtectedVisibility": --- Original +++ New @@ @@ * * @psalm-return list{FilterInterface[]|null,ValidationResult} */ - protected function makeFilters() : array + private function makeFilters() : array { return [[], new ValidationResult()]; }
{
Expand Down Expand Up @@ -550,7 +558,7 @@ protected function renderEmpty(int $colspan): Td
public function render(): string
{
[$filters, $filterValidationResult] = $this->makeFilters();
$items = $this->prepareDataReaderAndGetItems($filters);
$items = $filters === null ? [] : $this->prepareDataReaderAndGetItems($filters);

$content = trim(
strtr(
Expand Down
4 changes: 4 additions & 0 deletions src/Column/FilterableColumnRendererInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
use Yiisoft\Yii\DataView\Column\Base\Cell;
use Yiisoft\Yii\DataView\Column\Base\FilterContext;
use Yiisoft\Yii\DataView\Column\Base\MakeFilterContext;
use Yiisoft\Yii\DataView\Filter\Factory\IncorrectValueException;

interface FilterableColumnRendererInterface extends ColumnRendererInterface
{
public function renderFilter(ColumnInterface $column, Cell $cell, FilterContext $context): ?Cell;

/**
* @throws IncorrectValueException
*/
public function makeFilter(ColumnInterface $column, MakeFilterContext $context): ?FilterInterface;
}
3 changes: 3 additions & 0 deletions src/Filter/Factory/FilterFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@

interface FilterFactoryInterface
{
/**
* @throws IncorrectValueException
*/
public function create(string $property, string $value): ?FilterInterface;
}
11 changes: 11 additions & 0 deletions src/Filter/Factory/IncorrectValueException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Yii\DataView\Filter\Factory;

use Exception;

final class IncorrectValueException extends Exception
{
}
8 changes: 7 additions & 1 deletion src/GridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Yiisoft\Yii\DataView\Column\ColumnInterface;
use Yiisoft\Yii\DataView\Column\ColumnRendererInterface;
use Yiisoft\Yii\DataView\Column\FilterableColumnRendererInterface;
use Yiisoft\Yii\DataView\Filter\Factory\IncorrectValueException;

/**
* The GridView widget is used to display data in a grid.
Expand Down Expand Up @@ -649,7 +650,12 @@ protected function makeFilters(): array
$filters = [];
foreach ($columns as $i => $column) {
if ($renderers[$i] instanceof FilterableColumnRendererInterface) {
$filter = $renderers[$i]->makeFilter($column, $context);
try {
$filter = $renderers[$i]->makeFilter($column, $context);
} catch (IncorrectValueException) {
$filters = null;
break;
}
if ($filter !== null) {
$filters[] = $filter;
}
Expand Down

0 comments on commit 7ed40cd

Please sign in to comment.