Skip to content

Commit 0e7d112

Browse files
xepozzvjik
andauthored
Add rector (#9)
Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
1 parent 703f31f commit 0e7d112

5 files changed

Lines changed: 62 additions & 39 deletions

File tree

.github/workflows/rector.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
secrets:
18+
token: ${{ secrets.YIISOFT_GITHUB_TOKEN }}
19+
with:
20+
os: >-
21+
['ubuntu-latest']
22+
php: >-
23+
['8.0']

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"require-dev": {
3838
"maglnet/composer-require-checker": "^4.4",
3939
"phpunit/phpunit": "^9.5",
40+
"rector/rector": "^0.17.2",
4041
"roave/infection-static-analysis-plugin": "^1.16",
4142
"spatie/phpunit-watcher": "^1.23",
4243
"vimeo/psalm": "^4.18"

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\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector;
8+
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
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+
ClosureToArrowFunctionRector::class,
27+
AddDefaultValueForUndefinedVariableRector::class,
28+
]);
29+
};

src/RedisCache.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,11 @@
2727
*/
2828
final class RedisCache implements CacheInterface
2929
{
30-
/**
31-
* @var ClientInterface $client Predis client instance to use.
32-
*/
33-
private ClientInterface $client;
34-
3530
/**
3631
* @param ClientInterface $client Predis client instance to use.
3732
*/
38-
public function __construct(ClientInterface $client)
33+
public function __construct(private ClientInterface $client)
3934
{
40-
$this->client = $client;
4135
}
4236

4337
public function get(string $key, mixed $default = null): mixed
@@ -184,8 +178,6 @@ private function normalizeTtl(null|int|string|DateInterval $ttl): ?int
184178
/**
185179
* Converts iterable to array.
186180
*
187-
* @param iterable $iterable
188-
*
189181
* @return array
190182
*/
191183
private function iterableToArray(iterable $iterable): array

tests/RedisCacheTest.php

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,6 @@ public function dataProviderSetMultiple(): array
213213
/**
214214
* @dataProvider dataProviderSetMultiple
215215
*
216-
* @param int|null $ttl
217-
*
218216
* @throws InvalidArgumentException
219217
*/
220218
public function testSetMultiple(?int $ttl): void
@@ -230,15 +228,13 @@ public function testSetMultiple(?int $ttl): void
230228

231229
foreach ($data as $key => $value) {
232230
$this->assertSameExceptObject($value, $this->cache->get((string) $key));
233-
$this->assertSame($ttl === null ? -1 : $ttl, $client->ttl($key));
231+
$this->assertSame($ttl ?? -1, $client->ttl($key));
234232
}
235233
}
236234

237235
/**
238236
* @dataProvider dataProviderSetMultiple
239237
*
240-
* @param int|null $ttl
241-
*
242238
* @throws InvalidArgumentException
243239
*/
244240
public function testReSetMultiple(?int $ttl): void
@@ -342,12 +338,9 @@ public function dataProviderNormalizeTtl(): array
342338
/**
343339
* @dataProvider dataProviderNormalizeTtl
344340
*
345-
* @param mixed $ttl
346-
* @param mixed $expectedResult
347-
*
348341
* @throws ReflectionException
349342
*/
350-
public function testNormalizeTtl($ttl, $expectedResult): void
343+
public function testNormalizeTtl(mixed $ttl, mixed $expectedResult): void
351344
{
352345
$reflection = new ReflectionObject($this->cache);
353346
$method = $reflection->getMethod('normalizeTtl');
@@ -391,9 +384,6 @@ public function getIterator(): ArrayIterator
391384
/**
392385
* @dataProvider iterableProvider
393386
*
394-
* @param array $array
395-
* @param iterable $iterable
396-
*
397387
* @throws InvalidArgumentException
398388
*/
399389
public function testValuesAsIterable(array $array, iterable $iterable): void
@@ -413,65 +403,53 @@ public function invalidKeyProvider(): array
413403

414404
/**
415405
* @dataProvider invalidKeyProvider
416-
*
417-
* @param mixed $key
418406
*/
419-
public function testGetThrowExceptionForInvalidKey($key): void
407+
public function testGetThrowExceptionForInvalidKey(mixed $key): void
420408
{
421409
$this->expectException(InvalidArgumentException::class);
422410
$this->cache->get($key);
423411
}
424412

425413
/**
426414
* @dataProvider invalidKeyProvider
427-
*
428-
* @param mixed $key
429415
*/
430-
public function testSetThrowExceptionForInvalidKey($key): void
416+
public function testSetThrowExceptionForInvalidKey(mixed $key): void
431417
{
432418
$this->expectException(InvalidArgumentException::class);
433419
$this->cache->set($key, 'value');
434420
}
435421

436422
/**
437423
* @dataProvider invalidKeyProvider
438-
*
439-
* @param mixed $key
440424
*/
441-
public function testDeleteThrowExceptionForInvalidKey($key): void
425+
public function testDeleteThrowExceptionForInvalidKey(mixed $key): void
442426
{
443427
$this->expectException(InvalidArgumentException::class);
444428
$this->cache->delete($key);
445429
}
446430

447431
/**
448432
* @dataProvider invalidKeyProvider
449-
*
450-
* @param mixed $key
451433
*/
452-
public function testGetMultipleThrowExceptionForInvalidKeys($key): void
434+
public function testGetMultipleThrowExceptionForInvalidKeys(mixed $key): void
453435
{
454436
$this->expectException(InvalidArgumentException::class);
455437
$this->cache->getMultiple([$key]);
456438
}
457439

458440
/**
459441
* @dataProvider invalidKeyProvider
460-
*
461-
* @param mixed $key
462442
*/
463-
public function testDeleteMultipleThrowExceptionForInvalidKeys($key): void
443+
public function testDeleteMultipleThrowExceptionForInvalidKeys(mixed $key): void
464444
{
465445
$this->expectException(InvalidArgumentException::class);
466446
$this->cache->deleteMultiple([$key]);
467447
}
468448

469449
/**
470450
* @dataProvider invalidKeyProvider
471-
*
472-
* @param mixed $key
473451
*/
474-
public function testHasThrowExceptionForInvalidKey($key): void
452+
public function testHasThrowExceptionForInvalidKey(mixed $key): void
475453
{
476454
$this->expectException(InvalidArgumentException::class);
477455
$this->cache->has($key);

0 commit comments

Comments
 (0)