Skip to content

Commit

Permalink
Cleanup (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark authored Aug 10, 2024
1 parent d13ddff commit e3b27cb
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ Since Yii 3 consists of many packages, we have a [special development tool](http
If you don't have any particular package in mind to start with:

- [Check roadmap](https://github.com/yiisoft/docs/blob/master/003-roadmap.md).
- Check package issues at github. Usually there are some.
- Check package issues at GitHub. Usually there are some.
- Ask @samdark.
6 changes: 3 additions & 3 deletions src/BaseListView.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ final public function containerAttributes(array $attributes): static
/**
* Return a new instance with the empty text.
*
* @param string $emptyText the HTML content to be displayed when {@see dataProvider} does not have any data.
* @param ?string $emptyText The HTML content to be displayed when {@see dataProvider} does not have any data.
*
* The default value is the text "No results found." which will be translated to the current application language.
*
Expand Down Expand Up @@ -375,7 +375,7 @@ private function prepareDataReaderByParams(
}
}

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

Check warning on line 378 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

Escaped Mutant for Mutator "LogicalAndSingleSubExprNegation": --- Original +++ New @@ @@ $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);
Expand All @@ -387,7 +387,7 @@ private function prepareDataReaderByParams(
}
}

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

Check warning on line 390 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

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

Check warning on line 390 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

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

Check warning on line 390 in src/BaseListView.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.2-ubuntu-latest

Escaped Mutant for Mutator "LogicalAndSingleSubExprNegation": --- Original +++ New @@ @@ $dataReader = $dataReader->withSort($sortObject->withOrder($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
10 changes: 4 additions & 6 deletions src/Column/ActionColumnRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ function (array $matches) use ($column, $buttons, $context): string {
$name = $matches[1];

if (
isset($buttons[$name]) &&
$this->isVisibleButton(
$column,
$name,
$context->data,
$context->key,
$context->index,
) &&
isset($buttons[$name])
)
) {
return $this->renderButton($buttons[$name], $name, $context);
}
Expand Down Expand Up @@ -150,10 +150,8 @@ private function renderButton(ActionButton|callable $button, string $name, DataC
} else {
$attributes = $button->attributes ?? [];
}
if (!$button->overrideAttributes) {
if (!empty($this->buttonAttributes)) {
$attributes = array_merge($this->buttonAttributes, $attributes);
}
if (!$button->overrideAttributes && !empty($this->buttonAttributes)) {
$attributes = array_merge($this->buttonAttributes, $attributes);
}

if ($button->class instanceof Closure) {
Expand Down
2 changes: 1 addition & 1 deletion src/Column/Base/Cell.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function doubleEncode(bool $doubleEncode): self
}

/**
* @param string|Stringable $content Tag content.
* @param string|Stringable ...$content Tag content.
*/
public function content(string|Stringable ...$content): self
{
Expand Down
40 changes: 16 additions & 24 deletions src/Column/Base/HeaderContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public function __construct(
private readonly ?Sort $sort,
private readonly array $overrideOrderFields,
private readonly ?string $sortableHeaderClass,
private string|Stringable $sortableHeaderPrepend,
private string|Stringable $sortableHeaderAppend,
private readonly string|Stringable $sortableHeaderPrepend,
private readonly string|Stringable $sortableHeaderAppend,
private readonly ?string $sortableHeaderAscClass,
private readonly string|Stringable $sortableHeaderAscPrepend,
private readonly string|Stringable $sortableHeaderAscAppend,
Expand Down Expand Up @@ -117,34 +117,26 @@ private function getLinkSortValue(
if ($this->enableMultiSort) {
if ($order[$property] === 'asc') {
$order[$property] = 'desc';
} elseif (!empty($originalOrder) && count($order) === 1) {
$order[$property] = 'asc';
} else {
if (count($order) === 1 && !empty($originalOrder)) {
$order[$property] = 'asc';
} else {
unset($order[$property]);
}
unset($order[$property]);
}
} else {
if (isset($originalOrder[$property])) {
if ($order[$property] === $originalOrder[$property]) {
$order = [$property => $originalOrder[$property] === 'asc' ? 'desc' : 'asc'];
} else {
unset($order[$property]);
}
} elseif (isset($originalOrder[$property])) {
if ($order[$property] === $originalOrder[$property]) {
$order = [$property => $originalOrder[$property] === 'asc' ? 'desc' : 'asc'];
} else {
if ($order[$property] === 'asc') {
$order = [$property => 'desc'];
} else {
unset($order[$property]);
}
unset($order[$property]);
}
}
} else {
if ($this->enableMultiSort) {
$order[$property] = 'asc';
} elseif ($order[$property] === 'asc') {
$order = [$property => 'desc'];
} else {
$order = [$property => 'asc'];
unset($order[$property]);
}
} elseif ($this->enableMultiSort) {
$order[$property] = 'asc';
} else {
$order = [$property => 'asc'];
}

if ($this->isEqualOrders($order, $originalOrder)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Filter/Widget/DropdownFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function optionsData(
*
* @see Select::addAttributes()
*/
public function addAttributes(array $attributes): static
public function addAttributes(array $attributes): self
{
$new = clone $this;
$new->select = $this->getSelect()->addAttributes($attributes);
Expand Down
2 changes: 1 addition & 1 deletion src/Filter/Widget/TextInputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class TextInputFilter extends FilterWidget
*
* @see Input::addAttributes()
*/
public function addAttributes(array $attributes): static
public function addAttributes(array $attributes): self
{
$new = clone $this;
$new->input = $this->getInput()->addAttributes($attributes);
Expand Down
14 changes: 8 additions & 6 deletions src/GridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public function addTableClass(?string ...$class): self
*
* @param string|null ...$class One or many CSS classes.
*/
public function tableClass(?string ...$class): static
public function tableClass(?string ...$class): self
{
$new = clone $this;
$new->tableAttributes['class'] = array_filter($class, static fn ($c) => $c !== null);
Expand Down Expand Up @@ -350,7 +350,7 @@ public function addTbodyClass(?string ...$class): self
*
* @param string|null ...$class One or many CSS classes.
*/
public function tbodyClass(?string ...$class): static
public function tbodyClass(?string ...$class): self
{
$new = clone $this;
$new->tbodyAttributes['class'] = array_filter($class, static fn ($c) => $c !== null);
Expand Down Expand Up @@ -386,7 +386,7 @@ public function bodyCellAttributes(array $attributes): self
*
* @param array $attributes The tag attributes in terms of name-value pairs.
*/
public function sortableLinkAttributes(array $attributes): static
public function sortableLinkAttributes(array $attributes): self
{
$new = clone $this;
$new->sortableLinkAttributes = $attributes;
Expand Down Expand Up @@ -504,10 +504,10 @@ protected function renderItems(array $items, ValidationResult $filterValidationR
)
);
$content = [Html::submitButton()];
if ($this->urlConfig->getPageSizeParameterType() === UrlParameterType::QUERY && !empty($pageSize)) {
if (!empty($pageSize) && $this->urlConfig->getPageSizeParameterType() === UrlParameterType::QUERY) {
$content[] = Html::hiddenInput($this->urlConfig->getPageSizeParameterName(), $pageSize);
}
if ($this->urlConfig->getSortParameterType() === UrlParameterType::QUERY && !empty($sort)) {
if (!empty($sort) && $this->urlConfig->getSortParameterType() === UrlParameterType::QUERY) {
$content[] = Html::hiddenInput($this->urlConfig->getSortParameterName(), $sort);
}
$filtersForm = Html::form($url, 'GET', ['id' => $filterContext->formId, 'style' => 'display:none'])
Expand All @@ -530,10 +530,12 @@ protected function renderItems(array $items, ValidationResult $filterValidationR
$overrideOrderFields = [];
foreach ($columns as $i => $column) {
if ($renderers[$i] instanceof OverrideOrderFieldsColumnInterface) {
$overrideOrderFields = array_merge($overrideOrderFields, $renderers[$i]->getOverrideOrderFields($column));
$overrideOrderFields[] = $renderers[$i]->getOverrideOrderFields($column);
}
}

$overrideOrderFields = array_merge(...$overrideOrderFields);

if ($this->headerTableEnabled) {
$headerContext = new HeaderContext(
$this->getSort($dataReader),
Expand Down
2 changes: 1 addition & 1 deletion tests/Column/ActionColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ private function initialize(
$config = [
CurrentRoute::class => $currentRoute,
UrlGeneratorInterface::class => Mock::urlGenerator([], $currentRoute),
ActionColumnRenderer::class => $rendererDefinition ?? [
ActionColumnRenderer::class => [
'__construct()' => [
'defaultUrlCreator' => $defaultUrlCreator,
],
Expand Down
2 changes: 1 addition & 1 deletion tests/Support/Mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static function translator(
string $fallbackLocale = null,
EventDispatcherInterface $eventDispatcher = null
): TranslatorInterface {
return new Translator($locale, $fallbackLocale, $eventDispatcher);
return new Translator($locale, $fallbackLocale, 'app', $eventDispatcher);
}

/**
Expand Down

0 comments on commit e3b27cb

Please sign in to comment.