Skip to content

Commit fa68681

Browse files
committed
Change priority order of migration's db group
1 parent 70aa8c3 commit fa68681

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

phpstan-baseline.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,11 +1146,6 @@
11461146
'count' => 1,
11471147
'path' => __DIR__ . '/system/Database/Migration.php',
11481148
];
1149-
$ignoreErrors[] = [
1150-
'message' => '#^Property CodeIgniter\\\\Database\\\\Migration\\:\\:\\$DBGroup \\(string\\) on left side of \\?\\? is not nullable\\.$#',
1151-
'count' => 1,
1152-
'path' => __DIR__ . '/system/Database/Migration.php',
1153-
];
11541149
$ignoreErrors[] = [
11551150
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
11561151
'count' => 8,

system/Database/Migration.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ abstract class Migration
2121
/**
2222
* The name of the database group to use.
2323
*
24-
* @var string
24+
* @var string|null
2525
*/
2626
protected $DBGroup;
2727

@@ -39,12 +39,15 @@ abstract class Migration
3939
*/
4040
protected $forge;
4141

42-
/**
43-
* Constructor.
44-
*/
4542
public function __construct(?Forge $forge = null)
4643
{
47-
$this->forge = $forge ?? Database::forge($this->DBGroup ?? config(Database::class)->defaultGroup);
44+
if (isset($this->DBGroup)) {
45+
$this->forge = Database::forge($this->DBGroup);
46+
} elseif ($forge !== null) {
47+
$this->forge = $forge;
48+
} else {
49+
$this->forge = Database::forge(config(Database::class)->defaultGroup);
50+
}
4851

4952
$this->db = $this->forge->getConnection();
5053
}

0 commit comments

Comments
 (0)