1212namespace CodeIgniter \Database ;
1313
1414use CodeIgniter \Config \BaseConfig ;
15+ use Config \Database as DbConfig ;
1516use InvalidArgumentException ;
1617
1718/**
@@ -55,13 +56,14 @@ public static function connect($group = null, bool $getShared = true)
5556 $ group = 'custom- ' . md5 (json_encode ($ config ));
5657 }
5758
58- $ config ??= config ('Database ' );
59+ /** @var DbConfig $dbConfig */
60+ $ dbConfig = config ('Database ' );
5961
6062 if (empty ($ group )) {
61- $ group = ENVIRONMENT === 'testing ' ? 'tests ' : $ config ->defaultGroup ;
63+ $ group = ENVIRONMENT === 'testing ' ? 'tests ' : $ dbConfig ->defaultGroup ;
6264 }
6365
64- if (is_string ($ group ) && ! isset ($ config ->{$ group }) && strpos ($ group , 'custom- ' ) !== 0 ) {
66+ if (is_string ($ group ) && ! isset ($ dbConfig ->{$ group }) && strpos ($ group , 'custom- ' ) !== 0 ) {
6567 throw new InvalidArgumentException ($ group . ' is not a valid database connection group. ' );
6668 }
6769
@@ -71,8 +73,12 @@ public static function connect($group = null, bool $getShared = true)
7173
7274 static ::ensureFactory ();
7375
74- if (isset ($ config ->{$ group })) {
75- $ config = $ config ->{$ group };
76+ if (isset ($ dbConfig ->{$ group })) {
77+ $ config = $ dbConfig ->{$ group };
78+ }
79+
80+ if (! isset ($ config )) {
81+ throw new InvalidArgumentException ('There is no valid database config. ' );
7682 }
7783
7884 $ connection = static ::$ factory ->load ($ config , $ group );
0 commit comments