Skip to content

Commit f14de1e

Browse files
authored
Add rector, raise minimum PHP version to ^8.0, change return type of immutable methods in ViewInterface from self to static
1 parent b87d31d commit f14de1e

28 files changed

Lines changed: 190 additions & 351 deletions

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ jobs:
2828
os: >-
2929
['ubuntu-latest', 'windows-latest']
3030
php: >-
31-
['7.4', '8.0', '8.1']
31+
['8.0', '8.1']

.github/workflows/rector.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
on:
2+
pull_request:
3+
paths-ignore:
4+
- 'docs/**'
5+
- 'README.md'
6+
- 'CHANGELOG.md'
7+
- '.gitignore'
8+
- '.gitattributes'
9+
- 'infection.json.dist'
10+
- 'psalm.xml'
11+
12+
name: rector
13+
14+
jobs:
15+
rector:
16+
uses: yiisoft/actions/.github/workflows/rector.yml@master
17+
with:
18+
os: >-
19+
['ubuntu-latest']
20+
php: >-
21+
['8.0']

.github/workflows/static.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ jobs:
2828
os: >-
2929
['ubuntu-latest']
3030
php: >-
31-
['7.4', '8.0', '8.1']
31+
['8.0', '8.1']

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Yii View Change Log
22

3-
## 6.0.1 under development
3+
## 7.0.0 under development
44

5-
- no changes in this release.
5+
- Enh #211: Raise minimum PHP version to `^8.0` (@xepozz, @vjik)
6+
- Chg #211: Change return type of immutable methods in `ViewInterface` from `self` to `static` (@vjik)
67

78
## 6.0.0 July 21, 2022
89

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ to be usable separately.
2121

2222
## Requirements
2323

24-
- PHP 7.4 or higher.
24+
- PHP 8.0 or higher.
2525

2626
## Installation
2727

2828
The package could be installed via composer:
2929

3030
```shell
31-
composer require yiisoft/view --prefer-dist
31+
composer require yiisoft/view
3232
```
3333

