for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Ez\DbLinker\Driver;
use \Doctrine\DBAL\DriverManager;
use Ez\DbLinker\Driver\Connection\MasterSlavesConnection;
use SplObjectStorage;
trait MasterSlavesDriver
{
use WrapperDriver;
/**
* Attempts to create a connection with the database.
*
* @param array $params All connection parameters passed by the user.
* @param string|null $username The username to use when connecting.
* @param string|null $password The password to use when connecting.
* @param array $driverOptions The driver options to use when connecting.
* @return \Doctrine\DBAL\Driver\Connection The database connection.
*/
public function connect(Array $params, $username = null, $password = null, Array $driverOptions = []) {
$username
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.
$password
$driverOptions
$driverKey = array_key_exists('driverClass', $params['master']) ? 'driverClass' : 'driver';
$driverValue = $params['master'][$driverKey];
$master = function () use ($params) {
return DriverManager::getConnection($params['master']);
};
$slaves = new SplObjectStorage;
foreach ($params['slaves'] as $slaveParams) {
$slaveParams[$driverKey] = $driverValue;
$slaves->attach(function () use ($slaveParams) {
return DriverManager::getConnection($slaveParams);
}, $slaveParams['weight']);
}
return new MasterSlavesConnection($master, $slaves);
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.