Your example with DB is incomplete, so you have doubts. The key point here is where you will get the connection to the database. If you have them sewn into the class is wrong. If they are rendered to the cofig, this is better, and there is a logic for accessing the configuration and getting the parameters inside your Db class, but you need to think about the situation when you have several connections, then either send the connection ID using which the parameters from the config will be received. But this makes your class dependent on this config.
Db::connect('mainDb')->query($sql)->fetchAll();
And the third option is when you transfer the connection parameters to the constructor, but you need to think about how to forward this instance to all other modules so that you can reach the base. Do not use $ db as a global variable. You can of course create a certain $ application that will store all the components and transfer it to all modules. But I do not like this approach. Personally, I used statics for the top level, and it already has components in the form of instances. Like the way it is done in Yii2 through Piping
Yii::$app->db->query($sql)->fetchAll();