Skip to content

Commit

Permalink
Raise PHP version to 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Nov 24, 2023
1 parent 5aad36a commit ab16536
Show file tree
Hide file tree
Showing 24 changed files with 195 additions and 556 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
os: >-
['ubuntu-latest', 'windows-latest']
php: >-
['8.0', '8.1']
['8.1', '8.2']
2 changes: 1 addition & 1 deletion .github/workflows/composer-require-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.0']
['8.1']
13 changes: 3 additions & 10 deletions .github/workflows/rector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,16 @@ on:
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'
push:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

name: rector

jobs:
rector:
uses: yiisoft/actions/.github/workflows/rector.yml@master
secrets:
token: ${{ secrets.YIISOFT_GITHUB_TOKEN }}
with:
os: >-
['ubuntu-latest']
php: >-
['8.0']
['8.2']
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.0', '8.1']
['8.1', '8.2']
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^8.0",
"php": "^8.1",
"ext-json": "*",
"ext-mbstring": "*",
"psr/container": "^1.0|^2.0",
Expand All @@ -44,10 +44,10 @@
"maglnet/composer-require-checker": "^4.2",
"nyholm/psr7": "^1.3",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.18.0",
"rector/rector": "^0.18.10",
"roave/infection-static-analysis-plugin": "^1.25",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.30|^5.2",
"vimeo/psalm": "^5.2",
"yiisoft/di": "^1.2",
"yiisoft/event-dispatcher": "^1.0",
"yiisoft/log": "^2.0",
Expand Down
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_80,
LevelSetList::UP_TO_PHP_81,
]);
};
2 changes: 1 addition & 1 deletion src/BaseListView.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract class BaseListView extends Widget
/**
* A name for {@see CategorySource} used with translator ({@see TranslatorInterface}) by default.
*/
public const DEFAULT_TRANSLATION_CATEGORY = 'yii-dataview';
final public const DEFAULT_TRANSLATION_CATEGORY = 'yii-dataview';

