protected function refreshDatabaseSettings()
    {
        /** @var Database $database */
        $database = $this->getDatabaseInfo();
        $settings = file_get_contents($this->settingLocalFile);

        // Replace database properties based on database info.
        foreach ($database->asArray() as $property => $value) {
            $settings = $this->replaceDatabaseProperty(
                $property,
                $value,
                $settings
            );
        }

        // Replace the namespace property based on the database protocol.
        $namespace_base = addslashes('Drupal\\\\Core\\\\Database\\\\Driver\\\\');
        $settings = $this->replaceDatabaseProperty(
            'namespace',
            "{$namespace_base}{$database->getProtocol()}",
            $settings
        );

        // Check if file contents whats updated.
        $status = file_put_contents($this->settingLocalFile, $settings);

        if (false === $status) {
            throw new \Exception(
                sprintf('Unable to refresh database settings in (%s).', $this->settingLocalFile)
            );

            return false;
        }

        return true;
    }