Skip to content

Commit

Permalink
Add rector (#9)
Browse files Browse the repository at this point in the history
Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
  • Loading branch information
xepozz and vjik committed Jul 4, 2023
1 parent 703f31f commit 0e7d112
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 39 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/rector.yml
@@ -0,0 +1,23 @@
on:
pull_request:
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']
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -37,6 +37,7 @@
"require-dev": {
"maglnet/composer-require-checker": "^4.4",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.17.2",
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.18"
Expand Down
29 changes: 29 additions & 0 deletions rector.php
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Set\ValueObject\LevelSetList;

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

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

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

$rectorConfig->skip([
ClosureToArrowFunctionRector::class,
AddDefaultValueForUndefinedVariableRector::class,
]);
};
10 changes: 1 addition & 9 deletions src/RedisCache.php
Expand Up @@ -27,17 +27,11 @@
*/
final class RedisCache implements CacheInterface
{
/**
* @var ClientInterface $client Predis client instance to use.
*/
private ClientInterface $client;

/**
* @param ClientInterface $client Predis client instance to use.
*/
public function __construct(ClientInterface $client)
public function __construct(private ClientInterface $client)
{
$this->client = $client;
}

public function get(string $key, mixed $default = null): mixed
Expand Down Expand Up @@ -184,8 +178,6 @@ private function normalizeTtl(null|int|string|DateInterval $ttl): ?int
/**
* Converts iterable to array.
*
* @param iterable $iterable
*
* @return array
*/
private function iterableToArray(iterable $iterable): array
Expand Down
38 changes: 8 additions & 30 deletions tests/RedisCacheTest.php
Expand Up @@ -213,8 +213,6 @@ public function dataProviderSetMultiple(): array
/**
* @dataProvider dataProviderSetMultiple
*
* @param int|null $ttl
*
* @throws InvalidArgumentException
*/
public function testSetMultiple(?int $ttl): void
Expand All @@ -230,15 +228,13 @@ public function testSetMultiple(?int $ttl): void

foreach ($data as $key => $value) {
$this->assertSameExceptObject($value, $this->cache->get((string) $key));
$this->assertSame($ttl === null ? -1 : $ttl, $client->ttl($key));
$this->assertSame($ttl ?? -1, $client->ttl($key));
}
}

/**
* @dataProvider dataProviderSetMultiple
*
* @param int|null $ttl
*
* @throws InvalidArgumentException
*/
public function testReSetMultiple(?int $ttl): void
Expand Down Expand Up @@ -342,12 +338,9 @@ public function dataProviderNormalizeTtl(): array
/**
* @dataProvider dataProviderNormalizeTtl
*
* @param mixed $ttl
* @param mixed $expectedResult
*
* @throws ReflectionException
*/
public function testNormalizeTtl($ttl, $expectedResult): void
public function testNormalizeTtl(mixed $ttl, mixed $expectedResult): void
{
$reflection = new ReflectionObject($this->cache);
$method = $reflection->getMethod('normalizeTtl');
Expand Down Expand Up @@ -391,9 +384,6 @@ public function getIterator(): ArrayIterator
/**
* @dataProvider iterableProvider
*
* @param array $array
* @param iterable $iterable
*
* @throws InvalidArgumentException
*/
public function testValuesAsIterable(array $array, iterable $iterable): void
Expand All @@ -413,65 +403,53 @@ public function invalidKeyProvider(): array

/**
* @dataProvider invalidKeyProvider
*
* @param mixed $key
*/
public function testGetThrowExceptionForInvalidKey($key): void
public function testGetThrowExceptionForInvalidKey(mixed $key): void
{
$this->expectException(InvalidArgumentException::class);
$this->cache->get($key);
}

/**
* @dataProvider invalidKeyProvider
*
* @param mixed $key
*/
public function testSetThrowExceptionForInvalidKey($key): void
public function testSetThrowExceptionForInvalidKey(mixed $key): void
{
$this->expectException(InvalidArgumentException::class);
$this->cache->set($key, 'value');
}

/**
* @dataProvider invalidKeyProvider
*
* @param mixed $key
*/
public function testDeleteThrowExceptionForInvalidKey($key): void
public function testDeleteThrowExceptionForInvalidKey(mixed $key): void
{
$this->expectException(InvalidArgumentException::class);
$this->cache->delete($key);
}

/**
* @dataProvider invalidKeyProvider
*
* @param mixed $key
*/
public function testGetMultipleThrowExceptionForInvalidKeys($key): void
public function testGetMultipleThrowExceptionForInvalidKeys(mixed $key): void
{
$this->expectException(InvalidArgumentException::class);
$this->cache->getMultiple([$key]);
}

/**
* @dataProvider invalidKeyProvider
*
* @param mixed $key
*/
public function testDeleteMultipleThrowExceptionForInvalidKeys($key): void
public function testDeleteMultipleThrowExceptionForInvalidKeys(mixed $key): void
{
$this->expectException(InvalidArgumentException::class);
$this->cache->deleteMultiple([$key]);
}

/**
* @dataProvider invalidKeyProvider
*
* @param mixed $key
*/
public function testHasThrowExceptionForInvalidKey($key): void
public function testHasThrowExceptionForInvalidKey(mixed $key): void
{
$this->expectException(InvalidArgumentException::class);
$this->cache->has($key);
Expand Down

0 comments on commit 0e7d112

Please sign in to comment.