3434
## General usage

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
}
2828
],
2929
"require": {
30-
"php": "^7.4|^8.0",
30+
"php": "^8.0",
3131
"psr/event-dispatcher": "1.0.0",
3232
"psr/event-dispatcher-implementation": "1.0.0",
3333
"yiisoft/arrays": "^2.0",
@@ -38,6 +38,7 @@
3838
},
3939
"require-dev": {
4040
"phpunit/phpunit": "^9.5",
41+
"rector/rector": "^0.14.3",
4142
"roave/infection-static-analysis-plugin": "^1.18",
4243
"spatie/phpunit-watcher": "^1.23",
4344
"vimeo/psalm": "^4.24",

rector.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
6+
use Rector\Config\RectorConfig;
7+
use Rector\Php70\Rector\FuncCall\NonVariableToVariableOnFunctionCallRector;
8+
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
9+
use Rector\Set\ValueObject\LevelSetList;
10+
11+
return static function (RectorConfig $rectorConfig): void {
12+
$rectorConfig->paths([
13+
__DIR__ . '/src',
14+
__DIR__ . '/tests',
15+
]);
16+
17+
// register a single rule
18+
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
19+
20+
// define sets of rules
21+
$rectorConfig->sets([
22+
LevelSetList::UP_TO_PHP_80,
23+
]);
24+
25+
$rectorConfig->skip([
26+
NonVariableToVariableOnFunctionCallRector::class => [__DIR__ . '/src/PhpTemplateRenderer.php'],
27+
RemoveExtraParametersRector::class => [__DIR__ . '/src/PhpTemplateRenderer.php'],
28+
]);
29+
};

src/Cache/CachedContent.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
use Yiisoft\Cache\Dependency\Dependency;
1212

1313
use function array_merge;
14-
use function get_class;
15-
use function gettype;
1614
use function is_string;
17-
use function is_object;
1815
use function sprintf;
1916
use function strtr;
2017

@@ -23,8 +20,6 @@
2320
*/
2421
final class CachedContent
2522
{
26-
private string $id;
27-
private CacheInterface $cache;
2823
private CacheKeyNormalizer $cacheKeyNormalizer;
2924

3025
/**
@@ -43,10 +38,12 @@ final class CachedContent
4338
* @param DynamicContent[] $dynamicContents The dynamic content instances.
4439
* @param string[] $variations List of string factors that would cause the variation of the content being cached.
4540
*/
46-
public function __construct(string $id, CacheInterface $cache, array $dynamicContents = [], array $variations = [])
47-
{
48-
$this->id = $id;
49-
$this->cache = $cache;
41+
public function __construct(
42+
private string $id,
43+
private CacheInterface $cache,
44+
array $dynamicContents = [],
45+
array $variations = []
46+
) {
5047
$this->cacheKeyNormalizer = new CacheKeyNormalizer();
5148
$this->setDynamicContents($dynamicContents);
5249
$this->setVariations($variations);
@@ -98,7 +95,7 @@ public function get(): ?string
9895
*/
9996
private function cacheKey(): string
10097
{
101-
return $this->cacheKeyNormalizer->normalize(array_merge([__CLASS__, $this->id], $this->variations));
98+
return $this->cacheKeyNormalizer->normalize(array_merge([self::class, $this->id], $this->variations));
10299
}
103100

104101
/**
@@ -134,7 +131,7 @@ private function setDynamicContents(array $dynamicContents): void
134131
if (!($dynamicContent instanceof DynamicContent)) {
135132
throw new InvalidArgumentException(sprintf(
136133
'Invalid dynamic content "%s" specified. It must be a "%s" instance.',
137-
is_object($dynamicContent) ? get_class($dynamicContent) : gettype($dynamicContent),
134+
get_debug_type($dynamicContent),
138135
DynamicContent::class,
139136
));
140137
}
@@ -154,7 +151,7 @@ private function setVariations(array $variations): void
154151
if (!is_string($variation)) {
155152
throw new InvalidArgumentException(sprintf(
156153
'Invalid variation "%s" specified. It must be a string type.',
157-
is_object($variation) ? get_class($variation) : gettype($variation),
154+
get_debug_type($variation),
158155
));
159156
}
160157

src/Cache/DynamicContent.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
*/
1010
final class DynamicContent
1111
{
12-
private string $id;
13-
private array $parameters;
14-
1512
/**
1613
* @var callable
1714
*/
@@ -22,11 +19,12 @@ final class DynamicContent
2219
* @param callable $contentGenerator PHP callable with the signature: `function (array $parameters = []): string;`.
2320
* @param array $parameters The parameters (name-value pairs) that will be passed in the $contentGenerator context.
2421
*/
25-
public function __construct(string $id, callable $contentGenerator, array $parameters = [])
26-
{
27-
$this->id = $id;
22+
public function __construct(
23+
private string $id,
24+
callable $contentGenerator,
25+
private array $parameters = []
26+
) {
2827
$this->contentGenerator = $contentGenerator;
29-
$this->parameters = $parameters;
3028
}
3129

3230
/**

src/Event/View/AfterRender.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,17 @@
1212
*/
1313
final class AfterRender implements AfterRenderEventInterface
1414
{
15-
private View $view;
16-
17-
/**
18-
* @var string The view file being rendered.
19-
*/
20-
private string $file;
21-
2215
/**
23-
* @var array The parameters array passed to the {@see View::render()} or {@see View::renderFile()} method.
16+
* @param string $file The view file being rendered.
17+
* @param array $parameters The parameters array passed to the {@see View::render()} or {@see View::renderFile()}
18+
* method.
2419
*/
25-
private array $parameters;
26-
27-
private string $result;
28-
29-
public function __construct(View $view, string $file, array $parameters, string $result)
30-
{
31-
$this->view = $view;
32-
$this->file = $file;
33-
$this->parameters = $parameters;
34-
$this->result = $result;
20+
public function __construct(
21+
private View $view,
22+
private string $file,
23+
private array $parameters,
24+
private string $result
25+
) {
3526
}
3627

3728
public function getView(): View

0 commit comments

Comments
 (0)