Skip to content

Commit e196c31

Browse files
xepozzvjik
andauthored
Add rector [batch] (#24)
Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
1 parent 95785bc commit e196c31

9 files changed

Lines changed: 73 additions & 104 deletions

File tree

.github/workflows/mssql.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,21 @@ jobs:
4545
- server:2019-latest
4646

4747
exclude:
48-
- php: 8.0
49-
mssql: server:2017-latest
50-
- php: 8.1
51-
mssql: server:2017-latest
48+
- php: 8.0
49+
mssql: server:2017-latest
50+
- php: 8.1
51+
mssql: server:2017-latest
5252

5353
services:
5454
mssql:
55-
image: mcr.microsoft.com/mssql/${{ matrix.mssql }}
56-
env:
57-
SA_PASSWORD: YourStrong!Passw0rd
58-
ACCEPT_EULA: Y
59-
MSSQL_PID: Developer
60-
ports:
61-
- 1433:1433
62-
options: --name=mssql --health-cmd="/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'YourStrong!Passw0rd' -Q 'SELECT 1'" --health-interval=10s --health-timeout=5s --health-retries=3
55+
image: mcr.microsoft.com/mssql/${{ matrix.mssql }}
56+
env:
57+
SA_PASSWORD: YourStrong!Passw0rd
58+
ACCEPT_EULA: Y
59+
MSSQL_PID: Developer
60+
ports:
61+
- 1433:1433
62+
options: --name=mssql --health-cmd="/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'YourStrong!Passw0rd' -Q 'SELECT 1'" --health-interval=10s --health-timeout=5s --health-retries=3
6363

6464
steps:
6565
- name: Checkout

.github/workflows/oracle.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ jobs:
4242

4343
services:
4444
oci:
45-
image: wnameless/oracle-xe-11g-r2:latest
46-
ports:
47-
- 1521:1521
48-
options: --name=oci
45+
image: wnameless/oracle-xe-11g-r2:latest
46+
ports:
47+
- 1521:1521
48+
options: --name=oci
4949

5050
steps:
5151
- name: Checkout

.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
@@ -34,6 +34,7 @@
3434
"require-dev": {
3535
"maglnet/composer-require-checker": "^4.2",
3636
"phpunit/phpunit": "^9.5",
37+
"rector/rector": "^0.14.3",
3738
"roave/infection-static-analysis-plugin": "^1.16",
3839
"spatie/phpunit-watcher": "^1.23",
3940
"vimeo/psalm": "^4.18",

rector.php

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

src/DbCache.php

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -36,44 +36,25 @@ final class DbCache implements CacheInterface
3636
{
3737
use LoggerAwareTrait;
3838

39-
/**
40-
* @var ConnectionInterface The database connection instance.
41-
*/
42-
private ConnectionInterface $db;
43-
4439
private string $loggerMessageDelete = 'Unable to delete cache data: ';
4540
private string $loggerMessageUpdate = 'Unable to update cache data: ';
4641

47-
/**
48-
* @var string The name of the database table to store the cache data. Defaults to "cache".
49-
*/
50-
private string $table;
51-
52-
/**
53-
* @var int The probability (parts per million) that garbage collection (GC) should be performed
54-
* when storing a piece of data in the cache. Defaults to 100, meaning 0.01% chance.
55-
* This number should be between 0 and 1000000. A value 0 meaning no GC will be performed at all.
56-
*/
57-
public int $gcProbability;
58-
5942
/**
6043
* @param ConnectionInterface $db The database connection instance.
6144
* @param string $table The name of the database table to store the cache data. Defaults to "cache".
6245
* @param int $gcProbability The probability (parts per million) that garbage collection (GC) should
6346
* be performed when storing a piece of data in the cache. Defaults to 100, meaning 0.01% chance.
6447
* This number should be between 0 and 1000000. A value 0 meaning no GC will be performed at all.
6548
*/
66-
public function __construct(ConnectionInterface $db, string $table = '{{%cache}}', int $gcProbability = 100)
67-
{
68-
$this->db = $db;
69-
$this->table = $table;
70-
$this->gcProbability = $gcProbability;
49+
public function __construct(
50+
private ConnectionInterface $db,
51+
private string $table = '{{%cache}}',
52+
public int $gcProbability = 100
53+
) {
7154
}
7255

7356
/**
7457
* Gets an instance of a database connection.
75-
*
76-
* @return ConnectionInterface
7758
*/
7859
public function getDb(): ConnectionInterface
7960
{
@@ -82,8 +63,6 @@ public function getDb(): ConnectionInterface
8263

8364
/**
8465
* Gets the name of the database table to store the cache data.
85-
*
86-
* @return string
8766
*/
8867
public function getTable(): string
8968
{
@@ -320,7 +299,7 @@ private function buildDataRow(string $id, ?int $ttl, mixed $value, bool $associa
320299
*/
321300
private function gc(): void
322301
{
323-
if (random_int(0, 1000000) < $this->gcProbability) {
302+
if (random_int(0, 1_000_000) < $this->gcProbability) {
324303
$this->db
325304
->createCommand()
326305
->delete($this->table, ['AND', ['>', 'expire', 0], ['<', 'expire', time()]])
@@ -369,19 +348,13 @@ private function iterableToArray(iterable $iterable): array
369348
return $iterable instanceof Traversable ? iterator_to_array($iterable) : (array) $iterable;
370349
}
371350

372-
/**
373-
* @param mixed $key
374-
*/
375351
private function validateKey(mixed $key): void
376352
{
377353
if (!is_string($key) || $key === '' || strpbrk($key, '{}()/\@:')) {
378354
throw new InvalidArgumentException('Invalid key value.');
379355
}
380356
}
381357

382-
/**
383-
* @param array $keys
384-
*/
385358
private function validateKeys(array $keys): void
386359
{
387360
/** @var mixed $key */

src/Migration/M202101140204CreateCache.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,13 @@
1414
*/
1515
final class M202101140204CreateCache implements RevertibleMigrationInterface
1616
{
17-
private MigrationInformerInterface $migrationInformer;
18-
19-
/**
20-
* @var DbCache An instance for creating a cache table.
21-
*/
22-
private DbCache $cache;
23-
24-
public function __construct(DbCache $cache, MigrationInformerInterface $migrationInformer)
25-
{
26-
$this->cache = $cache;
27-
$this->migrationInformer = $migrationInformer;
17+
public function __construct(
18+
/**
19+
* @var DbCache An instance for creating a cache table.
20+
*/
21+
private DbCache $cache,
22+
private MigrationInformerInterface $migrationInformer
23+
) {
2824
}
2925

3026
public function up(MigrationBuilder $b): void

tests/DbCacheTest.php

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ public function dataProvider(): array
5151
/**
5252
* @dataProvider dataProvider
5353
*
54-
* @param string $key
55-
* @param mixed $value
56-
*
5754
* @throws InvalidArgumentException
5855
*/
5956
public function testSet(string $key, mixed $value): void
@@ -66,9 +63,6 @@ public function testSet(string $key, mixed $value): void
6663
/**
6764
* @dataProvider dataProvider
6865
*
69-
* @param string $key
70-
* @param mixed $value
71-
*
7266
* @throws InvalidArgumentException
7367
*/
7468
public function testGet(string $key, mixed $value): void
@@ -82,9 +76,6 @@ public function testGet(string $key, mixed $value): void
8276
/**
8377
* @dataProvider dataProvider
8478
*
85-
* @param string $key
86-
* @param mixed $value
87-
*
8879
* @throws InvalidArgumentException
8980
*/
9081
public function testValueInCacheCannotBeChanged(string $key, mixed $value): void
@@ -106,9 +97,6 @@ public function testValueInCacheCannotBeChanged(string $key, mixed $value): void
10697
/**
10798
* @dataProvider dataProvider
10899
*
109-
* @param string $key
110-
* @param mixed $value
111-
*
112100
* @throws InvalidArgumentException
113101
*/
114102
public function testHas(string $key, mixed $value): void
@@ -131,9 +119,6 @@ public function testGetNonExistent(): void
131119
/**
132120
* @dataProvider dataProvider
133121
*
134-
* @param string $key
135-
* @param mixed $value
136-
*
137122
* @throws InvalidArgumentException
138123
*/
139124
public function testDelete(string $key, mixed $value): void
@@ -148,9 +133,6 @@ public function testDelete(string $key, mixed $value): void
148133
/**
149134
* @dataProvider dataProvider
150135
*
151-
* @param string $key
152-
* @param mixed $value
153-
*
154136
* @throws InvalidArgumentException
155137
*/
156138
public function testClear(string $key, mixed $value): void
@@ -177,8 +159,6 @@ public function dataProviderSetMultiple(): array
177159
/**
178160
* @dataProvider dataProviderSetMultiple
179161
*
180-
* @param int|null $ttl
181-
*
182162
* @throws InvalidArgumentException
183163
*/
184164
public function testSetMultiple(?int $ttl): void
@@ -251,9 +231,6 @@ public function dataProviderNormalizeTtl(): array
251231
/**
252232
* @dataProvider dataProviderNormalizeTtl
253233
*
254-
* @param mixed $ttl
255-
* @param mixed $expectedResult
256-
*
257234
* @throws ReflectionException
258235
*/
259236
public function testNormalizeTtl(mixed $ttl, mixed $expectedResult): void
@@ -300,9 +277,6 @@ public function getIterator(): ArrayIterator
300277
/**
301278
* @dataProvider iterableProvider
302279
*
303-
* @param array $array
304-
* @param iterable $iterable
305-
*
306280
* @throws InvalidArgumentException
307281
*/
308282
public function testValuesAsIterable(array $array, iterable $iterable): void
@@ -338,8 +312,6 @@ public function invalidKeyProvider(): array
338312

339313
/**
340314
* @dataProvider invalidKeyProvider
341-
*
342-
* @param string $key
343315
*/
344316
public function testGetThrowExceptionForInvalidKey(string $key): void
345317
{
@@ -349,8 +321,6 @@ public function testGetThrowExceptionForInvalidKey(string $key): void
349321

350322
/**
351323
* @dataProvider invalidKeyProvider
352-
*
353-
* @param string $key
354324
*/
355325
public function testSetThrowExceptionForInvalidKey(string $key): void
356326
{
@@ -360,8 +330,6 @@ public function testSetThrowExceptionForInvalidKey(string $key): void
360330

361331
/**
362332
* @dataProvider invalidKeyProvider
363-
*
364-
* @param string $key
365333
*/
366334
public function testDeleteThrowExceptionForInvalidKey(string $key): void
367335
{
@@ -371,8 +339,6 @@ public function testDeleteThrowExceptionForInvalidKey(string $key): void
371339

372340
/**
373341
* @dataProvider invalidKeyProvider
374-
*
375-
* @param string $key
376342
*/
377343
public function testGetMultipleThrowExceptionForInvalidKeys(string $key): void
378344
{
@@ -382,8 +348,6 @@ public function testGetMultipleThrowExceptionForInvalidKeys(string $key): void
382348

383349
/**
384350
* @dataProvider invalidKeyProvider
385-
*
386-
* @param string $key
387351
*/
388352
public function testDeleteMultipleThrowExceptionForInvalidKeys(string $key): void
389353
{
@@ -393,8 +357,6 @@ public function testDeleteMultipleThrowExceptionForInvalidKeys(string $key): voi
393357

394358
/**
395359
* @dataProvider invalidKeyProvider
396-
*
397-
* @param string $key
398360
*/
399361
public function testHasThrowExceptionForInvalidKey(string $key): void
400362
{

tests/TestCase.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ protected function getLogger(): Logger
4848
/**
4949
* Gets an inaccessible object property.
5050
*
51-
* @param object $object
52-
* @param string $propertyName
5351
* @param bool $revoke whether to make property inaccessible after getting.
54-
*
55-
* @return mixed
5652
*/
5753
protected function getInaccessibleProperty(object $object, string $propertyName, bool $revoke = true): mixed
5854
{
@@ -83,8 +79,6 @@ protected function getInaccessibleProperty(object $object, string $propertyName,
8379
* @param array $args The arguments to pass to the method.
8480
*
8581
* @throws ReflectionException
86-
*
87-
* @return mixed
8882
*/
8983
protected function invokeMethod(object $object, string $method, array $args = []): mixed
9084
{

0 commit comments

Comments
 (0)