I have an inherited class that I quickly want to write for several tests. Unfortunately, we have a single call in the constructor, and currently there is not enough time to reorganize it.
function __construct(){
$this->_dbConnect = DbConnect::getInstance();
}
It is acceptable practice for this to have elegant legacy code:
function __construct(DbConnect $dbConnect = null){
$this->_dbConnect = isset($dbConnect) ? $dbConnect : DbConnect::getInstance();
}
source
share