/**
* @var TranslatorInterface A translator instance used for translations of messages. If it was not set
Expand Down
126 changes: 17 additions & 109 deletions src/Column/ActionColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,121 +12,29 @@
*/
final class ActionColumn implements ColumnInterface
{
/**
* @var callable|null
*/
private $urlCreator;

/**
* @psalm-param array<string,Closure> $buttons
* @psalm-param array<string,bool|Closure> $visibleButtons
*/
public function __construct(
private string $primaryKey = 'id',
private string $template = "{view}\n{update}\n{delete}",
private ?string $routeName = null,
private array $urlParamsConfig = [],
private ?array $urlArguments = null,
private array $urlQueryParameters = [],
?callable $urlCreator = null,
private ?string $header = null,
private ?string $footer = null,
private mixed $content = null,
private array $buttons = [],
private array $visibleButtons = [],
private array $columnAttributes = [],
private array $headerAttributes = [],
private array $bodyAttributes = [],
private array $footerAttributes = [],
private bool $visible = true,
public readonly string $primaryKey = 'id',
public readonly string $template = "{view}\n{update}\n{delete}",
public readonly ?string $routeName = null,
public readonly array $urlParamsConfig = [],
public readonly ?array $urlArguments = null,
public readonly array $urlQueryParameters = [],
public readonly ?Closure $urlCreator = null,
public readonly ?string $header = null,
public readonly ?string $footer = null,
public readonly mixed $content = null,
public readonly array $buttons = [],
public readonly array $visibleButtons = [],
public readonly array $columnAttributes = [],
public readonly array $headerAttributes = [],
public readonly array $bodyAttributes = [],
public readonly array $footerAttributes = [],
private readonly bool $visible = true,
) {
$this->urlCreator = $urlCreator;
}

public function getPrimaryKey(): string
{
return $this->primaryKey;
}

public function getTemplate(): string
{
return $this->template;
}

public function getRouteName(): ?string
{
return $this->routeName;
}

public function getUrlParamsConfig(): array
{
return $this->urlParamsConfig;
}

public function getUrlArguments(): ?array
{
return $this->urlArguments;
}

public function getUrlQueryParameters(): array
{
return $this->urlQueryParameters;
}

public function getUrlCreator(): ?callable
{
return $this->urlCreator;
}

public function getHeader(): ?string
{
return $this->header;
}

public function getFooter(): ?string
{
return $this->footer;
}

public function getContent(): mixed
{
return $this->content;
}

/**
* @psalm-return array<string,Closure>
*/
public function getButtons(): array
{
return $this->buttons;
}

/**
* @psalm-return array<string,bool|Closure>
*/
public function getVisibleButtons(): array
{
return $this->visibleButtons;
}

public function getColumnAttributes(): array
{
return $this->columnAttributes;
}

public function getHeaderAttributes(): array
{
return $this->headerAttributes;
}

public function getBodyAttributes(): array
{
return $this->bodyAttributes;
}

public function getFooterAttributes(): array
{
return $this->footerAttributes;
}

public function isVisible(): bool
Expand Down
50 changes: 25 additions & 25 deletions src/Column/ActionColumnRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@
final class ActionColumnRenderer implements ColumnRendererInterface
{
public function __construct(
private UrlGeneratorInterface $urlGenerator,
private CurrentRoute $currentRoute,
private readonly UrlGeneratorInterface $urlGenerator,
private readonly CurrentRoute $currentRoute,
) {
}

public function renderColumn(ColumnInterface $column, Cell $cell, GlobalContext $context): Cell
{
$this->checkColumn($column);
return $cell->addAttributes($column->getColumnAttributes());
return $cell->addAttributes($column->columnAttributes);

Check warning on line 27 in src/Column/ActionColumnRenderer.php

View check run for this annotation

Codecov / codecov/patch

src/Column/ActionColumnRenderer.php#L27

Added line #L27 was not covered by tests
}

public function renderHeader(ColumnInterface $column, Cell $cell, GlobalContext $context): Cell
{
$this->checkColumn($column);
return $cell
->content($column->getHeader() ?? 'Actions')
->addAttributes($column->getHeaderAttributes());
->content($column->header ?? 'Actions')
->addAttributes($column->headerAttributes);
}

public function renderFilter(ColumnInterface $column, Cell $cell, GlobalContext $context): ?Cell
Expand All @@ -44,12 +44,12 @@ public function renderBody(ColumnInterface $column, Cell $cell, DataContext $con
{
$this->checkColumn($column);

$contentSource = $column->getContent();
$contentSource = $column->content;

if ($contentSource !== null) {
$content = (string)(is_callable($contentSource) ? $contentSource($context) : $contentSource);
} else {
$buttons = empty($column->getButtons()) ? $this->getDefaultButtons() : $column->getButtons();
$buttons = empty($column->buttons) ? $this->getDefaultButtons() : $column->buttons;
$content = preg_replace_callback(
'/{([\w\-\/]+)}/',
function (array $matches) use ($column, $buttons, $context): string {
Expand All @@ -59,25 +59,25 @@ function (array $matches) use ($column, $buttons, $context): string {
$this->isVisibleButton(
$column,
$name,
$context->getData(),
$context->getKey(),
$context->getIndex()
$context->data,
$context->key,
$context->index,
) &&
isset($buttons[$name])
) {
$url = $this->createUrl($column, $name, $context->getData(), $context->getKey());
$url = $this->createUrl($column, $name, $context->data, $context->key);
return (string)$buttons[$name]($url);
}

return '';
},
$column->getTemplate()
$column->template
);
$content = trim($content);
}

return $cell
->addAttributes($column->getBodyAttributes())
->addAttributes($column->bodyAttributes)
->content(PHP_EOL . $content . PHP_EOL)
->encode(false);
}
Expand All @@ -86,21 +86,21 @@ public function renderFooter(ColumnInterface $column, Cell $cell, GlobalContext
{
$this->checkColumn($column);

if ($column->getFooter() !== null) {
$cell = $cell->content($column->getFooter());
if ($column->footer !== null) {
$cell = $cell->content($column->footer);
}

return $cell->addAttributes($column->getFooterAttributes());
return $cell->addAttributes($column->footerAttributes);
}

private function createUrl(ActionColumn $column, string $action, array|object $data, mixed $key): string
{
if ($column->getUrlCreator() !== null) {
return (string) ($column->getUrlCreator())($action, $data, $key);
if ($column->urlCreator !== null) {
return (string) ($column->urlCreator)($action, $data, $key);
}

$primaryKey = $column->getPrimaryKey();
$routeName = $column->getRouteName();
$primaryKey = $column->primaryKey;
$routeName = $column->routeName;

if ($primaryKey !== '') {
$key = $data[$primaryKey] ?? $key;
Expand All @@ -114,17 +114,17 @@ private function createUrl(ActionColumn $column, string $action, array|object $d


$urlParamsConfig = array_merge(
$column->getUrlParamsConfig(),
$column->urlParamsConfig,
is_array($key) ? $key : [$primaryKey => $key]
);

if ($column->getUrlArguments() !== null) {
if ($column->urlArguments !== null) {
/** @psalm-var array<string,string> */
$urlArguments = array_merge($column->getUrlArguments(), $urlParamsConfig);
$urlArguments = array_merge($column->urlArguments, $urlParamsConfig);
$urlQueryParameters = [];
} else {
$urlArguments = [];
$urlQueryParameters = array_merge($column->getUrlQueryParameters(), $urlParamsConfig);
$urlQueryParameters = array_merge($column->urlQueryParameters, $urlParamsConfig);
}

return $this->urlGenerator->generate($route, $urlArguments, $urlQueryParameters);
Expand All @@ -137,7 +137,7 @@ private function isVisibleButton(
mixed $key,
int $index
): bool {
$visibleButtons = $column->getVisibleButtons();
$visibleButtons = $column->visibleButtons;

if (empty($visibleButtons)) {
return true;
Expand Down
28 changes: 4 additions & 24 deletions src/Column/Base/DataContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,10 @@
final class DataContext
{
public function __construct(
private ColumnInterface $column,
private array|object $data,
private mixed $key,
private int $index,
public readonly ColumnInterface $column,
public readonly array|object $data,
public readonly mixed $key,
public readonly int $index,
) {
}

public function getColumn(): ColumnInterface
{
return $this->column;
}

public function getData(): array|object
{
return $this->data;
}

public function getKey(): mixed
{
return $this->key;
}

public function getIndex(): int
{
return $this->index;
}
}
Loading

0 comments on commit ab16536

Please sign in to comment.