Skip to content

Commit 71a45c9

Browse files
Sairahcazgithub-actions[bot]
authored andcommitted
Fix styling
1 parent dc87e21 commit 71a45c9

8 files changed

+58
-61
lines changed

config/schema-rules.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
* Always skip this columns
2020
*/
2121
'skip_columns' => ['created_at', 'updated_at', 'deleted_at'],
22-
22+
2323
];

src/Contracts/SchemaRulesResolverInterface.php

-4
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@
55
interface SchemaRulesResolverInterface
66
{
77
/**
8-
* @param string $table
9-
* @param array $columns
108
* @return array
119
*/
1210
public function __construct(string $table, array $columns = []);
1311

1412
/**
1513
* Generate the rules of the provided tables schema.
16-
*
17-
* @return array
1814
*/
1915
public function generate(): array;
2016
}

src/LaravelSchemaRulesServiceProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function register()
4949

5050
break;
5151
default: throw new UnsupportedDbDriverException('This db driver is not supported: '.$driver);
52-
};
52+
}
5353

5454
return new $class(...array_values($parameters));
5555
});

src/Resolvers/BaseSchemaRulesResolver.php

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
abstract class BaseSchemaRulesResolver implements SchemaRulesResolverInterface
99
{
1010
private string $table;
11+
1112
private array $columns;
1213

1314
public function __construct(string $table, array $columns = [])

src/Resolvers/SchemaRulesResolverMySql.php

+17-17
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected function getColumnsDefinitionsFromTable()
3737
$databaseName = config('database.connections.mysql.database');
3838
$tableName = $this->table();
3939

40-
$tableColumns = collect(DB::select('SHOW COLUMNS FROM ' . $tableName))->keyBy('Field')->toArray();
40+
$tableColumns = collect(DB::select('SHOW COLUMNS FROM '.$tableName))->keyBy('Field')->toArray();
4141

4242
$foreignKeys = DB::select("
4343
SELECT k.COLUMN_NAME, k.REFERENCED_TABLE_NAME, k.REFERENCED_COLUMN_NAME
@@ -61,45 +61,45 @@ protected function getColumnsDefinitionsFromTable()
6161
protected function generateColumnRules(stdClass $column): array
6262
{
6363
$columnRules = [];
64-
$columnRules[] = $column->Null === "YES" ? 'nullable' : 'required' ;
64+
$columnRules[] = $column->Null === 'YES' ? 'nullable' : 'required';
6565

6666
if (! empty($column->Foreign)) {
67-
$columnRules[] = "exists:".implode(',', $column->Foreign);
67+
$columnRules[] = 'exists:'.implode(',', $column->Foreign);
6868

6969
return $columnRules;
7070
}
7171

7272
$type = Str::of($column->Type);
7373
switch (true) {
7474
case $type == 'tinyint(1)' && config('schema-rules.tinyint1_to_bool'):
75-
$columnRules[] = "boolean";
75+
$columnRules[] = 'boolean';
7676

7777
break;
7878
case $type->contains('char'):
79-
$columnRules[] = "string";
80-
$columnRules[] = "min:".config('schema-rules.string_min_length');
81-
$columnRules[] = "max:".filter_var($type, FILTER_SANITIZE_NUMBER_INT);
79+
$columnRules[] = 'string';
80+
$columnRules[] = 'min:'.config('schema-rules.string_min_length');
81+
$columnRules[] = 'max:'.filter_var($type, FILTER_SANITIZE_NUMBER_INT);
8282

8383
break;
8484
case $type == 'text':
85-
$columnRules[] = "string";
86-
$columnRules[] = "min:".config('schema-rules.string_min_length');
85+
$columnRules[] = 'string';
86+
$columnRules[] = 'min:'.config('schema-rules.string_min_length');
8787

8888
break;
8989
case $type->contains('int'):
90-
$columnRules[] = "integer";
91-
$sign = ($type->contains('unsigned')) ? 'unsigned' : 'signed' ;
90+
$columnRules[] = 'integer';
91+
$sign = ($type->contains('unsigned')) ? 'unsigned' : 'signed';
9292
$intType = $type->before(' unsigned')->__toString();
9393

9494
// prevent int(xx) for mysql
95-
$intType = preg_replace("/\([^)]+\)/", "", $intType);
95+
$intType = preg_replace("/\([^)]+\)/", '', $intType);
9696

97-
if(! array_key_exists($intType, self::$integerTypes)) {
98-
$intType = "int";
97+
if (! array_key_exists($intType, self::$integerTypes)) {
98+
$intType = 'int';
9999
}
100100

101-
$columnRules[] = "min:".self::$integerTypes[$intType][$sign][0];
102-
$columnRules[] = "max:".self::$integerTypes[$intType][$sign][1];
101+
$columnRules[] = 'min:'.self::$integerTypes[$intType][$sign][0];
102+
$columnRules[] = 'max:'.self::$integerTypes[$intType][$sign][1];
103103

104104
break;
105105
case $type->contains('double') ||
@@ -108,7 +108,7 @@ protected function generateColumnRules(stdClass $column): array
108108
$type->contains('float'):
109109
// should we do more specific here?
110110
// some kind of regex validation for double, double unsigned, double(8, 2), decimal etc...?
111-
$columnRules[] = "numeric";
111+
$columnRules[] = 'numeric';
112112

113113
break;
114114
case $type->contains('enum') || $type->contains('set'):

src/Resolvers/SchemaRulesResolverPgSql.php

+14-14
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ protected function getColumnsDefinitionsFromTable()
2121
$tableName = $this->table();
2222

2323
$tableColumns = collect(DB::select(
24-
"
24+
'
2525
SELECT column_name, data_type, character_maximum_length, is_nullable, column_default
2626
FROM INFORMATION_SCHEMA.COLUMNS
27-
WHERE table_name = :table",
27+
WHERE table_name = :table',
2828
['table' => $tableName]
2929
))->keyBy('column_name')->toArray();
3030

@@ -57,35 +57,35 @@ protected function getColumnsDefinitionsFromTable()
5757
protected function generateColumnRules(stdClass $column): array
5858
{
5959
$columnRules = [];
60-
$columnRules[] = $column->is_nullable === "YES" ? 'nullable' : 'required' ;
60+
$columnRules[] = $column->is_nullable === 'YES' ? 'nullable' : 'required';
6161

6262
if (! empty($column->Foreign)) {
63-
$columnRules[] = "exists:".implode(',', $column->Foreign);
63+
$columnRules[] = 'exists:'.implode(',', $column->Foreign);
6464

6565
return $columnRules;
6666
}
6767

6868
$type = Str::of($column->data_type);
6969
switch (true) {
7070
case $type == 'boolean':
71-
$columnRules[] = "boolean";
71+
$columnRules[] = 'boolean';
7272

7373
break;
7474
case $type->contains('char'):
75-
$columnRules[] = "string";
76-
$columnRules[] = "min:".config('schema-rules.string_min_length');
77-
$columnRules[] = "max:".$column->character_maximum_length;
75+
$columnRules[] = 'string';
76+
$columnRules[] = 'min:'.config('schema-rules.string_min_length');
77+
$columnRules[] = 'max:'.$column->character_maximum_length;
7878

7979
break;
8080
case $type == 'text':
81-
$columnRules[] = "string";
82-
$columnRules[] = "min:".config('schema-rules.string_min_length');
81+
$columnRules[] = 'string';
82+
$columnRules[] = 'min:'.config('schema-rules.string_min_length');
8383

8484
break;
8585
case $type->contains('int'):
86-
$columnRules[] = "integer";
87-
$columnRules[] = "min:" . self::$integerTypes[$type->__toString()][0];
88-
$columnRules[] = "max:" . self::$integerTypes[$type->__toString()][1];
86+
$columnRules[] = 'integer';
87+
$columnRules[] = 'min:'.self::$integerTypes[$type->__toString()][0];
88+
$columnRules[] = 'max:'.self::$integerTypes[$type->__toString()][1];
8989

9090
break;
9191
case $type->contains('double') ||
@@ -94,7 +94,7 @@ protected function generateColumnRules(stdClass $column): array
9494
$type->contains('real'):
9595
// should we do more specific here?
9696
// some kind of regex validation for double, double unsigned, double(8, 2), decimal etc...?
97-
$columnRules[] = "numeric";
97+
$columnRules[] = 'numeric';
9898

9999
break;
100100
// unfortunately, it's not so easy in pgsql to find out if a column is an enum

src/Resolvers/SchemaRulesResolverSqlite.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,35 @@ protected function getColumnsDefinitionsFromTable()
2929
protected function generateColumnRules(stdClass $column): array
3030
{
3131
$columnRules = [];
32-
$columnRules[] = $column->notnull ? 'required' : 'nullable' ;
32+
$columnRules[] = $column->notnull ? 'required' : 'nullable';
3333

3434
if (! empty($column->Foreign)) {
35-
$columnRules[] = "exists:".implode(',', $column->Foreign);
35+
$columnRules[] = 'exists:'.implode(',', $column->Foreign);
3636

3737
return $columnRules;
3838
}
3939

4040
$type = Str::of($column->type);
4141
switch (true) {
4242
case $type == 'tinyint(1)' && config('schema-rules.tinyint1_to_bool'):
43-
$columnRules[] = "boolean";
43+
$columnRules[] = 'boolean';
4444

4545
break;
4646
case $type == 'varchar' || $type == 'text':
47-
$columnRules[] = "string";
48-
$columnRules[] = "min:".config('schema-rules.min_string');
47+
$columnRules[] = 'string';
48+
$columnRules[] = 'min:'.config('schema-rules.min_string');
4949

5050
break;
5151
case $type == 'integer':
52-
$columnRules[] = "integer";
53-
$columnRules[] = "min:-9223372036854775808";
54-
$columnRules[] = "max:9223372036854775807";
52+
$columnRules[] = 'integer';
53+
$columnRules[] = 'min:-9223372036854775808';
54+
$columnRules[] = 'max:9223372036854775807';
5555

5656
break;
5757
case $type->contains('numeric') || $type->contains('float'):
5858
// should we do more specific here?
5959
// some kind of regex validation for double, double unsigned, double(8, 2), decimal etc...?
60-
$columnRules[] = "numeric";
60+
$columnRules[] = 'numeric';
6161

6262
break;
6363
case $type == 'date' || $type == 'time' || $type == 'datetime':

tests/SchemaRulesTest.php

+15-15
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
$this->expectException(\Symfony\Component\Console\Exception\InvalidArgumentException::class);
3232

33-
$this->artisan("schema:generate-rules", [
33+
$this->artisan('schema:generate-rules', [
3434
'foo' => $this->tableName,
3535
]);
3636
});
@@ -42,7 +42,7 @@
4242

4343
$this->expectException(\Symfony\Component\Console\Exception\InvalidOptionException::class);
4444

45-
$this->artisan("schema:generate-rules", [
45+
$this->artisan('schema:generate-rules', [
4646
'table' => $this->tableName,
4747
'--foo' => 'test_bool',
4848
]);
@@ -55,7 +55,7 @@
5555

5656
$this->expectException(TableDoesNotExistException::class);
5757

58-
$this->artisan("schema:generate-rules", [
58+
$this->artisan('schema:generate-rules', [
5959
'table' => $this->tableName.'1',
6060
]);
6161
});
@@ -67,7 +67,7 @@
6767

6868
$this->expectException(MultipleTablesSuppliedException::class);
6969

70-
$this->artisan("schema:generate-rules", [
70+
$this->artisan('schema:generate-rules', [
7171
'table' => $this->tableName.',tests2',
7272
]);
7373
});
@@ -79,7 +79,7 @@
7979

8080
$this->expectException(ColumnDoesNotExistException::class);
8181

82-
$this->artisan("schema:generate-rules", [
82+
$this->artisan('schema:generate-rules', [
8383
'table' => $this->tableName,
8484
'--columns' => 'foo',
8585
]);
@@ -106,7 +106,7 @@
106106
$stringNullableColumnName => ['nullable', 'string', 'min:1', 'max:255'],
107107
]);
108108

109-
$this->artisan("schema:generate-rules", [
109+
$this->artisan('schema:generate-rules', [
110110
'table' => $this->tableName,
111111
])->assertSuccessful();
112112
});
@@ -132,7 +132,7 @@
132132
$boolNullableColumnName => ['nullable', 'boolean'],
133133
]);
134134

135-
$this->artisan("schema:generate-rules", [
135+
$this->artisan('schema:generate-rules', [
136136
'table' => $this->tableName,
137137
])->assertSuccessful();
138138
});
@@ -170,7 +170,7 @@
170170
$textColumnName => ['required', 'string', 'min:1'],
171171
]);
172172

173-
$this->artisan("schema:generate-rules", [
173+
$this->artisan('schema:generate-rules', [
174174
'table' => $this->tableName,
175175
])->assertSuccessful();
176176
});
@@ -234,7 +234,7 @@
234234
$bigintNullableColumnName => ['nullable', 'integer', 'min:'.$integerTypes['bigint']['signed'][0], 'max:'.$integerTypes['bigint']['signed'][1]],
235235
]);
236236

237-
$this->artisan("schema:generate-rules", [
237+
$this->artisan('schema:generate-rules', [
238238
'table' => $this->tableName,
239239
])->assertSuccessful();
240240
});
@@ -282,7 +282,7 @@
282282
$decimalNullableColumnName => ['nullable', 'numeric'],
283283
]);
284284

285-
$this->artisan("schema:generate-rules", [
285+
$this->artisan('schema:generate-rules', [
286286
'table' => $this->tableName,
287287
])->assertSuccessful();
288288
});
@@ -310,7 +310,7 @@
310310
$setColumnName => ['required', 'string', 'in:'.implode(',', $allowed)],
311311
]);
312312

313-
$this->artisan("schema:generate-rules", [
313+
$this->artisan('schema:generate-rules', [
314314
'table' => $this->tableName,
315315
])->assertSuccessful();
316316
});
@@ -344,7 +344,7 @@
344344
$timestampColumnName => ['required', 'date', 'after_or_equal:1970-01-01 00:00:01', 'before_or_equal:2038-01-19 03:14:07'],
345345
]);
346346

347-
$this->artisan("schema:generate-rules", [
347+
$this->artisan('schema:generate-rules', [
348348
'table' => $this->tableName,
349349
])->assertSuccessful();
350350
});
@@ -364,7 +364,7 @@
364364
$jsonColumnName => ['required', 'json'],
365365
]);
366366

367-
$this->artisan("schema:generate-rules", [
367+
$this->artisan('schema:generate-rules', [
368368
'table' => $this->tableName,
369369
])->assertSuccessful();
370370
});
@@ -396,7 +396,7 @@
396396
$foreignKeyColumnName => ['required', 'exists:'.implode(',', $constrained)],
397397
]);
398398

399-
$this->artisan("schema:generate-rules", [
399+
$this->artisan('schema:generate-rules', [
400400
'table' => $foreignTable,
401401
])->assertSuccessful();
402402

@@ -426,7 +426,7 @@
426426
$stringColumnName => ['required', 'string', 'min:1', 'max:255'],
427427
]);
428428

429-
$this->artisan("schema:generate-rules", [
429+
$this->artisan('schema:generate-rules', [
430430
'table' => $this->tableName,
431431
])->assertSuccessful();
432432

0 commit comments

Comments
 (0)