Skip to content

Cleanup + Add PHP 8.4 #243

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 9, 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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
os: >-
['ubuntu-latest', 'windows-latest']
php: >-
['8.1', '8.2', '8.3']
['8.1', '8.2', '8.3', '8.4']
2 changes: 1 addition & 1 deletion .github/workflows/composer-require-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.1', '8.2', '8.3']
['8.1', '8.2', '8.3', '8.4']
2 changes: 1 addition & 1 deletion .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.2']
['8.4']
secrets:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
2 changes: 1 addition & 1 deletion .github/workflows/rector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.3']
['8.4']
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.1', '8.2', '8.3']
['8.1', '8.2', '8.3', '8.4']
35 changes: 15 additions & 20 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,32 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^8.1",
"ext-json": "*",
"ext-mbstring": "*",
"psr/container": "^1.0|^2.0",
"php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0",
"psr/container": "^1.0 || ^2.0",
"yiisoft/arrays": "^3.1",
"yiisoft/data": "dev-master",
"yiisoft/factory": "^1.0",
"yiisoft/friendly-exception": "^1.0",
"yiisoft/html": "^3.0",
"yiisoft/injector": "^1.2",
"yiisoft/json": "^1.0",
"yiisoft/router": "^3.0",
"yiisoft/strings": "^2.0",
"yiisoft/translator": "^3.0",
"yiisoft/validator": "^2.0",
"yiisoft/view": "^12.0.0",
"yiisoft/widget": "^2.0"
},
"require-dev": {
"maglnet/composer-require-checker": "^4.7",
"nyholm/psr7": "^1.3",
"phpunit/phpunit": "^10.5",
"rector/rector": "^2.0.3",
"roave/infection-static-analysis-plugin": "^1.34",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^5.25",
"yiisoft/di": "^1.2",
"yiisoft/event-dispatcher": "^1.0",
"yiisoft/log": "^2.0",
"yiisoft/router-fastroute": "^3.0.1",
"yiisoft/test-support": "^3.0",
"yiisoft/translator-message-php": "^1.1"
"maglnet/composer-require-checker": "^4.7.1",
"phpunit/phpunit": "^10.5.45",
"rector/rector": "^2.0.8",
"roave/infection-static-analysis-plugin": "^1.35",
"spatie/phpunit-watcher": "^1.24",
"vimeo/psalm": "^5.26.1 || ^6.5",
"yiisoft/di": "^1.3",
"yiisoft/event-dispatcher": "^1.1",
"yiisoft/log": "^2.1",
"yiisoft/router-fastroute": "^3.1.0",
"yiisoft/test-support": "^3.0.1",
"yiisoft/translator-message-php": "^1.1.1"
},
"extra": {
"branch-alias": {
Expand All @@ -91,6 +85,7 @@
},
"config": {
"sort-packages": true,
"bump-after-update": "dev",
"allow-plugins": {
"infection/extension-installer": true,
"composer/package-versions-deprecated": true
Expand Down
27 changes: 11 additions & 16 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,23 @@

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Php80\Rector\Catch_\RemoveUnusedVariableInCatchRector;
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81,
]);

$rectorConfig->skip([
])
->withPhpSets(php81: true)
->withRules([
InlineConstructorDefaultToPropertyRector::class,
])
->withSkip([
ClosureToArrowFunctionRector::class,
NullToStrictStringFuncCallArgRector::class,
RemoveUnusedVariableInCatchRector::class => [
__DIR__ . '/src/BaseListView.php',
],
NullToStrictStringFuncCallArgRector::class,
]);
};
7 changes: 5 additions & 2 deletions src/Column/ActionColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
namespace Yiisoft\Yii\DataView\Column;

use Closure;
use Stringable;
use Yiisoft\Yii\DataView\Column\Base\DataContext;

/**
* `ActionColumn` is a column for the {@see GridView} widget that displays buttons for viewing and manipulating
* the items.
*
* @psalm-type UrlCreator = callable(string,DataContext):string
* @psalm-type ButtonRenderer = ActionButton|callable(string):string
* @psalm-type UrlCreator = callable(string, DataContext): string
* @psalm-type ButtonRenderer = ActionButton|callable(string): string
* @psalm-type TContent = scalar|Stringable|null|callable(array|object, DataContext): string
*/
final class ActionColumn implements ColumnInterface
{
Expand Down Expand Up @@ -41,6 +43,7 @@ final class ActionColumn implements ColumnInterface
* @param array $footerAttributes HTML attributes for the footer cell.
* @param bool $visible Whether the column is visible.
*
* @psalm-param TContent $content
* @psalm-param UrlCreator|null $urlCreator
* @psalm-param array<array-key, ButtonRenderer>|null $buttons
* @psalm-param array<string, bool|Closure>|null $visibleButtons
Expand Down
6 changes: 6 additions & 0 deletions src/Column/ActionColumnRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,18 @@ public function renderHeader(ColumnInterface $column, Cell $cell, HeaderContext

public function renderBody(ColumnInterface $column, Cell $cell, DataContext $context): Cell
{
/** @var ActionColumn $column This annotation needs for IDE only. */

$contentSource = $column->content;

if ($contentSource !== null) {
$content = (string)(is_callable($contentSource) ? $contentSource($context->data, $context) : $contentSource);
} else {
$buttons = $column->buttons ?? $this->buttons;
/**
* @var string $content We assume that we work with valid UTF-8 strings, so `preg_replace_callback()` never
* returns `null`.
*/
$content = preg_replace_callback(
'/{([\w\-\/]+)}/',
function (array $matches) use ($column, $buttons, $context): string {
Expand Down
9 changes: 8 additions & 1 deletion src/DetailView.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
use Yiisoft\Widget\Widget;
use Yiisoft\Yii\DataView\Field\DataField;

use function is_array;
use function is_bool;
use function is_object;

/**
* `DetailView` displays details about a single data item.
* The data can be either an object or an associative array.
Expand Down Expand Up @@ -420,10 +424,13 @@ private function renderValue(string $attribute, mixed $value): mixed
/**
* Remove double line breaks from a string.
*
* @param string $string String to remove double line breaks from.
* @param string $string The valid UTF-8 string to remove double line breaks from.
*/
private function removeDoubleLineBreaks(string $string): string
{
/**
* @var string We assume that `$string` is a valid UTF-8 string.
*/
return preg_replace('/(\R{2,})/', "\n", $string);
}
}
Loading