Conditions | 10 |
Paths | 1 |
Total Lines | 48 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
11 | public static function create(string $tableName, ?\Closure $tableStructure = null, |
||
12 | ?array $references = null, bool $useTimestamps = false, bool $useSorting = false): void |
||
13 | { |
||
14 | Schema::create($tableName, function (Blueprint $table) use ($tableStructure, $references, $useTimestamps, $useSorting) { |
||
15 | $table->uuid('uuid'); |
||
16 | $table->primary('uuid'); |
||
17 | |||
18 | if ($tableStructure !== null) |
||
19 | { |
||
20 | $tableStructure($table); |
||
21 | } |
||
22 | |||
23 | if ($references !== null) |
||
24 | { |
||
25 | foreach ($references as $referenceKey => $reference) |
||
26 | { |
||
27 | $referenceSettings = []; |
||
28 | |||
29 | if (! is_numeric($referenceKey) && is_array($reference)) |
||
30 | { |
||
31 | $referenceSettings = $reference; |
||
32 | $reference = $referenceKey; |
||
33 | } |
||
34 | |||
35 | $columnName = sprintf('%sUuid', Str::camel($reference)); |
||
36 | $onUpdate = $referenceSettings['onUpdate'] ?? 'cascade'; |
||
37 | $onDelete = $referenceSettings['onDelete'] ?? 'cascade'; |
||
38 | |||
39 | $column = $table->uuid($columnName); |
||
40 | |||
41 | if ($onUpdate === 'set null' || $onDelete === 'set null') |
||
42 | { |
||
43 | $column->nullable(); |
||
44 | } |
||
45 | |||
46 | $table->foreign($columnName)->references('uuid')->on($reference)->onUpdate($onUpdate)->onDelete($onDelete); |
||
47 | } |
||
48 | } |
||
49 | |||
50 | if ($useSorting) |
||
51 | { |
||
52 | $table->unsignedMediumInteger('sortOrder')->default(0); |
||
53 | } |
||
54 | |||
55 | if ($useTimestamps) |
||
56 | { |
||
57 | $table->timestamp('createdAt')->nullable(); |
||
58 | $table->timestamp('updatedAt')->nullable(); |
||
59 | } |
||
88 |