I've outsourced the setup functions from my class to another file, I outsourced initDriver from the class PortalController to the class SeleniumUtility.Before:class PortalController extends Controller{           protected $driver = NULL;    const URL_GOOGLE = 'https://www.google.com';    const SELENIUM_SERVER_ADDRESS = 'http://localhost:4444/wd/hub';    const DRIVER_TIMEOUT = 5000;    /**    *   Initialize Driver    * As you can see I am using `initDriver` to initialize the protected property `$driver`.    */    public function initDriver()    {        if ($this->driver === NULL) {            $this->driver = RemoteWebDriver::create(self::SELENIUM_SERVER_ADDRESS, DesiredCapabilities::firefox(), self::DRIVER_TIMEOUT);        }    }    public function main()    {        $this->initDriver();        //start firefox and open google        $this->driver->get(self::URL_GOOGLE);    }...}After:PortalControlleruse App\Http\Utility\SeleniumUtility As Selenium;class PortalController extends Controller{           protected $driver = NULL;    const URL_GOOGLE = 'https://www.google.com';    public function main()    {        if ($this->driver === NULL) {            $this->driver = Selenium::initDriver(array($this, driver));        }        //start firefox and open google        $this->driver->get(self::URL_GOOGLE);    }...}SeleniumUtilityclass SeleniumUtility{    const SELENIUM_SERVER_ADDRESS = 'http://localhost:4444/wd/hub';    const DRIVER_TIMEOUT = 5000;    /**    *   Initialize Driver    *   @return RemoteWebDriver    */    public static function initDriver($thisObj)    {            return RemoteWebDriver::create(self::SELENIUM_SERVER_ADDRESS, DesiredCapabilities::firefox(), self::DRIVER_TIMEOUT);    }...}But I am not sure if this is the right way, it feels dirty.I also now have to do the check if ($this->driver === NULL) { in PortalController, If i do the check in initDriver then I get:Call to a member function get() on null on the line where I try to open the browser with google $this->driver->get(self::URL_GOOGLE);I appreciate any feedback on how to improve this if it is possible.
Outsource function from class
php;object oriented;mvc