Skip to content

Commit f97e955

Browse files
authored
Merge pull request #215 from kitloong/feature/lint
Lint
2 parents 5cdacea + fff24fb commit f97e955

28 files changed

+70
-82
lines changed

.github/FUNDING.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
# These are supported funding model platforms
2-
3-
custom: ['https://www.buymeacoffee.com/kitloong']
1+
github: kitloong
2+
buy_me_a_coffee: kitloong

src/MigrateGenerateCommand.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -626,21 +626,12 @@ protected function makeSchema(): Schema
626626
throw new Exception('Failed to find database driver.');
627627
}
628628

629-
switch ($driver) {
630-
case Driver::MYSQL->value:
631-
return $this->schema = app(MySQLSchema::class);
632-
633-
case Driver::PGSQL->value:
634-
return $this->schema = app(PgSQLSchema::class);
635-
636-
case Driver::SQLITE->value:
637-
return $this->schema = app(SQLiteSchema::class);
638-
639-
case Driver::SQLSRV->value:
640-
return $this->schema = app(SQLSrvSchema::class);
641-
642-
default:
643-
throw new Exception('The database driver in use is not supported.');
644-
}
629+
return match ($driver) {
630+
Driver::MYSQL->value => $this->schema = app(MySQLSchema::class),
631+
Driver::PGSQL->value => $this->schema = app(PgSQLSchema::class),
632+
Driver::SQLITE->value => $this->schema = app(SQLiteSchema::class),
633+
Driver::SQLSRV->value => $this->schema = app(SQLSrvSchema::class),
634+
default => throw new Exception('The database driver in use is not supported.'),
635+
};
645636
}
646637
}

src/Migration/Blueprint/DBStatementBlueprint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DBStatementBlueprint implements WritableBlueprint
2929
*
3030
* @param string $sql The SQL statement.
3131
*/
32-
public function __construct(private string $sql)
32+
public function __construct(private readonly string $sql)
3333
{
3434
}
3535

src/Migration/Blueprint/DBUnpreparedBlueprint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DBUnpreparedBlueprint implements WritableBlueprint
2929
*
3030
* @param string $sql The SQL statement.
3131
*/
32-
public function __construct(private string $sql)
32+
public function __construct(private readonly string $sql)
3333
{
3434
}
3535

