Skip to content
Draft
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
21 changes: 21 additions & 0 deletions .github/workflows/rector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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
with:
os: >-
['ubuntu-latest']
php: >-
['8.0']
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.14.3",
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.18"
Expand Down
22 changes: 22 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
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,
]);
};
25 changes: 2 additions & 23 deletions src/ApcuCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,8 @@ private function normalizeTtl($ttl): int

/**
* Converts iterable to array. If provided value is not iterable it throws an InvalidArgumentException.
*
* @param mixed $iterable
*
* @return array
*/
private function iterableToArray($iterable): array
private function iterableToArray(mixed $iterable): array
{
if (!is_iterable($iterable)) {
throw new InvalidArgumentException('Iterable is expected, got ' . gettype($iterable));
Expand All @@ -158,29 +154,20 @@ private function iterableToArray($iterable): array
return $iterable instanceof Traversable ? iterator_to_array($iterable) : (array) $iterable;
}

/**
* @param mixed $key
*/
private function validateKey($key): void
private function validateKey(mixed $key): void
{
if (!is_string($key) || $key === '' || strpbrk($key, '{}()/\@:')) {
throw new InvalidArgumentException('Invalid key value.');
}
}

/**
* @param array $keys
*/
private function validateKeys(array $keys): void
{
foreach ($keys as $key) {
$this->validateKey($key);
}
}

/**
* @param array $values
*/
private function validateKeysOfValues(array $values): void
{
$keys = array_map('\strval', array_keys($values));
Expand All @@ -192,10 +179,6 @@ private function validateKeysOfValues(array $values): void
* representation of an integer ('123') the returned key from the cache doesn't equal neither to an integer nor a
* string ($key !== 123 and $key !== '123'). Coping element from the returned array one by one to the new array
* fixes this issue.
*
* @param array $values
*
* @return array
*/
private function normalizeAPCuOutput(array $values): array
{
Expand All @@ -210,10 +193,6 @@ private function normalizeAPCuOutput(array $values): array

/**
* Splits the array of values into two arrays, one with int keys and one with string keys.
*
* @param array $values
*
* @return array
*/
private function splitValuesByKeyType(array $values): array
{
Expand Down
46 changes: 11 additions & 35 deletions tests/ApcuCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ public function testClear($key, $value): void
/**
* @dataProvider dataProviderSetMultiple
*
* @param int|null $ttl
*
* @throws InvalidArgumentException
*/
public function testSetMultiple(?int $ttl): void
Expand Down Expand Up @@ -254,12 +252,9 @@ public function testNegativeTtl(): void
/**
* @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 @@ -293,9 +288,6 @@ public function dataProviderNormalizeTtl(): array
/**
* @dataProvider iterableProvider
*
* @param array $array
* @param iterable $iterable
*
* @throws InvalidArgumentException
*/
public function testValuesAsIterable(array $array, iterable $iterable): void
Expand All @@ -312,11 +304,11 @@ public function iterableProvider(): array
['a' => 1, 'b' => 2,],
['a' => 1, 'b' => 2,],
],
'ArrayIterator' => [
\ArrayIterator::class => [
['a' => 1, 'b' => 2,],
new ArrayIterator(['a' => 1, 'b' => 2,]),
],
'IteratorAggregate' => [
\IteratorAggregate::class => [
['a' => 1, 'b' => 2,],
new class () implements IteratorAggregate {
public function getIterator(): ArrayIterator
Expand Down Expand Up @@ -360,87 +352,71 @@ 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 testGetMultipleThrowExceptionForInvalidKeysNotIterable($key): void
public function testGetMultipleThrowExceptionForInvalidKeysNotIterable(mixed $key): void
{
$this->expectException(InvalidArgumentException::class);
$this->cache->getMultiple($key);
}

/**
* @dataProvider invalidKeyProvider
*
* @param mixed $key
*/
public function testSetMultipleThrowExceptionForInvalidKeysNotIterable($key): void
public function testSetMultipleThrowExceptionForInvalidKeysNotIterable(mixed $key): void
{
$this->expectException(InvalidArgumentException::class);
$this->cache->setMultiple($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 testDeleteMultipleThrowExceptionForInvalidKeysNotIterable($key): void
public function testDeleteMultipleThrowExceptionForInvalidKeysNotIterable(mixed $key): void
{
$this->expectException(InvalidArgumentException::class);
$this->cache->deleteMultiple($key);
Expand Down