Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ language: php
sudo: false

php:
- 5.5
- 5.6
- 7.0
- 7.1


before_script:
- composer install --dev
- composer install

script:
- mkdir -p build/logs
Expand Down
13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@
"email": "joe.green0991@gmail.com"
}
],
"scripts" : {
"test": "./vendor/bin/phpunit"
},
"require": {
"php": ">=5.4.0",
"psr/log": "~1.0"
},
"require-dev": {
"mockery/mockery": "*",
"satooshi/php-coveralls": "dev-master",
"phpunit/phpunit": "*"
},
"autoload": {
"psr-4": {
"Database\\": "src"
}
},
"require-dev": {
"mockery/mockery": "^0.9.9",
"satooshi/php-coveralls": "^1.0",
"phpunit/phpunit": "^6.1"
}
}
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="true"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
Expand Down
26 changes: 11 additions & 15 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@ protected function run($query, $bindings, $useReadPdo = false)
*/
private function execute($query, $bindings, $useReadPdo)
{
if ($this->pretending()) return new \PDOStatement();
if ($this->pretending()) {
return new \PDOStatement();
}

$pdo = $useReadPdo ? $this->getReadPdo() : $this->getPdo();

Expand All @@ -354,9 +356,7 @@ private function execute($query, $bindings, $useReadPdo)
// If an exception occurs when attempting to run a query, we'll call the exception handler
// if there is one, or throw the exception if not
catch (\Exception $e) {

if($this->exceptionHandler)
{
if ($this->exceptionHandler) {
$this->exceptionHandler->handle($query, $this->prepareBindings($bindings), $e);
}

Expand Down Expand Up @@ -499,13 +499,9 @@ public function connect()
public function reconnect()
{
if (is_callable($this->reconnector)) {

try
{
try {
return call_user_func($this->reconnector, $this);
}
catch(\PDOException $e)
{
} catch (\PDOException $e) {
$this->exceptionHandler->handle("Connection attempt", array(), $e);
}
}
Expand Down Expand Up @@ -535,7 +531,9 @@ protected function reconnectIfMissingConnection()
*/
protected function logQuery($query, $bindings, $start = null)
{
if (!$this->loggingQueries || !$this->logger) return;
if (!$this->loggingQueries || !$this->logger) {
return;
}

$time = $start ? round((microtime(true) - $start) * 1000, 2) : null;

Expand All @@ -562,8 +560,7 @@ public function getPdo()
*/
public function getReadPdo()
{
if (!$this->readPdo || $this->pdo->inTransaction())
{
if (!$this->readPdo || $this->pdo->inTransaction()) {
return $this->getPdo();
}

Expand Down Expand Up @@ -684,8 +681,7 @@ public function enableQueryLog()
{
$this->loggingQueries = true;

if(!$this->logger)
{
if (!$this->logger) {
$this->logger = new QueryLogger();
}

Expand Down
1 change: 0 additions & 1 deletion src/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,4 @@ public function inTransaction();
* @return array
*/
public function pretend(Closure $callback);

}
15 changes: 10 additions & 5 deletions src/ConnectionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ public function __construct(array $connections = array(), ConnectionFactoryInter
*/
public function connection($name = null)
{
if (is_null($name)) $name = $this->getDefaultConnection();
if (is_null($name)) {
$name = $this->getDefaultConnection();
}

if (!isset($this->connectionCache[$name]))
{
if (!isset($this->connectionCache[$name])) {
$this->connectionCache[$name] = $this->newConnection($name);
}

Expand All @@ -73,7 +74,9 @@ public function connection($name = null)
*/
public function newConnection($name = null)
{
if (is_null($name)) $name = $this->getDefaultConnection();
if (is_null($name)) {
$name = $this->getDefaultConnection();
}

return $this->connectionFactory->make($this->connectionConfig($name));
}
Expand All @@ -86,7 +89,9 @@ public function newConnection($name = null)
*/
public function connectionConfig($name = null)
{
if (is_null($name)) $name = $this->getDefaultConnection();
if (is_null($name)) {
$name = $this->getDefaultConnection();
}

return $this->value($this->connections[$name]);
}
Expand Down
1 change: 0 additions & 1 deletion src/ConnectionResolverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ public function getDefaultConnection();
* @return void
*/
public function setDefaultConnection($name);

}
6 changes: 2 additions & 4 deletions src/Connectors/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ protected function createSingleConnection(array $config, $lazy)
->setTablePrefix(isset($config['prefix']) ? $config['prefix'] : '')
->setLogger($this->logger);

if(!$lazy)
{
if (!$lazy) {
$connection->setPdo($this->createConnector($config['driver'])->connect($config));
}

Expand All @@ -141,8 +140,7 @@ protected function createReadWriteConnection(array $config, $lazy)
{
$connection = $this->createSingleConnection($this->getWriteConfig($config), $lazy);

if(!$lazy)
{
if (!$lazy) {
$connection->setReadPdo($this->createReadPdo($config));
}

Expand Down
8 changes: 2 additions & 6 deletions src/Connectors/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,11 @@ public function createConnection($dsn, array $config, array $options)

$password = isset($config['password']) ? $config['password'] : null;

try
{
try {
return new PDO($dsn, $username, $password, $options);
}catch (\PDOException $e)
{
} catch (\PDOException $e) {
throw new ConnectionException("Connection to '$dsn' failed: " . $e->getMessage(), $e);
}

}

/**
Expand All @@ -76,5 +73,4 @@ public function setDefaultOptions(array $options)
{
$this->options = $options;
}

}
1 change: 0 additions & 1 deletion src/Connectors/ConnectorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ interface ConnectorInterface
* @return \PDO
*/
public function connect(array $config);

}
1 change: 0 additions & 1 deletion src/Connectors/MySqlConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,4 @@ protected function getHostDsn(array $config)

return $dsn;
}

}
1 change: 0 additions & 1 deletion src/Connectors/PostgresConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,4 @@ protected function getDsn(array $config)

return $dsn;
}

}
1 change: 0 additions & 1 deletion src/Connectors/SQLiteConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,4 @@ public function connect(array $config)

return $this->createConnection("sqlite:{$path}", $config, $options);
}

}
1 change: 0 additions & 1 deletion src/Connectors/SqlServerConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,4 @@ protected function getAvailableDrivers()
{
return PDO::getAvailableDrivers();
}

}
7 changes: 3 additions & 4 deletions src/Exception/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public function handle($query = '', array $bindings = array(), \Exception $previ
{
$parameters = $this->parameters;

if($query){
if ($query) {
$sql = $this->replaceArray('\?', $bindings, $query);

if($this->maxQueryLength && strlen($sql) > $this->maxQueryLength){
if ($this->maxQueryLength && strlen($sql) > $this->maxQueryLength) {
$sql = substr($sql, 0, $this->maxQueryLength);
}

Expand All @@ -57,8 +57,7 @@ private function formatArrayParameters(array $parameters)
{
$parameters = $this->flattenArray($parameters);

foreach($parameters as $name => $value)
{
foreach ($parameters as $name => $value) {
$parameters[$name] = $name . ': ' . $value;
}

Expand Down
Loading