src/Migration/Blueprint/Method.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Method
2222
* @param \KitLoong\MigrationsGenerator\Enum\Migrations\Method\MethodName $name Method name.
2323
* @param mixed ...$values Method arguments.
2424
*/
25-
public function __construct(private MethodName $name, mixed ...$values)
25+
public function __construct(private readonly MethodName $name, mixed ...$values)
2626
{
2727
$this->values = $values;
2828
$this->chains = [];

src/Migration/Blueprint/Property.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Property
99
/**
1010
* Property constructor.
1111
*/
12-
public function __construct(private PropertyName $name, private mixed $value)
12+
public function __construct(private readonly PropertyName $name, private readonly mixed $value)
1313
{
1414
}
1515

src/Migration/Blueprint/SchemaBlueprint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class SchemaBlueprint implements WritableBlueprint
5050
* @param string $table Table name.
5151
* @param \KitLoong\MigrationsGenerator\Enum\Migrations\Method\SchemaBuilder $schemaBuilder SchemaBuilder name.
5252
*/
53-
public function __construct(string $table, private SchemaBuilder $schemaBuilder)
53+
public function __construct(string $table, private readonly SchemaBuilder $schemaBuilder)
5454
{
5555
$this->table = $this->stripTablePrefix($table);
5656
}

src/Migration/Blueprint/TableBlueprint.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,11 @@ public function toString(): string
115115
$lines = [];
116116

117117
foreach ($this->lines as $line) {
118-
switch (true) {
119-
case $line instanceof Property:
120-
$lines[] = $this->propertyToString($line);
121-
break;
122-
123-
case $line instanceof Method:
124-
$lines[] = $this->methodToString($line);
125-
break;
126-
127-
default:
128-
$lines[] = $this->convertFromAnyTypeToString($line);
129-
}
118+
$lines[] = match (true) {
119+
$line instanceof Property => $this->propertyToString($line),
120+
$line instanceof Method => $this->methodToString($line),
121+
default => $this->convertFromAnyTypeToString($line),
122+
};
130123
}
131124

132125
return $this->flattenLines($lines, $this->numberOfPrefixTab);

src/Migration/ForeignKeyMigration.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ class ForeignKeyMigration
1919
use TableName;
2020

2121
public function __construct(
22-
private ForeignKeyGenerator $foreignKeyGenerator,
23-
private MigrationNameHelper $migrationNameHelper,
24-
private MigrationWriter $migrationWriter,
25-
private Setting $setting,
26-
private SquashWriter $squashWriter,
22+
private readonly ForeignKeyGenerator $foreignKeyGenerator,
23+
private readonly MigrationNameHelper $migrationNameHelper,
24+
private readonly MigrationWriter $migrationWriter,
25+
private readonly Setting $setting,
26+
private readonly SquashWriter $squashWriter,
2727
) {
2828
}
2929

src/Migration/Generator/ColumnGenerator.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
class ColumnGenerator
2020
{
2121
public function __construct(
22-
private CharsetModifier $charsetModifier,
23-
private CollationModifier $collationModifier,
24-
private CommentModifier $commentModifier,
25-
private DefaultModifier $defaultModifier,
26-
private IndexModifier $indexModifier,
27-
private NullableModifier $nullableModifier,
28-
private StoredAsModifier $storedAsModifier,
29-
private VirtualAsModifier $virtualAsModifier,
22+
private readonly CharsetModifier $charsetModifier,
23+
private readonly CollationModifier $collationModifier,
24+
private readonly CommentModifier $commentModifier,
25+
private readonly DefaultModifier $defaultModifier,
26+
private readonly IndexModifier $indexModifier,
27+
private readonly NullableModifier $nullableModifier,
28+
private readonly StoredAsModifier $storedAsModifier,
29+
private readonly VirtualAsModifier $virtualAsModifier,
3030
) {
3131
}
3232

src/Migration/Generator/IndexGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class IndexGenerator
1313
{
14-
public function __construct(private IndexNameHelper $indexNameHelper)
14+
public function __construct(private readonly IndexNameHelper $indexNameHelper)
1515
{
1616
}
1717

src/Migration/Generator/Modifiers/CharsetModifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class CharsetModifier implements Modifier
1313
{
14-
public function __construct(private Setting $setting)
14+
public function __construct(private readonly Setting $setting)
1515
{
1616
}
1717

src/Migration/Generator/Modifiers/CollationModifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class CollationModifier implements Modifier
1212
{
13-
public function __construct(private Setting $setting)
13+
public function __construct(private readonly Setting $setting)
1414
{
1515
}
1616

src/Migration/Generator/Modifiers/IndexModifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class IndexModifier implements Modifier
1212
{
13-
public function __construct(private IndexNameHelper $indexNameHelper)
13+
public function __construct(private readonly IndexNameHelper $indexNameHelper)
1414
{
1515
}
1616

src/Migration/ProcedureMigration.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
class ProcedureMigration
1515
{
1616
public function __construct(
17-
private MigrationNameHelper $migrationNameHelper,
18-
private MigrationWriter $migrationWriter,
19-
private Setting $setting,
20-
private SquashWriter $squashWriter,
17+
private readonly MigrationNameHelper $migrationNameHelper,
18+
private readonly MigrationWriter $migrationWriter,
19+
private readonly Setting $setting,
20+
private readonly SquashWriter $squashWriter,
2121
) {
2222
}
2323

src/Migration/Squash.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99

1010
class Squash
1111
{
12-
public function __construct(private SquashWriter $squashWriter, private MigrationNameHelper $migrationNameHelper, private Setting $setting)
13-
{
12+
public function __construct(
13+
private readonly SquashWriter $squashWriter,
14+
private readonly MigrationNameHelper $migrationNameHelper,
15+
private readonly Setting $setting,
16+
) {
1417
}
1518

1619
/**

src/Migration/TableMigration.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ class TableMigration
2828
use TableName;
2929

3030
public function __construct(
31-
private ColumnGenerator $columnGenerator,
32-
private MigrationNameHelper $migrationNameHelper,
33-
private IndexGenerator $indexGenerator,
34-
private MigrationWriter $migrationWriter,
35-
private Setting $setting,
36-
private SquashWriter $squashWriter,
31+
private readonly ColumnGenerator $columnGenerator,
32+
private readonly MigrationNameHelper $migrationNameHelper,
33+
private readonly IndexGenerator $indexGenerator,
34+
private readonly MigrationWriter $migrationWriter,
35+
private readonly Setting $setting,
36+
private readonly SquashWriter $squashWriter,
3737
) {
3838
}
3939

src/Migration/ViewMigration.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ class ViewMigration
1717
use TableName;
1818

1919
public function __construct(
20-
private MigrationNameHelper $migrationNameHelper,
21-
private MigrationWriter $migrationWriter,
22-
private Setting $setting,
23-
private SquashWriter $squashWriter,
20+
private readonly MigrationNameHelper $migrationNameHelper,
21+
private readonly MigrationWriter $migrationWriter,
22+
private readonly Setting $setting,
23+
private readonly SquashWriter $squashWriter,
2424
) {
2525
}
2626

src/Migration/Writer/MigrationWriter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
class MigrationWriter
1414
{
15-
public function __construct(private MigrationStub $migrationStub)
15+
public function __construct(private readonly MigrationStub $migrationStub)
1616
{
1717
}
1818

src/Migration/Writer/SquashWriter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class SquashWriter
1313
{
14-
public function __construct(private MigrationNameHelper $migrationNameHelper, private MigrationStub $migrationStub)
14+
public function __construct(private readonly MigrationNameHelper $migrationNameHelper, private readonly MigrationStub $migrationStub)
1515
{
1616
}
1717

src/Repositories/Entities/MariaDB/CheckConstraint.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public function __construct(stdClass $column)
3636
$this->constraintSchema = $lowerKey['constraint_schema'];
3737
$this->tableName = $lowerKey['table_name'];
3838
$this->constraintName = $lowerKey['constraint_name'];
39-
$this->level = null;
4039

4140
if (isset($lowerKey['level'])) {
4241
$this->level = $lowerKey['level'];

src/Repositories/Entities/MySQL/ShowColumn.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ShowColumn
2323

2424
private string $key;
2525

26-
private ?string $default = null;
26+
private ?string $default;
2727

2828
private string $extra;
2929

src/Repositories/Entities/PgSQL/IndexDefinition.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
class IndexDefinition
66
{
7-
public function __construct(private string $tableName, private string $indexName, private string $indexDef)
8-
{
7+
public function __construct(
8+
private readonly string $tableName,
9+
private readonly string $indexName,
10+
private readonly string $indexDef,
11+
) {
912
}
1013

1114
public function getTableName(): string

src/Repositories/Entities/ProcedureDefinition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class ProcedureDefinition
66
{
7-
public function __construct(private string $name, private string $definition)
7+
public function __construct(private readonly string $name, private readonly string $definition)
88
{
99
}
1010

src/Repositories/Entities/SQLSrv/ColumnDefinition.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ class ColumnDefinition
1515

1616
private bool $notnull;
1717

18-
private ?string $default = null;
18+
private ?string $default;
1919

2020
private int $scale;
2121

2222
private int $precision;
2323

2424
private bool $autoincrement;
2525

26-
private ?string $collation = null;
26+
private ?string $collation;
2727

28-
private ?string $comment = null;
28+
private ?string $comment;
2929

3030
public function __construct(stdClass $column)
3131
{

src/Repositories/SQLSrvRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private function getTableWhereClause(string $table, string $schemaColumn, string
143143
{
144144
$schema = 'SCHEMA_NAME()';
145145

146-
if (strpos($table, '.') !== false) {
146+
if (str_contains($table, '.')) {
147147
[$schema, $table] = explode('.', $table);
148148
$schema = $this->quoteStringLiteral($schema);
149149
}

src/Support/IndexNameHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class IndexNameHelper
1010
{
11-
public function __construct(private Setting $setting)
11+
public function __construct(private readonly Setting $setting)
1212
{
1313
}
1414

src/Support/MigrationNameHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class MigrationNameHelper
99
{
1010
use TableName;
1111

12-
public function __construct(private Setting $setting)
12+
public function __construct(private readonly Setting $setting)
1313
{
1414
}
1515

0 commit comments

Comments
 (0)