Skip to content

Commit abc1ac3

Browse files
committed
feat: run rector, and fix issues
1 parent 17f8a72 commit abc1ac3

File tree

10 files changed

+55
-42
lines changed

10 files changed

+55
-42
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,8 @@ jobs:
4141
- name: Run static analysis
4242
run: composer run-script phpstan
4343

44+
- name: Run rector
45+
run: composer run-script rector-dry-run
46+
4447
- name: Run phpcs analysis
4548
run: composer run-script phpcs

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
"scripts": {
3939
"phpcs": "phpcs",
4040
"phpstan": "phpstan analyse --memory-limit=512M",
41-
"test": "php ./vendor/bin/phpunit"
41+
"test": "php ./vendor/bin/phpunit",
42+
"rector": "php ./vendor/bin/rector process example src test",
43+
"rector-dry-run": "php ./vendor/bin/rector process example src test --dry-run"
4244
},
4345
"config": {
4446
"allow-plugins": {

rector.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
use Rector\Config\RectorConfig;
5+
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
6+
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
7+
use Rector\DeadCode\Rector\Node\RemoveNonExistingVarAnnotationRector;
8+
use Rector\DeadCode\Rector\Property\RemoveUselessReadOnlyTagRector;
9+
use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector;
10+
11+
return RectorConfig::configure()
12+
->withRules([
13+
RemoveUselessParamTagRector::class,
14+
RemoveUselessReturnTagRector::class,
15+
RemoveUselessReadOnlyTagRector::class,
16+
RemoveNonExistingVarAnnotationRector::class,
17+
RemoveUselessVarTagRector::class,
18+
])
19+
->withPreparedSets(
20+
typeDeclarations: true,
21+
)
22+
->withPhpSets(
23+
php81: true,
24+
);

src/DataObject/Sql/Database/Table/ColumnCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ColumnCollection implements ColumnCollectionInterface
99
/** @var ColumnInterface[] */
1010
private array $columns = [];
1111

12-
public function add(ColumnInterface $column)
12+
public function add(ColumnInterface $column): void
1313
{
1414
$this->columns[$column->getName()] = $column;
1515
}

src/Parser/CassandraParser.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,15 @@ protected function getColumnsWithoutRequiredTypeParametersFromCreateTableSchema(
219219
protected function trimNames(string ...$strings): array
220220
{
221221
return array_map(
222-
function ($string) {
223-
return $this->trimName($string);
224-
},
222+
fn($string): string => $this->trimName($string),
225223
$strings
226224
);
227225
}
228226

229227
protected function getFormatedParameters(string ...$strings): array
230228
{
231229
return array_map(
232-
function ($string) {
233-
return $this->getFormatedParameter($string);
234-
},
230+
fn($string): string => $this->getFormatedParameter($string),
235231
$strings
236232
);
237233
}
@@ -535,9 +531,7 @@ private function handleMapAndSetConnections(
535531
ConnectionCollectionInterface $connections
536532
): ConnectionCollection {
537533
$allDefinedTables = array_map(
538-
function (TableInterface $table) {
539-
return $table->getName();
540-
},
534+
fn(TableInterface $table): string => $table->getName(),
541535
$tables->getIterator()->getArrayCopy()
542536
);
543537

src/Parser/MysqlParser.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,15 @@ protected function getColumnsWithoutRequiredTypeParametersFromCreateTableSchema(
184184
protected function trimNames(string ...$strings): array
185185
{
186186
return array_map(
187-
function ($string) {
188-
return $this->trimName($string);
189-
},
187+
fn($string): string => $this->trimName($string),
190188
$strings
191189
);
192190
}
193191

194192
protected function getFormatedParameters(string ...$strings): array
195193
{
196194
return array_map(
197-
function ($string) {
198-
return $this->getFormatedParameter($string);
199-
},
195+
fn($string): string => $this->getFormatedParameter($string),
200196
$strings
201197
);
202198
}

src/Parser/ParserAbstract.php

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,10 @@ private function generateConnections(array $conditions): ConnectionCollectionInt
129129
$matches['childTableColumns'][$index]
130130
);
131131
$childTableColumns = array_map(
132-
static function ($column): string {
133-
return trim(
134-
$column,
135-
'` '
136-
);
137-
},
132+
static fn(string $column): string => trim(
133+
$column,
134+
'` '
135+
),
138136
$childTableColumns
139137
);
140138

@@ -143,12 +141,10 @@ static function ($column): string {
143141
(string) $matches['parentTableColumns'][$index]
144142
);
145143
$parentTableColumns = array_map(
146-
static function ($column): string {
147-
return trim(
148-
$column,
149-
'` '
150-
);
151-
},
144+
static fn(string $column): string => trim(
145+
$column,
146+
'` '
147+
),
152148
$parentTableColumns
153149
);
154150

@@ -219,12 +215,12 @@ protected function removeMultiLineComments($schema): string
219215
protected function getSafeRandomString(string $schema): string
220216
{
221217
do {
222-
$safeRandomString = (string)rand();
218+
$safeRandomString = (string)random_int(0, mt_getrandmax());
223219
} while (
224-
strpos(
220+
str_contains(
225221
$schema,
226222
$safeRandomString
227-
) !== false
223+
)
228224
);
229225

230226
return $safeRandomString;
@@ -234,12 +230,10 @@ protected function replaceCharactersInString(string $schema, array $replacePairs
234230
{
235231
return preg_replace_callback(
236232
'#(\'.*\')#Uxsm',
237-
static function ($matches) use ($replacePairs): string {
238-
return strtr(
239-
$matches[0],
240-
$replacePairs
241-
);
242-
},
233+
static fn($matches): string => strtr(
234+
$matches[0],
235+
$replacePairs
236+
),
243237
$schema
244238
);
245239
}

test/Unit/Parser/CassandraParserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function testParser(
6868
SplFileInfo $file,
6969
SchemaInterface $schemaObject,
7070
ConnectionCollectionInterface $forcedConnections
71-
) {
71+
): void {
7272
$sut = new CassandraParser();
7373
$result = $sut->run(file_get_contents($file->getRealPath()), $forcedConnections); //@todo
7474

test/Unit/Parser/MysqlParserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function testParser(
6767
SplFileInfo $file,
6868
SchemaInterface $schemaObject,
6969
ConnectionCollectionInterface $forcedConnections
70-
) {
70+
): void {
7171
$sut = new MysqlParser();
7272
$result = $sut->run(file_get_contents($file->getRealPath()), $forcedConnections); //@todo
7373

test/Unit/Template/Plantuml/V1TemplateTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ public function getSchemaProvider(): array
373373
/**
374374
* @dataProvider getSchemaProvider
375375
*/
376-
public function testExport(SchemaInterface $schema, string $extendOutput)
376+
public function testExport(SchemaInterface $schema, string $extendOutput): void
377377
{
378378
$template = file_get_contents(__DIR__ . '/../../../../src/Template/Plantuml/v1.twig');
379379

@@ -388,7 +388,7 @@ public function testExport(SchemaInterface $schema, string $extendOutput)
388388
protected function trim($text): string
389389
{
390390
return trim(
391-
preg_replace(
391+
(string) preg_replace(
392392
'/^\s+/m',
393393
'',
394394
(string) $text

0 commit comments

Comments
 (0)