Skip to content

Commit c15bbf5

Browse files
xepozzvjik
andauthored
Add rector [batch] (#41)
Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
1 parent 5226e69 commit c15bbf5

5 files changed

Lines changed: 58 additions & 44 deletions

File tree

.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']

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"require-dev": {
2828
"maglnet/composer-require-checker": "^4.4",
2929
"phpunit/phpunit": "^9.5",
30+
"rector/rector": "^0.15.13",
3031
"roave/infection-static-analysis-plugin": "^1.16",
3132
"spatie/phpunit-watcher": "^1.23",
3233
"vimeo/psalm": "^4.30|^5.6"

rector.php

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

src/Memcached.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ private function normalizeTtl(DateInterval|int|string|null $ttl): int
161161

162162
$ttl = (int) $ttl;
163163

164-
if ($ttl > 2592000) {
164+
if ($ttl > 2_592_000) {
165165
return $ttl + time();
166166
}
167167

@@ -170,10 +170,6 @@ private function normalizeTtl(DateInterval|int|string|null $ttl): int
170170

171171
/**
172172
* Converts iterable to array.
173-
*
174-
* @param iterable $iterable
175-
*
176-
* @return array
177173
*/
178174
private function iterableToArray(iterable $iterable): array
179175
{
@@ -182,9 +178,6 @@ private function iterableToArray(iterable $iterable): array
182178
}
183179

184180
/**
185-
* @param array $servers
186-
* @param string $persistentId
187-
*
188181
* @throws CacheException If an error occurred when adding servers to the server pool.
189182
* @throws InvalidArgumentException If the servers format is incorrect.
190183
*/
@@ -203,10 +196,6 @@ private function initServers(array $servers, string $persistentId): void
203196

204197
/**
205198
* Returns the list of the servers that are not in the pool.
206-
*
207-
* @param array $servers
208-
*
209-
* @return array
210199
*/
211200
private function getNewServers(array $servers): array
212201
{

tests/MemcachedTest.php

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ public function testClear($key, $value): void
189189
/**
190190
* @dataProvider dataProviderSetMultiple
191191
*
192-
* @param int|null $ttl
193-
*
194192
* @throws InvalidArgumentException
195193
*/
196194
public function testSetMultiple(?int $ttl): void
@@ -292,16 +290,13 @@ public function dataProviderNormalizeTtl(): array
292290
/**
293291
* @dataProvider dataProviderNormalizeTtl
294292
*
295-
* @param mixed $ttl
296-
* @param mixed $expectedResult
297-
*
298293
* @throws ReflectionException
299294
*/
300-
public function testNormalizeTtl($ttl, $expectedResult): void
295+
public function testNormalizeTtl(mixed $ttl, mixed $expectedResult): void
301296
{
302297
$cache = $this->createCacheInstance();
303298
$ttl = $this->invokeMethod($cache, 'normalizeTtl', [$ttl]);
304-
$ttl = $ttl < 2592001 ? $ttl : $ttl - time();
299+
$ttl = $ttl < 2_592_001 ? $ttl : $ttl - time();
305300

306301
$this->assertSameExceptObject($expectedResult, $ttl);
307302
}
@@ -339,9 +334,6 @@ public function getIterator(): ArrayIterator
339334
/**
340335
* @dataProvider iterableProvider
341336
*
342-
* @param array $array
343-
* @param iterable $iterable
344-
*
345337
* @throws InvalidArgumentException
346338
*/
347339
public function testValuesAsIterable(array $array, iterable $iterable): void
@@ -475,10 +467,8 @@ public function invalidKeyProvider(): array
475467

476468
/**
477469
* @dataProvider invalidKeyProvider
478-
*
479-
* @param mixed $key
480470
*/
481-
public function testGetThrowExceptionForInvalidKey($key): void
471+
public function testGetThrowExceptionForInvalidKey(mixed $key): void
482472
{
483473
$cache = $this->createCacheInstance();
484474
$this->expectException(InvalidArgumentException::class);
@@ -487,10 +477,8 @@ public function testGetThrowExceptionForInvalidKey($key): void
487477

488478
/**
489479
* @dataProvider invalidKeyProvider
490-
*
491-
* @param mixed $key
492480
*/
493-
public function testSetThrowExceptionForInvalidKey($key): void
481+
public function testSetThrowExceptionForInvalidKey(mixed $key): void
494482
{
495483
$cache = $this->createCacheInstance();
496484
$this->expectException(InvalidArgumentException::class);
@@ -499,10 +487,8 @@ public function testSetThrowExceptionForInvalidKey($key): void
499487

500488
/**
501489
* @dataProvider invalidKeyProvider
502-
*
503-
* @param mixed $key
504490
*/
505-
public function testDeleteThrowExceptionForInvalidKey($key): void
491+
public function testDeleteThrowExceptionForInvalidKey(mixed $key): void
506492
{
507493
$cache = $this->createCacheInstance();
508494
$this->expectException(InvalidArgumentException::class);
@@ -511,10 +497,8 @@ public function testDeleteThrowExceptionForInvalidKey($key): void
511497

512498
/**
513499
* @dataProvider invalidKeyProvider
514-
*
515-
* @param mixed $key
516500
*/
517-
public function testGetMultipleThrowExceptionForInvalidKeys($key): void
501+
public function testGetMultipleThrowExceptionForInvalidKeys(mixed $key): void
518502
{
519503
$cache = $this->createCacheInstance();
520504
$this->expectException(InvalidArgumentException::class);
@@ -523,10 +507,8 @@ public function testGetMultipleThrowExceptionForInvalidKeys($key): void
523507

524508
/**
525509
* @dataProvider invalidKeyProvider
526-
*
527-
* @param mixed $key
528510
*/
529-
public function testDeleteMultipleThrowExceptionForInvalidKeys($key): void
511+
public function testDeleteMultipleThrowExceptionForInvalidKeys(mixed $key): void
530512
{
531513
$cache = $this->createCacheInstance();
532514
$this->expectException(InvalidArgumentException::class);
@@ -557,7 +539,6 @@ private function createCacheInstance($persistentId = '', array $servers = []): C
557539
*
558540
* @param $object
559541
* @param $method
560-
* @param array $args
561542
* @param bool $revoke whether to make method inaccessible after execution
562543
*
563544
* @throws ReflectionException
@@ -581,12 +562,9 @@ private function invokeMethod($object, $method, array $args = [], bool $revoke =
581562
/**
582563
* Sets an inaccessible object property to a designated value.
583564
*
584-
* @param object $object
585-
* @param string $propertyName
586-
* @param mixed $value
587565
* @param bool $revoke whether to make property inaccessible after setting
588566
*/
589-
private function setInaccessibleProperty(object $object, string $propertyName, $value, bool $revoke = true): void
567+
private function setInaccessibleProperty(object $object, string $propertyName, mixed $value, bool $revoke = true): void
590568
{
591569
$class = new ReflectionClass($object);
592570

@@ -606,8 +584,6 @@ private function setInaccessibleProperty(object $object, string $propertyName, $
606584
/**
607585
* Gets an inaccessible object property.
608586
*
609-
* @param object $object
610-
* @param string $propertyName
611587
* @param bool $revoke whether to make property inaccessible after getting
612588
*
613589
* @return mixed

0 commit comments

Comments
 (0)