Automated coding style fixes using phpcbf

parent ba4c9a25
......@@ -17,13 +17,13 @@
* <http://www.doctrine-project.org>.
*/
use Symfony\Component\Console\Helper\HelperSet;
use Doctrine\DBAL\Tools\Console\ConsoleRunner;
use Symfony\Component\Console\Helper\HelperSet;
$files = array(__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../../autoload.php');
$files = [__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../../autoload.php'];
$loader = null;
$cwd = getcwd();
$directories = array($cwd, $cwd . DIRECTORY_SEPARATOR . 'config');
$directories = [$cwd, $cwd . DIRECTORY_SEPARATOR . 'config'];
$configFile = null;
foreach ($files as $file) {
......@@ -34,7 +34,7 @@ foreach ($files as $file) {
}
}
if ( ! $loader) {
if (! $loader) {
throw new RuntimeException('vendor/autoload.php could not be found. Did you run `php composer.phar install`?');
}
......@@ -46,22 +46,22 @@ foreach ($directories as $directory) {
}
}
if ( ! file_exists($configFile)) {
if (! file_exists($configFile)) {
ConsoleRunner::printCliConfigTemplate();
exit(1);
}
if ( ! is_readable($configFile)) {
if (! is_readable($configFile)) {
echo 'Configuration file [' . $configFile . '] does not have read permission.' . PHP_EOL;
exit(1);
}
$commands = array();
$commands = [];
$helperSet = require $configFile;
if ( ! $helperSet instanceof HelperSet) {
if (! $helperSet instanceof HelperSet) {
foreach ($GLOBALS as $helperSetCandidate) {
if ($helperSetCandidate instanceof HelperSet) {
$helperSet = $helperSetCandidate;
......
......@@ -2,33 +2,29 @@
namespace Doctrine\DBAL\Cache;
use ArrayIterator;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\FetchMode;
use InvalidArgumentException;
use IteratorAggregate;
use PDO;
use function array_merge;
use function array_values;
use function count;
use function reset;
class ArrayStatement implements \IteratorAggregate, ResultStatement
class ArrayStatement implements IteratorAggregate, ResultStatement
{
/**
* @var array
*/
/** @var array */
private $data;
/**
* @var int
*/
/** @var int */
private $columnCount = 0;
/**
* @var int
*/
/** @var int */
private $num = 0;
/**
* @var int
*/
/** @var int */
private $defaultFetchMode = FetchMode::MIXED;
/**
......@@ -37,9 +33,11 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement
public function __construct(array $data)
{
$this->data = $data;
if (count($data)) {
$this->columnCount = count($data[0]);
if (! count($data)) {
return;
}
$this->columnCount = count($data[0]);
}
/**
......@@ -47,7 +45,7 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement
*/
public function closeCursor()
{
unset ($this->data);
unset($this->data);
}
/**
......@@ -64,7 +62,7 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
{
if ($arg2 !== null || $arg3 !== null) {
throw new \InvalidArgumentException("Caching layer does not support 2nd/3rd argument to setFetchMode()");
throw new InvalidArgumentException('Caching layer does not support 2nd/3rd argument to setFetchMode()');
}
$this->defaultFetchMode = $fetchMode;
......@@ -79,13 +77,13 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement
{
$data = $this->fetchAll();
return new \ArrayIterator($data);
return new ArrayIterator($data);
}
/**
* {@inheritdoc}
*/
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
{
if (! isset($this->data[$this->num])) {
return false;
......@@ -110,7 +108,7 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement
return reset($row);
}
throw new \InvalidArgumentException('Invalid fetch-style given for fetching result.');
throw new InvalidArgumentException('Invalid fetch-style given for fetching result.');
}
/**
......
......@@ -2,18 +2,16 @@
namespace Doctrine\DBAL\Cache;
/**
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @since 2.2
*/
class CacheException extends \Doctrine\DBAL\DBALException
use Doctrine\DBAL\DBALException;
class CacheException extends DBALException
{
/**
* @return \Doctrine\DBAL\Cache\CacheException
*/
public static function noCacheKey()
{
return new self("No cache key was set.");
return new self('No cache key was set.');
}
/**
......@@ -21,6 +19,6 @@ class CacheException extends \Doctrine\DBAL\DBALException
*/
public static function noResultDriverConfigured()
{
return new self("Trying to cache a query but no result driver is configured.");
return new self('Trying to cache a query but no result driver is configured.');
}
}
......@@ -14,19 +14,13 @@ use function sha1;
*/
class QueryCacheProfile
{
/**
* @var Cache|null
*/
/** @var Cache|null */
private $resultCacheDriver;
/**
* @var int
*/
/** @var int */
private $lifetime = 0;
/**
* @var string|null
*/
/** @var string|null */
private $cacheKey;
/**
......@@ -98,7 +92,6 @@ class QueryCacheProfile
}
/**
*
* @return \Doctrine\DBAL\Cache\QueryCacheProfile
*/
public function setResultCacheDriver(Cache $cache)
......
......@@ -2,10 +2,14 @@
namespace Doctrine\DBAL\Cache;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Driver\ResultStatement;
use ArrayIterator;
use Doctrine\Common\Cache\Cache;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\FetchMode;
use InvalidArgumentException;
use IteratorAggregate;
use PDO;
use function array_merge;
use function array_values;
use function reset;
......@@ -23,32 +27,21 @@ use function reset;
* Also you have to realize that the cache will load the whole result into memory at once to ensure 2.
* This means that the memory usage for cached results might increase by using this feature.
*/
class ResultCacheStatement implements \IteratorAggregate, ResultStatement
class ResultCacheStatement implements IteratorAggregate, ResultStatement
{
/**
* @var \Doctrine\Common\Cache\Cache
*/
/** @var Cache */
private $resultCache;
/**
*
* @var string
*/
/** @var string */
private $cacheKey;
/**
* @var string
*/
/** @var string */
private $realKey;
/**
* @var int
*/
/** @var int */
private $lifetime;
/**
* @var \Doctrine\DBAL\Driver\Statement
*/
/** @var Statement */
private $statement;
/**
......@@ -58,19 +51,13 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement
*/
private $emptied = false;
/**
* @var array
*/
/** @var array */
private $data;
/**
* @var int
*/
/** @var int */
private $defaultFetchMode = FetchMode::MIXED;
/**
* @param \Doctrine\DBAL\Driver\Statement $stmt
* @param \Doctrine\Common\Cache\Cache $resultCache
* @param string $cacheKey
* @param string $realKey
* @param int $lifetime
......@@ -90,9 +77,12 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement
public function closeCursor()
{
$this->statement->closeCursor();
if ($this->emptied && $this->data !== null) {
if (! $this->emptied || $this->data === null) {
return;
}
$data = $this->resultCache->fetch($this->cacheKey);
if ( ! $data) {
if (! $data) {
$data = [];
}
$data[$this->realKey] = $this->data;
......@@ -100,7 +90,6 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement
$this->resultCache->save($this->cacheKey, $data, $this->lifetime);
unset($this->data);
}
}
/**
* {@inheritdoc}
......@@ -127,13 +116,13 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement
{
$data = $this->fetchAll();
return new \ArrayIterator($data);
return new ArrayIterator($data);
}
/**
* {@inheritdoc}
*/
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
{
if ($this->data === null) {
$this->data = [];
......@@ -162,7 +151,7 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement
return reset($row);
}
throw new \InvalidArgumentException('Invalid fetch-style given for caching result.');
throw new InvalidArgumentException('Invalid fetch-style given for caching result.');
}
$this->emptied = true;
......
......@@ -2,6 +2,8 @@
namespace Doctrine\DBAL;
use PDO;
/**
* Contains portable column case conversions.
*/
......@@ -12,14 +14,14 @@ final class ColumnCase
*
* @see \PDO::CASE_UPPER
*/
public const UPPER = \PDO::CASE_UPPER;
public const UPPER = PDO::CASE_UPPER;
/**
* Convert column names to lower case.
*
* @see \PDO::CASE_LOWER
*/
public const LOWER = \PDO::CASE_LOWER;
public const LOWER = PDO::CASE_LOWER;
/**
* This class cannot be instantiated.
......
......@@ -2,16 +2,12 @@
namespace Doctrine\DBAL;
use Doctrine\DBAL\Logging\SQLLogger;
use Doctrine\Common\Cache\Cache;
use Doctrine\DBAL\Logging\SQLLogger;
/**
* Configuration container for the Doctrine DBAL.
*
* @since 2.0
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
* @internal When adding a new configuration option just write a getter/setter
* pair and add the option to the _attributes array with a proper default value.
*/
......@@ -28,11 +24,9 @@ class Configuration
/**
* Sets the SQL logger to use. Defaults to NULL which means SQL logging is disabled.
*
* @param \Doctrine\DBAL\Logging\SQLLogger|null $logger
*
* @return void
*/
public function setSQLLogger(SQLLogger $logger = null)
public function setSQLLogger(?SQLLogger $logger = null)
{
$this->_attributes['sqlLogger'] = $logger;
}
......@@ -40,7 +34,7 @@ class Configuration
/**
* Gets the SQL logger that is used.
*
* @return \Doctrine\DBAL\Logging\SQLLogger|null
* @return SQLLogger|null
*/
public function getSQLLogger()
{
......@@ -50,7 +44,7 @@ class Configuration
/**
* Gets the cache driver implementation that is used for query result caching.
*
* @return \Doctrine\Common\Cache\Cache|null
* @return Cache|null
*/
public function getResultCacheImpl()
{
......@@ -60,8 +54,6 @@ class Configuration
/**
* Sets the cache driver implementation that is used for query result caching.
*
* @param \Doctrine\Common\Cache\Cache $cacheImpl
*
* @return void
*/
public function setResultCacheImpl(Cache $cacheImpl)
......@@ -102,21 +94,21 @@ class Configuration
* transactions. Otherwise, its SQL statements are grouped into transactions that are terminated by a call to either
* the method commit or the method rollback. By default, new connections are in auto-commit mode.
*
* @param bool $autoCommit True to enable auto-commit mode; false to disable it.
*
* @see getAutoCommit
*
* @param bool $autoCommit True to enable auto-commit mode; false to disable it.
*/
public function setAutoCommit($autoCommit)
{
$this->_attributes['autoCommit'] = (boolean) $autoCommit;
$this->_attributes['autoCommit'] = (bool) $autoCommit;
}
/**
* Returns the default auto-commit mode for connections.
*
* @return bool True if auto-commit mode is enabled by default for connections, false otherwise.
*
* @see setAutoCommit
*
* @return bool True if auto-commit mode is enabled by default for connections, false otherwise.
*/
public function getAutoCommit()
{
......
This diff is collapsed.
......@@ -4,8 +4,6 @@ namespace Doctrine\DBAL;
/**
* @link www.doctrine-project.org
* @since 2.0
* @author Jonathan H. Wage <jonwage@gmail.com
*/
class ConnectionException extends DBALException
{
......@@ -14,7 +12,7 @@ class ConnectionException extends DBALException
*/
public static function commitFailedRollbackOnly()
{
return new self("Transaction commit failed because the transaction has been marked for rollback only.");
return new self('Transaction commit failed because the transaction has been marked for rollback only.');
}
/**
......@@ -22,7 +20,7 @@ class ConnectionException extends DBALException
*/
public static function noActiveTransaction()
{
return new self("There is no active transaction.");
return new self('There is no active transaction.');
}
/**
......@@ -30,7 +28,7 @@ class ConnectionException extends DBALException
*/
public static function savepointsNotSupported()
{
return new self("Savepoints are not supported by this driver.");
return new self('Savepoints are not supported by this driver.');
}
/**
......@@ -38,6 +36,6 @@ class ConnectionException extends DBALException
*/
public static function mayNotAlterNestedTransactionWithSavepointsInTransaction()
{
return new self("May not alter the nested transaction with savepoints behavior while a transaction is open.");
return new self('May not alter the nested transaction with savepoints behavior while a transaction is open.');
}
}
......@@ -2,13 +2,14 @@
namespace Doctrine\DBAL\Connections;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Configuration;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events;
use InvalidArgumentException;
use function array_rand;
use function count;
use function func_get_args;
......@@ -63,9 +64,6 @@ use function func_get_args;
* ));
*
* You can also pass 'driverOptions' and any other documented option to each of this drivers to pass additional information.
*
* @author Lars Strojny <lstrojny@php.net>
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class MasterSlaveConnection extends Connection
{
......@@ -88,19 +86,16 @@ class MasterSlaveConnection extends Connection
* Creates Master Slave Connection.
*
* @param array $params
* @param \Doctrine\DBAL\Driver $driver
* @param \Doctrine\DBAL\Configuration|null $config
* @param \Doctrine\Common\EventManager|null $eventManager
*
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*/
public function __construct(array $params, Driver $driver, Configuration $config = null, EventManager $eventManager = null)
public function __construct(array $params, Driver $driver, ?Configuration $config = null, ?EventManager $eventManager = null)
{
if (! isset($params['slaves'], $params['master'])) {
throw new \InvalidArgumentException('master or slaves configuration missing');
throw new InvalidArgumentException('master or slaves configuration missing');
}
if (count($params['slaves']) == 0) {
throw new \InvalidArgumentException('You have to configure at least one slaves.');
if (count($params['slaves']) === 0) {
throw new InvalidArgumentException('You have to configure at least one slaves.');
}
$params['master']['driver'] = $params['driver'];
......@@ -132,13 +127,13 @@ class MasterSlaveConnection extends Connection
$connectionName = $connectionName ?: 'slave';
if ($connectionName !== 'slave' && $connectionName !== 'master') {
throw new \InvalidArgumentException("Invalid option to connect(), only master or slave allowed.");
throw new InvalidArgumentException('Invalid option to connect(), only master or slave allowed.');
}
// If we have a connection open, and this is not an explicit connection
// change request, then abort right here, because we are already done.
// This prevents writes to the slave in case of "keepSlave" option enabled.
if (isset($this->_conn) && $this->_conn && !$requestedConnectionChange) {
if (isset($this->_conn) && $this->_conn && ! $requestedConnectionChange) {
return false;
}
......@@ -163,7 +158,7 @@ class MasterSlaveConnection extends Connection
$this->connections['master'] = $this->_conn = $this->connectTo($connectionName);
// Set slave connection to master to avoid invalid reads
if ( ! $this->keepSlave) {
if (! $this->keepSlave) {
$this->connections['slave'] = $this->connections['master'];
}
} else {
......@@ -213,7 +208,7 @@ class MasterSlaveConnection extends Connection
$config = $params['slaves'][array_rand($params['slaves'])];
if ( ! isset($config['charset']) && isset($params['master']['charset'])) {
if (! isset($config['charset']) && isset($params['master']['charset'])) {
$config['charset'] = $params['master']['charset'];
}
......
This diff is collapsed.
......@@ -2,11 +2,12 @@
namespace Doctrine\DBAL;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
/**
* Driver interface.
* Interface that all DBAL drivers must implement.
*
* @since 2.0
*/
interface Driver
{
......@@ -26,7 +27,7 @@ interface Driver
* Gets the DatabasePlatform instance that provides all the metadata about
* the platform this driver connects to.
*
* @return \Doctrine\DBAL\Platforms\AbstractPlatform The database platform.
* @return AbstractPlatform The database platform.
*/
public function getDatabasePlatform();
......@@ -34,9 +35,7 @@ interface Driver
* Gets the SchemaManager that can be used to inspect and change the underlying
* database schema of the platform this driver connects to.
*
* @param \Doctrine\DBAL\Connection $conn
*
* @return \Doctrine\DBAL\Schema\AbstractSchemaManager
* @return AbstractSchemaManager
*/
public function getSchemaManager(Connection $conn);
......@@ -50,8 +49,6 @@ interface Driver
/**
* Gets the name of the database connected to for this driver.
*
* @param \Doctrine\DBAL\Connection $conn
*
* @return string The name of the database.
*/
public function getDatabase(Connection $conn);
......
......@@ -2,6 +2,7 @@
namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Schema\DB2SchemaManager;
......@@ -9,16 +10,14 @@ use Doctrine\DBAL\Schema\DB2SchemaManager;
/**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for IBM DB2 based drivers.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
abstract class AbstractDB2Driver implements Driver
{
/**
* {@inheritdoc}
*/
public function getDatabase(\Doctrine\DBAL\Connection $conn)
public function getDatabase(Connection $conn)
{
$params = $conn->getParams();
......@@ -36,7 +35,7 @@ abstract class AbstractDB2Driver implements Driver
/**
* {@inheritdoc}
*/
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
public function getSchemaManager(Connection $conn)
{
return new DB2SchemaManager($conn);
}
......
......@@ -2,14 +2,14 @@
namespace Doctrine\DBAL\Driver;
use Exception;
/**
* Abstract base implementation of the {@link DriverException} interface.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
abstract class AbstractDriverException extends \Exception implements DriverException
abstract class AbstractDriverException extends Exception implements DriverException
{
/**
* The driver specific error code.
......@@ -26,8 +26,6 @@ abstract class AbstractDriverException extends \Exception implements DriverExcep
private $sqlState;
/**
* Constructor.
*
* @param string $message The driver error message.
* @param string|null $sqlState The SQLSTATE the driver is in at the time the error occurred, if any.
* @param int|string|null $errorCode The driver specific error code if any.
......
......@@ -2,6 +2,7 @@
namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Exception;
......@@ -18,9 +19,7 @@ use function version_compare;
/**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for MySQL based drivers.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver
{
......@@ -116,7 +115,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
*/
public function createDatabasePlatformForVersion($version)
{
$mariadb = false !== stripos($version, 'mariadb');
$mariadb = stripos($version, 'mariadb') !== false;
if ($mariadb && version_compare($this->getMariaDbMysqlVersionNumber($version), '10.2.7', '>=')) {
return new MariaDb1027Platform();
}
......@@ -139,11 +138,12 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
* returned by Oracle MySQL servers.
*
* @param string $versionString Version string returned by the driver, i.e. '5.7.10'
*
* @throws DBALException
*/
private function getOracleMysqlVersionNumber(string $versionString) : string
{
if ( ! preg_match(
if (! preg_match(
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/',
$versionString,
$versionParts
......@@ -157,7 +157,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
$minorVersion = $versionParts['minor'] ?? 0;
$patchVersion = $versionParts['patch'] ?? null;
if ('5' === $majorVersion && '7' === $minorVersion && null === $patchVersion) {
if ($majorVersion === '5' && $minorVersion === '7' && $patchVersion === null) {
$patchVersion = '9';
}
......@@ -169,11 +169,12 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
* that starts with the prefix '5.5.5-'
*
* @param string $versionString Version string as returned by mariadb server, i.e. '5.5.5-Mariadb-10.0.8-xenial'
*
* @throws DBALException
*/
private function getMariaDbMysqlVersionNumber(string $versionString) : string
{
if ( ! preg_match(
if (! preg_match(
'/^(?:5\.5\.5-)?(mariadb-)?(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)/i',
$versionString,
$versionParts
......@@ -190,7 +191,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
/**
* {@inheritdoc}
*/
public function getDatabase(\Doctrine\DBAL\Connection $conn)
public function getDatabase(Connection $conn)
{
$params = $conn->getParams();
......@@ -199,6 +200,7 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
/**
* {@inheritdoc}
*
* @return MySqlPlatform
*/
public function getDatabasePlatform()
......@@ -208,9 +210,10 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver,
/**
* {@inheritdoc}
*
* @return MySqlSchemaManager
*/
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
public function getSchemaManager(Connection $conn)
{
return new MySqlSchemaManager($conn);
}
......
......@@ -2,6 +2,7 @@
namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\AbstractOracleDriver\EasyConnectString;
use Doctrine\DBAL\Exception;
......@@ -11,9 +12,7 @@ use Doctrine\DBAL\Schema\OracleSchemaManager;
/**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Oracle based drivers.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver
{
......@@ -63,7 +62,7 @@ abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver
/**
* {@inheritdoc}
*/
public function getDatabase(\Doctrine\DBAL\Connection $conn)
public function getDatabase(Connection $conn)
{
$params = $conn->getParams();
......@@ -81,7 +80,7 @@ abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver
/**
* {@inheritdoc}
*/
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
public function getSchemaManager(Connection $conn)
{
return new OracleSchemaManager($conn);
}
......
......@@ -2,6 +2,7 @@
namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Exception;
......@@ -19,9 +20,7 @@ use function version_compare;
/**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for PostgreSQL based drivers.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver
{
......@@ -87,7 +86,7 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri
*/
public function createDatabasePlatformForVersion($version)
{
if ( ! preg_match('/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/', $version, $versionParts)) {
if (! preg_match('/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/', $version, $versionParts)) {
throw DBALException::invalidPlatformVersionSpecified(
$version,
'<major_version>.<minor_version>.<patch_version>'
......@@ -99,7 +98,7 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri
$patchVersion = $versionParts['patch'] ?? 0;
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
switch(true) {
switch (true) {
case version_compare($version, '10.0', '>='):
return new PostgreSQL100Platform();
case version_compare($version, '9.4', '>='):
......@@ -116,7 +115,7 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri
/**
* {@inheritdoc}
*/
public function getDatabase(\Doctrine\DBAL\Connection $conn)
public function getDatabase(Connection $conn)
{
$params = $conn->getParams();
......@@ -134,7 +133,7 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri
/**
* {@inheritdoc}
*/
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
public function getSchemaManager(Connection $conn)
{
return new PostgreSqlSchemaManager($conn);
}
......
......@@ -2,6 +2,7 @@
namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Exception;
......@@ -17,9 +18,7 @@ use function version_compare;
/**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for SAP Sybase SQL Anywhere based drivers.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver
{
......@@ -73,7 +72,7 @@ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDr
*/
public function createDatabasePlatformForVersion($version)
{
if ( ! preg_match(
if (! preg_match(
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+)(?:\.(?P<build>\d+))?)?)?/',
$version,
$versionParts
......@@ -90,7 +89,7 @@ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDr
$buildVersion = $versionParts['build'] ?? 0;
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion . '.' . $buildVersion;
switch(true) {
switch (true) {
case version_compare($version, '16', '>='):
return new SQLAnywhere16Platform();
case version_compare($version, '12', '>='):
......@@ -105,7 +104,7 @@ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDr
/**
* {@inheritdoc}
*/
public function getDatabase(\Doctrine\DBAL\Connection $conn)
public function getDatabase(Connection $conn)
{
$params = $conn->getParams();
......@@ -123,7 +122,7 @@ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDr
/**
* {@inheritdoc}
*/
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
public function getSchemaManager(Connection $conn)
{
return new SQLAnywhereSchemaManager($conn);
}
......
......@@ -2,6 +2,7 @@
namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Platforms\SQLServer2005Platform;
......@@ -16,9 +17,7 @@ use function version_compare;
/**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Microsoft SQL Server based drivers.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDriver
{
......@@ -27,7 +26,7 @@ abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDr
*/
public function createDatabasePlatformForVersion($version)
{
if ( ! preg_match(
if (! preg_match(
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+)(?:\.(?P<build>\d+))?)?)?/',
$version,
$versionParts
......@@ -44,7 +43,7 @@ abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDr
$buildVersion = $versionParts['build'] ?? 0;
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion . '.' . $buildVersion;
switch(true) {
switch (true) {
case version_compare($version, '11.00.2100', '>='):
return new SQLServer2012Platform();
case version_compare($version, '10.00.1600', '>='):
......@@ -59,7 +58,7 @@ abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDr
/**
* {@inheritdoc}
*/
public function getDatabase(\Doctrine\DBAL\Connection $conn)
public function getDatabase(Connection $conn)
{
$params = $conn->getParams();
......@@ -78,7 +77,7 @@ abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDr
* {@inheritdoc}
*/
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
public function getSchemaManager(Connection $conn)
{
return new SQLServerSchemaManager($conn);
}
......
......@@ -2,6 +2,7 @@
namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\SqlitePlatform;
......@@ -11,9 +12,7 @@ use function strpos;
/**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for SQLite based drivers.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
abstract class AbstractSQLiteDriver implements Driver, ExceptionConverterDriver
{
......@@ -76,7 +75,7 @@ abstract class AbstractSQLiteDriver implements Driver, ExceptionConverterDriver
/**
* {@inheritdoc}
*/
public function getDatabase(\Doctrine\DBAL\Connection $conn)
public function getDatabase(Connection $conn)
{
$params = $conn->getParams();
......@@ -94,7 +93,7 @@ abstract class AbstractSQLiteDriver implements Driver, ExceptionConverterDriver
/**
* {@inheritdoc}
*/
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
public function getSchemaManager(Connection $conn)
{
return new SqliteSchemaManager($conn);
}
......
......@@ -9,8 +9,6 @@ use Doctrine\DBAL\ParameterType;
* Driver connections must implement this interface.
*
* This resembles (a subset of) the PDO interface.
*
* @since 2.0
*/
interface Connection
{
......@@ -26,7 +24,7 @@ interface Connection
/**
* Executes an SQL statement, returning a result set as a Statement object.
*
* @return \Doctrine\DBAL\Driver\Statement
* @return Statement
*/
public function query();
......
......@@ -2,17 +2,17 @@
namespace Doctrine\DBAL\Driver;
use Throwable;
/**
* Contract for a driver exception.
*
* Driver exceptions provide the SQLSTATE of the driver
* and the driver specific error code at the time the error occurred.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
interface DriverException extends \Throwable
interface DriverException extends Throwable
{
/**
* Returns the driver specific error code if available.
......
......@@ -2,12 +2,10 @@
namespace Doctrine\DBAL\Driver\DrizzlePDOMySql;
use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\ParameterType;
/**
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
*/
class Connection extends \Doctrine\DBAL\Driver\PDOConnection
class Connection extends PDOConnection
{
/**
* {@inheritdoc}
......
......@@ -7,8 +7,6 @@ use Doctrine\DBAL\Schema\DrizzleSchemaManager;
/**
* Drizzle driver using PDO MySql.
*
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
*/
class Driver extends \Doctrine\DBAL\Driver\PDOMySql\Driver
{
......@@ -17,14 +15,12 @@ class Driver extends \Doctrine\DBAL\Driver\PDOMySql\Driver
*/
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
{
$conn = new Connection(
return new Connection(
$this->constructPdoDsn($params),
$username,
$password,
$driverOptions
);
return $conn;
}
/**
......
......@@ -5,10 +5,7 @@ namespace Doctrine\DBAL\Driver;
/**
* Contract for a driver that is capable of converting DBAL driver exceptions into standardized DBAL driver exceptions.
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
interface ExceptionConverterDriver
{
......@@ -19,7 +16,7 @@ interface ExceptionConverterDriver
* it into a unified {@link Doctrine\DBAL\Exception\DriverException} subclass.
*
* @param string $message The DBAL exception message to use.
* @param \Doctrine\DBAL\Driver\DriverException $exception The DBAL driver exception to convert.
* @param DriverException $exception The DBAL driver exception to convert.
*
* @return \Doctrine\DBAL\Exception\DriverException An instance of one of the DriverException subclasses.
*/
......
......@@ -26,9 +26,7 @@ use function func_get_args;
class DB2Connection implements Connection, ServerInfoAwareConnection
{
/**
* @var resource
*/
/** @var resource */
private $_conn = null;
/**
......@@ -37,18 +35,18 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
* @param string $password
* @param array $driverOptions
*
* @throws \Doctrine\DBAL\Driver\IBMDB2\DB2Exception
* @throws DB2Exception
*/
public function __construct(array $params, $username, $password, $driverOptions = [])
{
$isPersistent = (isset($params['persistent']) && $params['persistent'] == true);
$isPersistent = (isset($params['persistent']) && $params['persistent'] === true);
if ($isPersistent) {
$this->_conn = db2_pconnect($params['dbname'], $username, $password, $driverOptions);
} else {
$this->_conn = db2_connect($params['dbname'], $username, $password, $driverOptions);
}
if ( ! $this->_conn) {
if (! $this->_conn) {
throw new DB2Exception(db2_conn_errormsg());
}
}
......@@ -78,7 +76,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
public function prepare($sql)
{
$stmt = @db2_prepare($this->_conn, $sql);
if ( ! $stmt) {
if (! $stmt) {
throw new DB2Exception(db2_stmt_errormsg());
}
......@@ -109,7 +107,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
return $input;
}
return "'".$input."'";
return "'" . $input . "'";
}
/**
......@@ -119,7 +117,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
{
$stmt = @db2_exec($this->_conn, $statement);
if (false === $stmt) {
if ($stmt === false) {
throw new DB2Exception(db2_stmt_errormsg());
}
......@@ -147,7 +145,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
*/
public function commit()
{
if (!db2_commit($this->_conn)) {
if (! db2_commit($this->_conn)) {
throw new DB2Exception(db2_conn_errormsg($this->_conn));
}
db2_autocommit($this->_conn, DB2_AUTOCOMMIT_ON);
......@@ -158,7 +156,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
*/
public function rollBack()
{
if (!db2_rollback($this->_conn)) {
if (! db2_rollback($this->_conn)) {
throw new DB2Exception(db2_conn_errormsg($this->_conn));
}
db2_autocommit($this->_conn, DB2_AUTOCOMMIT_ON);
......
......@@ -6,9 +6,6 @@ use Doctrine\DBAL\Driver\AbstractDB2Driver;
/**
* IBM DB2 Driver.
*
* @since 2.0
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class DB2Driver extends AbstractDB2Driver
{
......@@ -17,18 +14,18 @@ class DB2Driver extends AbstractDB2Driver
*/
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
{
if ( ! isset($params['protocol'])) {
if (! isset($params['protocol'])) {
$params['protocol'] = 'TCPIP';
}
if ($params['host'] !== 'localhost' && $params['host'] != '127.0.0.1') {
if ($params['host'] !== 'localhost' && $params['host'] !== '127.0.0.1') {
// if the host isn't localhost, use extended connection params
$params['dbname'] = 'DRIVER={IBM DB2 ODBC DRIVER}' .
';DATABASE=' . $params['dbname'] .
';HOSTNAME=' . $params['host'] .
';PROTOCOL=' . $params['protocol'] .
';UID=' . $username .
';PWD=' . $password .';';
';PWD=' . $password . ';';
if (isset($params['port'])) {
$params['dbname'] .= 'PORT=' . $params['port'];
}
......
......@@ -2,6 +2,8 @@
namespace Doctrine\DBAL\Driver\IBMDB2;
class DB2Exception extends \Exception
use Exception;
class DB2Exception extends Exception
{
}
......@@ -6,6 +6,13 @@ use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use PDO;
use ReflectionClass;
use ReflectionObject;
use ReflectionProperty;
use stdClass;
use const CASE_LOWER;
use const DB2_CHAR;
use const DB2_LONG;
use const DB2_PARAM_IN;
......@@ -30,31 +37,21 @@ use function ksort;
use function sprintf;
use function strtolower;
class DB2Statement implements \IteratorAggregate, Statement
class DB2Statement implements IteratorAggregate, Statement
{
/**
* @var resource
*/
/** @var resource */
private $_stmt;
/**
* @var array
*/
/** @var array */
private $_bindParam = [];
/**
* @var string Name of the default class to instantiate when fetching class instances.
*/
/** @var string Name of the default class to instantiate when fetching class instances. */
private $defaultFetchClass = '\stdClass';
/**
* @var mixed[] Constructor arguments for the default class to instantiate when fetching class instances.
*/
/** @var mixed[] Constructor arguments for the default class to instantiate when fetching class instances. */
private $defaultFetchClassCtorArgs = [];
/**
* @var int
*/
/** @var int */
private $_defaultFetchMode = FetchMode::MIXED;
/**
......@@ -103,7 +100,7 @@ class DB2Statement implements \IteratorAggregate, Statement
$type = DB2_CHAR;
}
if (!db2_bind_param($this->_stmt, $column, "variable", DB2_PARAM_IN, $type)) {
if (! db2_bind_param($this->_stmt, $column, 'variable', DB2_PARAM_IN, $type)) {
throw new DB2Exception(db2_stmt_errormsg());
}
......@@ -115,13 +112,13 @@ class DB2Statement implements \IteratorAggregate, Statement
*/
public function closeCursor()
{
if ( ! $this->_stmt) {
if (! $this->_stmt) {
return false;
}
$this->_bindParam = [];
if (!db2_free_result($this->_stmt)) {
if (! db2_free_result($this->_stmt)) {
return false;
}
......@@ -135,7 +132,7 @@ class DB2Statement implements \IteratorAggregate, Statement
*/
public function columnCount()
{
if ( ! $this->_stmt) {
if (! $this->_stmt) {
return false;
}
......@@ -166,7 +163,7 @@ class DB2Statement implements \IteratorAggregate, Statement
*/
public function execute($params = null)
{
if ( ! $this->_stmt) {
if (! $this->_stmt) {
return false;
}
......@@ -214,11 +211,11 @@ class DB2Statement implements \IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
{
// do not try fetching from the statement if it's not expected to contain result
// in order to prevent exceptional situation
if (!$this->result) {
if (! $this->result) {
return false;
}
......@@ -245,7 +242,7 @@ class DB2Statement implements \IteratorAggregate, Statement
$result = db2_fetch_object($this->_stmt);
if ($result instanceof \stdClass) {
if ($result instanceof stdClass) {
$result = $this->castObject($result, $className, $ctorArgs);
}
......@@ -296,7 +293,7 @@ class DB2Statement implements \IteratorAggregate, Statement
{
$row = $this->fetch(FetchMode::NUMERIC);
if (false === $row) {
if ($row === false) {
return false;
}
......@@ -308,13 +305,13 @@ class DB2Statement implements \IteratorAggregate, Statement
*/
public function rowCount()
{
return (@db2_num_rows($this->_stmt)) ? : 0;
return @db2_num_rows($this->_stmt) ? : 0;
}
/**
* Casts a stdClass object to the given class name mapping its' properties.
*
* @param \stdClass $sourceObject Object to cast from.
* @param stdClass $sourceObject Object to cast from.
* @param string|object $destinationClass Name of the class or class instance to cast to.
* @param array $ctorArgs Arguments to use for constructing the destination class instance.
*
......@@ -322,23 +319,24 @@ class DB2Statement implements \IteratorAggregate, Statement
*
* @throws DB2Exception
*/
private function castObject(\stdClass $sourceObject, $destinationClass, array $ctorArgs = [])
private function castObject(stdClass $sourceObject, $destinationClass, array $ctorArgs = [])
{
if ( ! is_string($destinationClass)) {
if ( ! is_object($destinationClass)) {
if (! is_string($destinationClass)) {
if (! is_object($destinationClass)) {
throw new DB2Exception(sprintf(
'Destination class has to be of type string or object, %s given.', gettype($destinationClass)
'Destination class has to be of type string or object, %s given.',
gettype($destinationClass)
));
}
} else {
$destinationClass = new \ReflectionClass($destinationClass);
$destinationClass = new ReflectionClass($destinationClass);
$destinationClass = $destinationClass->newInstanceArgs($ctorArgs);
}
$sourceReflection = new \ReflectionObject($sourceObject);
$destinationClassReflection = new \ReflectionObject($destinationClass);
/** @var \ReflectionProperty[] $destinationProperties */
$destinationProperties = array_change_key_case($destinationClassReflection->getProperties(), \CASE_LOWER);
$sourceReflection = new ReflectionObject($sourceObject);
$destinationClassReflection = new ReflectionObject($destinationClass);
/** @var ReflectionProperty[] $destinationProperties */
$destinationProperties = array_change_key_case($destinationClassReflection->getProperties(), CASE_LOWER);
foreach ($sourceReflection->getProperties() as $sourceProperty) {
$sourceProperty->setAccessible(true);
......
......@@ -2,12 +2,9 @@
namespace Doctrine\DBAL\Driver\Mysqli;
use Doctrine\DBAL\Driver\AbstractMySQLDriver;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\AbstractMySQLDriver;
/**
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
*/
class Driver extends AbstractMySQLDriver
{
/**
......
......@@ -6,6 +6,13 @@ use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\PingableConnection;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\ParameterType;
use mysqli;
use const MYSQLI_INIT_COMMAND;
use const MYSQLI_OPT_CONNECT_TIMEOUT;
use const MYSQLI_OPT_LOCAL_INFILE;
use const MYSQLI_READ_DEFAULT_FILE;
use const MYSQLI_READ_DEFAULT_GROUP;
use const MYSQLI_SERVER_PUBLIC_KEY;
use function defined;
use function floor;
use function func_get_args;
......@@ -20,20 +27,14 @@ use function set_error_handler;
use function sprintf;
use function stripos;
/**
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
* @author Till Klampaeckel <till@php.net>
*/
class MysqliConnection implements Connection, PingableConnection, ServerInfoAwareConnection
{
/**
* Name of the option to set connection flags
*/
const OPTION_FLAGS = 'flags';
public const OPTION_FLAGS = 'flags';
/**
* @var \mysqli
*/
/** @var mysqli */
private $_conn;
/**
......@@ -42,14 +43,14 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
* @param string $password
* @param array $driverOptions
*
* @throws \Doctrine\DBAL\Driver\Mysqli\MysqliException
* @throws MysqliException
*/
public function __construct(array $params, $username, $password, array $driverOptions = [])
{
$port = $params['port'] ?? ini_get('mysqli.default_port');
// Fallback to default MySQL port if not given.
if ( ! $port) {
if (! $port) {
$port = 3306;
}
......@@ -63,18 +64,21 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
$this->setSecureConnection($params);
$this->setDriverOptions($driverOptions);
set_error_handler(function () {});
set_error_handler(static function () {
});
try {
if ( ! $this->_conn->real_connect($params['host'], $username, $password, $dbname, $port, $socket, $flags)) {
if (! $this->_conn->real_connect($params['host'], $username, $password, $dbname, $port, $socket, $flags)) {
throw new MysqliException($this->_conn->connect_error, $this->_conn->sqlstate ?? 'HY000', $this->_conn->connect_errno);
}
} finally {
restore_error_handler();
}
if (isset($params['charset'])) {
$this->_conn->set_charset($params['charset']);
if (! isset($params['charset'])) {
return;
}
$this->_conn->set_charset($params['charset']);
}
/**
......@@ -82,7 +86,7 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
*
* Could be used if part of your application is not using DBAL.
*
* @return \mysqli
* @return mysqli
*/
public function getWrappedResourceHandle()
{
......@@ -94,12 +98,13 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
*
* The server version detection includes a special case for MariaDB
* to support '5.5.5-' prefixed versions introduced in Maria 10+
*
* @link https://jira.mariadb.org/browse/MDEV-4088
*/
public function getServerVersion()
{
$serverInfos = $this->_conn->get_server_info();
if (false !== stripos($serverInfos, 'mariadb')) {
if (stripos($serverInfos, 'mariadb') !== false) {
return $serverInfos;
}
......@@ -144,7 +149,7 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
*/
public function quote($input, $type = ParameterType::STRING)
{
return "'". $this->_conn->escape_string($input) ."'";
return "'" . $this->_conn->escape_string($input) . "'";
}
/**
......@@ -152,7 +157,7 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
*/
public function exec($statement)
{
if (false === $this->_conn->query($statement)) {
if ($this->_conn->query($statement) === false) {
throw new MysqliException($this->_conn->error, $this->_conn->sqlstate, $this->_conn->errno);
}
......@@ -220,26 +225,25 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
private function setDriverOptions(array $driverOptions = [])
{
$supportedDriverOptions = [
\MYSQLI_OPT_CONNECT_TIMEOUT,
\MYSQLI_OPT_LOCAL_INFILE,
\MYSQLI_INIT_COMMAND,
\MYSQLI_READ_DEFAULT_FILE,
\MYSQLI_READ_DEFAULT_GROUP,
MYSQLI_OPT_CONNECT_TIMEOUT,
MYSQLI_OPT_LOCAL_INFILE,
MYSQLI_INIT_COMMAND,
MYSQLI_READ_DEFAULT_FILE,
MYSQLI_READ_DEFAULT_GROUP,
];
if (defined('MYSQLI_SERVER_PUBLIC_KEY')) {
$supportedDriverOptions[] = \MYSQLI_SERVER_PUBLIC_KEY;
$supportedDriverOptions[] = MYSQLI_SERVER_PUBLIC_KEY;
}
$exceptionMsg = "%s option '%s' with value '%s'";
foreach ($driverOptions as $option => $value) {
if ($option === static::OPTION_FLAGS) {
continue;
}
if (!in_array($option, $supportedDriverOptions, true)) {
if (! in_array($option, $supportedDriverOptions, true)) {
throw new MysqliException(
sprintf($exceptionMsg, 'Unsupported', $option, $value)
);
......@@ -274,6 +278,7 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar
* Establish a secure connection
*
* @param array $params
*
* @throws MysqliException
*/
private function setSecureConnection(array $params)
......
......@@ -6,9 +6,6 @@ use Doctrine\DBAL\Driver\AbstractDriverException;
/**
* Exception thrown in case the mysqli driver errors.
*
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
* @author Steve Müller <st.mueller@dzh-online.de>
*/
class MysqliException extends AbstractDriverException
{
......
......@@ -7,6 +7,11 @@ use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\Exception\InvalidArgumentException;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use mysqli;
use mysqli_stmt;
use PDO;
use stdClass;
use function array_combine;
use function array_fill;
use function count;
......@@ -16,14 +21,9 @@ use function get_resource_type;
use function is_resource;
use function str_repeat;
/**
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
*/
class MysqliStatement implements \IteratorAggregate, Statement
class MysqliStatement implements IteratorAggregate, Statement
{
/**
* @var array
*/
/** @var array */
protected static $_paramTypeMap = [
ParameterType::STRING => 's',
ParameterType::BINARY => 's',
......@@ -33,34 +33,22 @@ class MysqliStatement implements \IteratorAggregate, Statement
ParameterType::LARGE_OBJECT => 'b',
];
/**
* @var \mysqli
*/
/** @var mysqli */
protected $_conn;
/**
* @var \mysqli_stmt
*/
/** @var mysqli_stmt */
protected $_stmt;
/**
* @var null|boolean|array
*/
/** @var bool|array|null */
protected $_columnNames;
/**
* @var null|array
*/
/** @var array|null */
protected $_rowBindedValues;
/**
* @var array
*/
/** @var array */
protected $_bindedValues;
/**
* @var string
*/
/** @var string */
protected $types;
/**
......@@ -70,9 +58,7 @@ class MysqliStatement implements \IteratorAggregate, Statement
*/
protected $_values = [];
/**
* @var int
*/
/** @var int */
protected $_defaultFetchMode = FetchMode::MIXED;
/**
......@@ -83,39 +69,40 @@ class MysqliStatement implements \IteratorAggregate, Statement
private $result = false;
/**
* @param \mysqli $conn
* @param string $prepareString
*
* @throws \Doctrine\DBAL\Driver\Mysqli\MysqliException
* @throws MysqliException
*/
public function __construct(\mysqli $conn, $prepareString)
public function __construct(mysqli $conn, $prepareString)
{
$this->_conn = $conn;
$this->_stmt = $conn->prepare($prepareString);
if (false === $this->_stmt) {
if ($this->_stmt === false) {
throw new MysqliException($this->_conn->error, $this->_conn->sqlstate, $this->_conn->errno);
}
$paramCount = $this->_stmt->param_count;
if (0 < $paramCount) {
if (0 >= $paramCount) {
return;
}
$this->types = str_repeat('s', $paramCount);
$this->_bindedValues = array_fill(1, $paramCount, null);
}
}
/**
* {@inheritdoc}
*/
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null)
{
if (null === $type) {
if ($type === null) {
$type = 's';
} else {
if (isset(self::$_paramTypeMap[$type])) {
$type = self::$_paramTypeMap[$type];
} else {
if (! isset(self::$_paramTypeMap[$type])) {
throw new MysqliException("Unknown type: '{$type}'");
}
$type = self::$_paramTypeMap[$type];
}
$this->_bindedValues[$column] =& $variable;
......@@ -129,14 +116,14 @@ class MysqliStatement implements \IteratorAggregate, Statement
*/
public function bindValue($param, $value, $type = ParameterType::STRING)
{
if (null === $type) {
if ($type === null) {
$type = 's';
} else {
if (isset(self::$_paramTypeMap[$type])) {
$type = self::$_paramTypeMap[$type];
} else {
if (! isset(self::$_paramTypeMap[$type])) {
throw new MysqliException("Unknown type: '{$type}'");
}
$type = self::$_paramTypeMap[$type];
}
$this->_values[$param] = $value;
......@@ -151,13 +138,13 @@ class MysqliStatement implements \IteratorAggregate, Statement
*/
public function execute($params = null)
{
if (null !== $this->_bindedValues) {
if (null !== $params) {
if ( ! $this->_bindValues($params)) {
if ($this->_bindedValues !== null) {
if ($params !== null) {
if (! $this->_bindValues($params)) {
throw new MysqliException($this->_stmt->error, $this->_stmt->errno);
}
} else {
list($types, $values, $streams) = $this->separateBoundValues();
[$types, $values, $streams] = $this->separateBoundValues();
if (! $this->_stmt->bind_param($types, ...$values)) {
throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno);
}
......@@ -165,13 +152,13 @@ class MysqliStatement implements \IteratorAggregate, Statement
}
}
if ( ! $this->_stmt->execute()) {
if (! $this->_stmt->execute()) {
throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno);
}
if (null === $this->_columnNames) {
if ($this->_columnNames === null) {
$meta = $this->_stmt->result_metadata();
if (false !== $meta) {
if ($meta !== false) {
$columnNames = [];
foreach ($meta->fetch_fields() as $col) {
$columnNames[] = $col->name;
......@@ -184,7 +171,7 @@ class MysqliStatement implements \IteratorAggregate, Statement
}
}
if (false !== $this->_columnNames) {
if ($this->_columnNames !== false) {
// Store result of every execution which has it. Otherwise it will be impossible
// to execute a new statement in case if the previous one has non-fetched rows
// @link http://dev.mysql.com/doc/refman/5.7/en/commands-out-of-sync.html
......@@ -301,7 +288,7 @@ class MysqliStatement implements \IteratorAggregate, Statement
{
$ret = $this->_stmt->fetch();
if (true === $ret) {
if ($ret === true) {
$values = [];
foreach ($this->_rowBindedValues as $v) {
$values[] = $v;
......@@ -316,11 +303,11 @@ class MysqliStatement implements \IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
{
// do not try fetching from the statement if it's not expected to contain result
// in order to prevent exceptional situation
if (!$this->result) {
if (! $this->result) {
return false;
}
......@@ -331,11 +318,11 @@ class MysqliStatement implements \IteratorAggregate, Statement
}
$values = $this->_fetch();
if (null === $values) {
if ($values === null) {
return false;
}
if (false === $values) {
if ($values === false) {
throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno);
}
......@@ -354,7 +341,7 @@ class MysqliStatement implements \IteratorAggregate, Statement
case FetchMode::STANDARD_OBJECT:
$assoc = array_combine($this->_columnNames, $values);
$ret = new \stdClass();
$ret = new stdClass();
foreach ($assoc as $column => $value) {
$ret->$column = $value;
......@@ -396,7 +383,7 @@ class MysqliStatement implements \IteratorAggregate, Statement
{
$row = $this->fetch(FetchMode::NUMERIC);
if (false === $row) {
if ($row === false) {
return false;
}
......@@ -435,7 +422,7 @@ class MysqliStatement implements \IteratorAggregate, Statement
*/
public function rowCount()
{
if (false === $this->_columnNames) {
if ($this->_columnNames === false) {
return $this->_stmt->affected_rows;
}
......
......@@ -8,9 +8,6 @@ use const OCI_DEFAULT;
/**
* A Doctrine DBAL driver for the Oracle OCI8 PHP extensions.
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/
class Driver extends AbstractOracleDriver
{
......
......@@ -5,6 +5,7 @@ namespace Doctrine\DBAL\Driver\OCI8;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\ParameterType;
use UnexpectedValueException;
use const OCI_COMMIT_ON_SUCCESS;
use const OCI_DEFAULT;
use const OCI_NO_AUTO_COMMIT;
......@@ -26,19 +27,13 @@ use function str_replace;
/**
* OCI8 implementation of the Connection interface.
*
* @since 2.0
*/
class OCI8Connection implements Connection, ServerInfoAwareConnection
{
/**
* @var resource
*/
/** @var resource */
protected $dbh;
/**
* @var int
*/
/** @var int */
protected $executeMode = OCI_COMMIT_ON_SUCCESS;
/**
......@@ -55,7 +50,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
*/
public function __construct($username, $password, $db, $charset = null, $sessionMode = OCI_DEFAULT, $persistent = false)
{
if (!defined('OCI_NO_AUTO_COMMIT')) {
if (! defined('OCI_NO_AUTO_COMMIT')) {
define('OCI_NO_AUTO_COMMIT', 0);
}
......@@ -63,7 +58,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
? @oci_pconnect($username, $password, $db, $charset, $sessionMode)
: @oci_connect($username, $password, $db, $charset, $sessionMode);
if ( ! $this->dbh) {
if (! $this->dbh) {
throw OCI8Exception::fromErrorInfo(oci_error());
}
}
......@@ -71,13 +66,13 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
/**
* {@inheritdoc}
*
* @throws \UnexpectedValueException if the version string returned by the database server
* @throws UnexpectedValueException if the version string returned by the database server
* does not contain a parsable version number.
*/
public function getServerVersion()
{
if ( ! preg_match('/\s+(\d+\.\d+\.\d+\.\d+\.\d+)\s+/', oci_server_version($this->dbh), $version)) {
throw new \UnexpectedValueException(
if (! preg_match('/\s+(\d+\.\d+\.\d+\.\d+\.\d+)\s+/', oci_server_version($this->dbh), $version)) {
throw new UnexpectedValueException(
sprintf(
'Unexpected database version string "%s". Cannot parse an appropriate version number from it. ' .
'Please report this database version string to the Doctrine team.',
......@@ -157,7 +152,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
$result = $stmt->fetchColumn();
if ($result === false) {
throw new OCI8Exception("lastInsertId failed: Query was executed but no result was returned.");
throw new OCI8Exception('lastInsertId failed: Query was executed but no result was returned.');
}
return (int) $result;
......@@ -188,7 +183,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
*/
public function commit()
{
if (!oci_commit($this->dbh)) {
if (! oci_commit($this->dbh)) {
throw OCI8Exception::fromErrorInfo($this->errorInfo());
}
$this->executeMode = OCI_COMMIT_ON_SUCCESS;
......@@ -201,7 +196,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
*/
public function rollBack()
{
if (!oci_rollback($this->dbh)) {
if (! oci_rollback($this->dbh)) {
throw OCI8Exception::fromErrorInfo($this->errorInfo());
}
$this->executeMode = OCI_COMMIT_ON_SUCCESS;
......
......@@ -6,7 +6,9 @@ use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
use InvalidArgumentException;
use IteratorAggregate;
use PDO;
use const OCI_ASSOC;
use const OCI_B_BIN;
use const OCI_B_BLOB;
......@@ -42,35 +44,22 @@ use function substr;
/**
* The OCI8 implementation of the Statement interface.
*
* @since 2.0
* @author Roman Borschel <roman@code-factory.org>
*/
class OCI8Statement implements IteratorAggregate, Statement
{
/**
* @var resource
*/
/** @var resource */
protected $_dbh;
/**
* @var resource
*/
/** @var resource */
protected $_sth;
/**
* @var \Doctrine\DBAL\Driver\OCI8\OCI8Connection
*/
/** @var OCI8Connection */
protected $_conn;
/**
* @var string
*/
/** @var string */
protected static $_PARAM = ':param';
/**
* @var array
*/
/** @var array */
protected static $fetchModeMap = [
FetchMode::MIXED => OCI_BOTH,
FetchMode::ASSOCIATIVE => OCI_ASSOC,
......@@ -78,14 +67,10 @@ class OCI8Statement implements IteratorAggregate, Statement
FetchMode::COLUMN => OCI_NUM,
];
/**
* @var int
*/
/** @var int */
protected $_defaultFetchMode = FetchMode::MIXED;
/**
* @var array
*/
/** @var array */
protected $_paramMap = [];
/**
......@@ -109,11 +94,10 @@ class OCI8Statement implements IteratorAggregate, Statement
*
* @param resource $dbh The connection handle.
* @param string $statement The SQL statement.
* @param \Doctrine\DBAL\Driver\OCI8\OCI8Connection $conn
*/
public function __construct($dbh, $statement, OCI8Connection $conn)
{
list($statement, $paramMap) = self::convertPositionalToNamedPlaceholders($statement);
[$statement, $paramMap] = self::convertPositionalToNamedPlaceholders($statement);
$this->_sth = oci_parse($dbh, $statement);
$this->_dbh = $dbh;
$this->_paramMap = $paramMap;
......@@ -132,13 +116,14 @@ class OCI8Statement implements IteratorAggregate, Statement
* Question marks inside literal strings are therefore handled correctly by this method.
* This comes at a cost, the whole sql statement has to be looped over.
*
* @todo extract into utility class in Doctrine\DBAL\Util namespace
* @todo review and test for lost spaces. we experienced missing spaces with oci8 in some sql statements.
*
* @param string $statement The SQL statement to convert.
*
* @return array [0] => the statement value (string), [1] => the paramMap value (array).
* @throws \Doctrine\DBAL\Driver\OCI8\OCI8Exception
*
* @throws OCI8Exception
*
* @todo extract into utility class in Doctrine\DBAL\Util namespace
* @todo review and test for lost spaces. we experienced missing spaces with oci8 in some sql statements.
*/
public static function convertPositionalToNamedPlaceholders($statement)
{
......@@ -147,7 +132,7 @@ class OCI8Statement implements IteratorAggregate, Statement
$currentLiteralDelimiter = null;
do {
if (!$currentLiteralDelimiter) {
if (! $currentLiteralDelimiter) {
$result = self::findPlaceholderOrOpeningQuote(
$statement,
$tokenOffset,
......@@ -184,6 +169,7 @@ class OCI8Statement implements IteratorAggregate, Statement
* @param string|null $currentLiteralDelimiter The delimiter of the current string literal
* or NULL if not currently in a literal
* @param array<int, string> $paramMap Mapping of the original parameter positions to their named replacements
*
* @return bool Whether the token was found
*/
private static function findPlaceholderOrOpeningQuote(
......@@ -196,7 +182,7 @@ class OCI8Statement implements IteratorAggregate, Statement
) {
$token = self::findToken($statement, $tokenOffset, '/[?\'"]/');
if (!$token) {
if (! $token) {
return false;
}
......@@ -225,6 +211,7 @@ class OCI8Statement implements IteratorAggregate, Statement
* @param string $tokenOffset The offset to start searching from
* @param string|null $currentLiteralDelimiter The delimiter of the current string literal
* or NULL if not currently in a literal
*
* @return bool Whether the token was found
*/
private static function findClosingQuote(
......@@ -238,7 +225,7 @@ class OCI8Statement implements IteratorAggregate, Statement
'/' . preg_quote($currentLiteralDelimiter, '/') . '/'
);
if (!$token) {
if (! $token) {
return false;
}
......@@ -255,6 +242,7 @@ class OCI8Statement implements IteratorAggregate, Statement
* @param string $statement The SQL statement to parse
* @param string $offset The offset to start searching from
* @param string $regex The regex containing token pattern
*
* @return string|null Token or NULL if not found
*/
private static function findToken($statement, &$offset, $regex)
......@@ -323,7 +311,7 @@ class OCI8Statement implements IteratorAggregate, Statement
public function closeCursor()
{
// not having the result means there's nothing to close
if (!$this->result) {
if (! $this->result) {
return true;
}
......@@ -380,7 +368,7 @@ class OCI8Statement implements IteratorAggregate, Statement
}
$ret = @oci_execute($this->_sth, $this->_conn->getExecuteMode());
if ( ! $ret) {
if (! $ret) {
throw OCI8Exception::fromErrorInfo($this->errorInfo());
}
......@@ -410,11 +398,11 @@ class OCI8Statement implements IteratorAggregate, Statement
/**
* {@inheritdoc}
*/
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
{
// do not try fetching from the statement if it's not expected to contain result
// in order to prevent exceptional situation
if (!$this->result) {
if (! $this->result) {
return false;
}
......@@ -429,7 +417,7 @@ class OCI8Statement implements IteratorAggregate, Statement
}
if (! isset(self::$fetchModeMap[$fetchMode])) {
throw new \InvalidArgumentException("Invalid fetch style: " . $fetchMode);
throw new InvalidArgumentException('Invalid fetch style: ' . $fetchMode);
}
return oci_fetch_array(
......@@ -455,8 +443,8 @@ class OCI8Statement implements IteratorAggregate, Statement
return $result;
}
if ( ! isset(self::$fetchModeMap[$fetchMode])) {
throw new \InvalidArgumentException("Invalid fetch style: " . $fetchMode);
if (! isset(self::$fetchModeMap[$fetchMode])) {
throw new InvalidArgumentException('Invalid fetch style: ' . $fetchMode);
}
if (self::$fetchModeMap[$fetchMode] === OCI_BOTH) {
......@@ -472,12 +460,17 @@ class OCI8Statement implements IteratorAggregate, Statement
// do not try fetching from the statement if it's not expected to contain result
// in order to prevent exceptional situation
if (!$this->result) {
if (! $this->result) {
return [];
}
oci_fetch_all($this->_sth, $result, 0, -1,
self::$fetchModeMap[$fetchMode] | OCI_RETURN_NULLS | $fetchStructure | OCI_RETURN_LOBS);
oci_fetch_all(
$this->_sth,
$result,
0,
-1,
self::$fetchModeMap[$fetchMode] | OCI_RETURN_NULLS | $fetchStructure | OCI_RETURN_LOBS
);
if ($fetchMode === FetchMode::COLUMN) {
$result = $result[0];
......@@ -494,13 +487,13 @@ class OCI8Statement implements IteratorAggregate, Statement
{
// do not try fetching from the statement if it's not expected to contain result
// in order to prevent exceptional situation
if (!$this->result) {
if (! $this->result) {
return false;
}
$row = oci_fetch_array($this->_sth, OCI_NUM | OCI_RETURN_NULLS | OCI_RETURN_LOBS);
if (false === $row) {
if ($row === false) {
return false;
}
......
......@@ -10,8 +10,6 @@ use function func_get_args;
/**
* PDO implementation of the Connection interface.
* Used by all PDO-based drivers.
*
* @since 2.0
*/
class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection
{
......@@ -23,7 +21,7 @@ class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection
*
* @throws PDOException in case of an error.
*/
public function __construct($dsn, $user = null, $password = null, array $options = null)
public function __construct($dsn, $user = null, $password = null, ?array $options = null)
{
try {
parent::__construct($dsn, $user, $password, $options);
......@@ -75,15 +73,15 @@ class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection
$argsCount = count($args);
try {
if ($argsCount == 4) {
if ($argsCount === 4) {
return parent::query($args[0], $args[1], $args[2], $args[3]);
}
if ($argsCount == 3) {
if ($argsCount === 3) {
return parent::query($args[0], $args[1], $args[2]);
}
if ($argsCount == 2) {
if ($argsCount === 2) {
return parent::query($args[0], $args[1]);
}
......
......@@ -5,9 +5,7 @@ namespace Doctrine\DBAL\Driver;
/**
* Tiny wrapper for PDOException instances to implement the {@link DriverException} interface.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
class PDOException extends \PDOException implements DriverException
{
......@@ -26,8 +24,6 @@ class PDOException extends \PDOException implements DriverException
private $sqlState;
/**
* Constructor.
*
* @param \PDOException $exception The PDO exception to wrap.
*/
public function __construct(\PDOException $exception)
......
......@@ -9,11 +9,6 @@ use Doctrine\DBAL\Driver\PDOConnection;
* Driver for the PDO IBM extension.
*
* @link www.doctrine-project.org
* @since 1.0
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class Driver extends AbstractDB2Driver
{
......@@ -22,14 +17,12 @@ class Driver extends AbstractDB2Driver
*/
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
{
$conn = new PDOConnection(
return new PDOConnection(
$this->_constructPdoDsn($params),
$username,
$password,
$driverOptions
);
return $conn;
}
/**
......
......@@ -9,8 +9,6 @@ use PDOException;
/**
* PDO MySql driver.
*
* @since 2.0
*/
class Driver extends AbstractMySQLDriver
{
......@@ -43,7 +41,7 @@ class Driver extends AbstractMySQLDriver
protected function constructPdoDsn(array $params)
{
$dsn = 'mysql:';
if (isset($params['host']) && $params['host'] != '') {
if (isset($params['host']) && $params['host'] !== '') {
$dsn .= 'host=' . $params['host'] . ';';
}
if (isset($params['port'])) {
......
......@@ -5,6 +5,7 @@ namespace Doctrine\DBAL\Driver\PDOOracle;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\AbstractOracleDriver;
use Doctrine\DBAL\Driver\PDOConnection;
use PDOException;
/**
* PDO Oracle driver.
......@@ -28,7 +29,7 @@ class Driver extends AbstractOracleDriver
$password,
$driverOptions
);
} catch (\PDOException $e) {
} catch (PDOException $e) {
throw DBALException::driverException($this, $e);
}
}
......
......@@ -2,17 +2,15 @@
namespace Doctrine\DBAL\Driver\PDOPgSql;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver;
use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\DBALException;
use PDOException;
use PDO;
use PDOException;
use function defined;
/**
* Driver that connects through pdo_pgsql.
*
* @since 2.0
*/
class Driver extends AbstractPostgreSQLDriver
{
......@@ -31,7 +29,7 @@ class Driver extends AbstractPostgreSQLDriver
if (defined('PDO::PGSQL_ATTR_DISABLE_PREPARES')
&& (! isset($driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES])
|| true === $driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES]
|| $driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES] === true
)
) {
$pdo->setAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES, true);
......@@ -62,11 +60,11 @@ class Driver extends AbstractPostgreSQLDriver
{
$dsn = 'pgsql:';
if (isset($params['host']) && $params['host'] != '') {
if (isset($params['host']) && $params['host'] !== '') {
$dsn .= 'host=' . $params['host'] . ';';
}
if (isset($params['port']) && $params['port'] != '') {
if (isset($params['port']) && $params['port'] !== '') {
$dsn .= 'port=' . $params['port'] . ';';
}
......
......@@ -10,14 +10,10 @@ use function array_merge;
/**
* The PDO Sqlite driver.
*
* @since 2.0
*/
class Driver extends AbstractSQLiteDriver
{
/**
* @var array
*/
/** @var array */
protected $_userDefinedFunctions = [
'sqrt' => ['callback' => ['Doctrine\DBAL\Platforms\SqlitePlatform', 'udfSqrt'], 'numArgs' => 1],
'mod' => ['callback' => ['Doctrine\DBAL\Platforms\SqlitePlatform', 'udfMod'], 'numArgs' => 2],
......@@ -31,7 +27,9 @@ class Driver extends AbstractSQLiteDriver
{
if (isset($driverOptions['userDefinedFunctions'])) {
$this->_userDefinedFunctions = array_merge(
$this->_userDefinedFunctions, $driverOptions['userDefinedFunctions']);
$this->_userDefinedFunctions,
$driverOptions['userDefinedFunctions']
);
unset($driverOptions['userDefinedFunctions']);
}
......
......@@ -4,23 +4,22 @@ namespace Doctrine\DBAL\Driver\PDOSqlsrv;
use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\ParameterType;
use PDO;
use function strpos;
use function substr;
/**
* Sqlsrv Connection implementation.
*
* @since 2.0
*/
class Connection extends PDOConnection implements \Doctrine\DBAL\Driver\Connection
{
/**
* {@inheritdoc}
*/
public function __construct($dsn, $user = null, $password = null, array $options = null)
public function __construct($dsn, $user = null, $password = null, ?array $options = null)
{
parent::__construct($dsn, $user, $password, $options);
$this->setAttribute(\PDO::ATTR_STATEMENT_CLASS, [Statement::class, []]);
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, [Statement::class, []]);
}
/**
......@@ -28,7 +27,7 @@ class Connection extends PDOConnection implements \Doctrine\DBAL\Driver\Connecti
*/
public function lastInsertId($name = null)
{
if (null === $name) {
if ($name === null) {
return parent::lastInsertId($name);
}
......
......@@ -8,8 +8,6 @@ use function sprintf;
/**
* The PDO-based Sqlsrv driver.
*
* @since 2.0
*/
class Driver extends AbstractSQLServerDriver
{
......@@ -44,7 +42,7 @@ class Driver extends AbstractSQLServerDriver
$dsn .= $params['host'];
}
if (isset($params['port']) && !empty($params['port'])) {
if (isset($params['port']) && ! empty($params['port'])) {
$dsn .= ',' . $params['port'];
}
......@@ -65,6 +63,7 @@ class Driver extends AbstractSQLServerDriver
* Separates a connection options from a driver options
*
* @param int[]|string[] $options
*
* @return int[][]|string[][]
*/
private function splitOptions(array $options) : array
......
......@@ -12,14 +12,9 @@ use function trigger_error;
/**
* The PDO implementation of the Statement interface.
* Used by all PDO-based drivers.
*
* @since 2.0
*/
class PDOStatement extends \PDOStatement implements Statement
{
/**
* @var int[]
*/
private const PARAM_TYPE_MAP = [
ParameterType::NULL => PDO::PARAM_NULL,
ParameterType::INTEGER => PDO::PARAM_INT,
......@@ -29,9 +24,6 @@ class PDOStatement extends \PDOStatement implements Statement
ParameterType::BOOLEAN => PDO::PARAM_BOOL,
];
/**
* @var int[]
*/
private const FETCH_MODE_MAP = [
FetchMode::ASSOCIATIVE => PDO::FETCH_ASSOC,
FetchMode::NUMERIC => PDO::FETCH_NUM,
......@@ -131,20 +123,20 @@ class PDOStatement extends \PDOStatement implements Statement
/**
* {@inheritdoc}
*/
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
{
$fetchMode = $this->convertFetchMode($fetchMode);
try {
if ($fetchMode === null && \PDO::FETCH_ORI_NEXT === $cursorOrientation && 0 === $cursorOffset) {
if ($fetchMode === null && $cursorOrientation === PDO::FETCH_ORI_NEXT && $cursorOffset === 0) {
return parent::fetch();
}
if (\PDO::FETCH_ORI_NEXT === $cursorOrientation && 0 === $cursorOffset) {
if ($cursorOrientation === PDO::FETCH_ORI_NEXT && $cursorOffset === 0) {
return parent::fetch($fetchMode);
}
if (0 === $cursorOffset) {
if ($cursorOffset === 0) {
return parent::fetch($fetchMode, $cursorOrientation);
}
......@@ -162,15 +154,15 @@ class PDOStatement extends \PDOStatement implements Statement
$fetchMode = $this->convertFetchMode($fetchMode);
try {
if ($fetchMode === null && null === $fetchArgument && null === $ctorArgs) {
if ($fetchMode === null && $fetchArgument === null && $ctorArgs === null) {
return parent::fetchAll();
}
if (null === $fetchArgument && null === $ctorArgs) {
if ($fetchArgument === null && $ctorArgs === null) {
return parent::fetchAll($fetchMode);
}
if (null === $ctorArgs) {
if ($ctorArgs === null) {
return parent::fetchAll($fetchMode, $fetchArgument);
}
......
......@@ -6,9 +6,6 @@ namespace Doctrine\DBAL\Driver;
* An interface for connections which support a "native" ping method.
*
* @link www.doctrine-project.org
* @since 2.5
* @author Till Klampaeckel <till@php.net>
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
interface PingableConnection
{
......
......@@ -2,12 +2,13 @@
namespace Doctrine\DBAL\Driver;
use PDO;
use Traversable;
/**
* Interface for the reading part of a prepare statement only.
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
interface ResultStatement extends \Traversable
interface ResultStatement extends Traversable
{
/**
* Closes the cursor, enabling the statement to be executed again.
......@@ -61,7 +62,7 @@ interface ResultStatement extends \Traversable
* @return mixed The return value of this method on success depends on the fetch mode. In all cases, FALSE is
* returned on failure.
*/
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0);
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0);
/**
* Returns an array containing all of the result set rows.
......@@ -92,7 +93,7 @@ interface ResultStatement extends \Traversable
* If no value is supplied, PDOStatement->fetchColumn()
* fetches the first column.
*
* @return string|boolean A single column in the next row of a result set, or FALSE if there are no more rows.
* @return string|bool A single column in the next row of a result set, or FALSE if there are no more rows.
*/
public function fetchColumn($columnIndex = 0);
}
......@@ -11,16 +11,14 @@ use function implode;
/**
* A Doctrine DBAL driver for the SAP Sybase SQL Anywhere PHP extension.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
class Driver extends AbstractSQLAnywhereDriver
{
/**
* {@inheritdoc}
*
* @throws \Doctrine\DBAL\DBALException if there was a problem establishing the connection.
* @throws DBALException if there was a problem establishing the connection.
*/
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
{
......@@ -74,15 +72,14 @@ class Driver extends AbstractSQLAnywhereDriver
$server = ';ServerName=' . $server;
}
return
'HOST=' . $host . ':' . $port .
return 'HOST=' . $host . ':' . $port .
$server .
';DBN=' . $dbname .
';UID=' . $username .
';PWD=' . $password .
';' . implode(
';',
array_map(function ($key, $value) {
array_map(static function ($key, $value) {
return $key . '=' . $value;
}, array_keys($driverOptions), $driverOptions)
);
......
......@@ -26,20 +26,14 @@ use function sasql_set_option;
/**
* SAP Sybase SQL Anywhere implementation of the Connection interface.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
{
/**
* @var resource The SQL Anywhere connection resource.
*/
/** @var resource The SQL Anywhere connection resource. */
private $connection;
/**
* Constructor.
*
* Connects to database with given connection string.
*
* @param string $dsn The connection string.
......@@ -51,22 +45,22 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
{
$this->connection = $persistent ? @sasql_pconnect($dsn) : @sasql_connect($dsn);
if ( ! is_resource($this->connection)) {
if (! is_resource($this->connection)) {
throw SQLAnywhereException::fromSQLAnywhereError();
}
// Disable PHP warnings on error.
if ( ! sasql_set_option($this->connection, 'verbose_errors', false)) {
if (! sasql_set_option($this->connection, 'verbose_errors', false)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
}
// Enable auto committing by default.
if ( ! sasql_set_option($this->connection, 'auto_commit', 'on')) {
if (! sasql_set_option($this->connection, 'auto_commit', 'on')) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
}
// Enable exact, non-approximated row count retrieval.
if ( ! sasql_set_option($this->connection, 'row_counts', true)) {
if (! sasql_set_option($this->connection, 'row_counts', true)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
}
}
......@@ -78,7 +72,7 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
*/
public function beginTransaction()
{
if ( ! sasql_set_option($this->connection, 'auto_commit', 'off')) {
if (! sasql_set_option($this->connection, 'auto_commit', 'off')) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
}
......@@ -92,7 +86,7 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
*/
public function commit()
{
if ( ! sasql_commit($this->connection)) {
if (! sasql_commit($this->connection)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
}
......@@ -122,7 +116,7 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
*/
public function exec($statement)
{
if (false === sasql_real_query($this->connection, $statement)) {
if (sasql_real_query($this->connection, $statement) === false) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
}
......@@ -146,7 +140,7 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
*/
public function lastInsertId($name = null)
{
if (null === $name) {
if ($name === null) {
return sasql_insert_id($this->connection);
}
......@@ -201,7 +195,7 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
*/
public function rollBack()
{
if ( ! sasql_rollback($this->connection)) {
if (! sasql_rollback($this->connection)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
}
......@@ -213,13 +207,13 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
/**
* Ends transactional mode and enables auto commit again.
*
* @throws SQLAnywhereException
*
* @return bool Whether or not ending transactional mode succeeded.
*
* @throws SQLAnywhereException
*/
private function endTransaction()
{
if ( ! sasql_set_option($this->connection, 'auto_commit', 'on')) {
if (! sasql_set_option($this->connection, 'auto_commit', 'on')) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
}
......
......@@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Driver\SQLAnywhere;
use Doctrine\DBAL\Driver\AbstractDriverException;
use InvalidArgumentException;
use function is_resource;
use function sasql_error;
use function sasql_errorcode;
......@@ -13,9 +14,7 @@ use function sasql_stmt_error;
/**
* SAP Sybase SQL Anywhere driver exception.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
class SQLAnywhereException extends AbstractDriverException
{
......@@ -27,16 +26,16 @@ class SQLAnywhereException extends AbstractDriverException
*
* @return SQLAnywhereException
*
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*/
public static function fromSQLAnywhereError($conn = null, $stmt = null)
{
if (null !== $conn && ! (is_resource($conn))) {
throw new \InvalidArgumentException('Invalid SQL Anywhere connection resource given: ' . $conn);
if ($conn !== null && ! is_resource($conn)) {
throw new InvalidArgumentException('Invalid SQL Anywhere connection resource given: ' . $conn);
}
if (null !== $stmt && ! (is_resource($stmt))) {
throw new \InvalidArgumentException('Invalid SQL Anywhere statement resource given: ' . $stmt);
if ($stmt !== null && ! is_resource($stmt)) {
throw new InvalidArgumentException('Invalid SQL Anywhere statement resource given: ' . $stmt);
}
$state = $conn ? sasql_sqlstate($conn) : sasql_sqlstate();
......@@ -69,7 +68,7 @@ class SQLAnywhereException extends AbstractDriverException
* or the last error could not be retrieved from the given
* connection / statement resource.
*/
if ( ! $conn || ! $code) {
if (! $conn || ! $code) {
$code = sasql_errorcode();
$message = sasql_error();
}
......
......@@ -7,6 +7,10 @@ use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use PDO;
use ReflectionClass;
use ReflectionObject;
use stdClass;
use const SASQL_BOTH;
use function array_key_exists;
use function func_get_args;
......@@ -35,45 +39,29 @@ use function sprintf;
/**
* SAP SQL Anywhere implementation of the Statement interface.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
class SQLAnywhereStatement implements IteratorAggregate, Statement
{
/**
* @var resource The connection resource.
*/
/** @var resource The connection resource. */
private $conn;
/**
* @var string Name of the default class to instantiate when fetching class instances.
*/
/** @var string Name of the default class to instantiate when fetching class instances. */
private $defaultFetchClass = '\stdClass';
/**
* @var mixed[] Constructor arguments for the default class to instantiate when fetching class instances.
*/
/** @var mixed[] Constructor arguments for the default class to instantiate when fetching class instances. */
private $defaultFetchClassCtorArgs = [];
/**
* @var int Default fetch mode to use.
*/
/** @var int Default fetch mode to use. */
private $defaultFetchMode = FetchMode::MIXED;
/**
* @var resource The result set resource to fetch.
*/
/** @var resource The result set resource to fetch. */
private $result;
/**
* @var resource The prepared SQL statement to execute.
*/
/** @var resource The prepared SQL statement to execute. */
private $stmt;
/**
* Constructor.
*
* Prepares given statement for given connection.
*
* @param resource $conn The connection resource to use.
......@@ -83,14 +71,14 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
*/
public function __construct($conn, $sql)
{
if ( ! is_resource($conn)) {
if (! is_resource($conn)) {
throw new SQLAnywhereException('Invalid SQL Anywhere connection resource: ' . $conn);
}
$this->conn = $conn;
$this->stmt = sasql_prepare($conn, $sql);
if ( ! is_resource($this->stmt)) {
if (! is_resource($this->stmt)) {
throw SQLAnywhereException::fromSQLAnywhereError($conn);
}
}
......@@ -122,7 +110,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
throw new SQLAnywhereException('Unknown type: ' . $type);
}
if ( ! sasql_stmt_bind_param_ex($this->stmt, $column - 1, $variable, $type, $variable === null)) {
if (! sasql_stmt_bind_param_ex($this->stmt, $column - 1, $variable, $type, $variable === null)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->conn, $this->stmt);
}
......@@ -144,7 +132,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
*/
public function closeCursor()
{
if (!sasql_stmt_reset($this->stmt)) {
if (! sasql_stmt_reset($this->stmt)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->conn, $this->stmt);
}
......@@ -186,13 +174,13 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
$hasZeroIndex = array_key_exists(0, $params);
foreach ($params as $key => $val) {
$key = ($hasZeroIndex && is_numeric($key)) ? $key + 1 : $key;
$key = $hasZeroIndex && is_numeric($key) ? $key + 1 : $key;
$this->bindValue($key, $val);
}
}
if ( ! sasql_stmt_execute($this->stmt)) {
if (! sasql_stmt_execute($this->stmt)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->conn, $this->stmt);
}
......@@ -206,9 +194,9 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
*
* @throws SQLAnywhereException
*/
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
{
if ( ! is_resource($this->result)) {
if (! is_resource($this->result)) {
return false;
}
......@@ -236,7 +224,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
$result = sasql_fetch_object($this->result);
if ($result instanceof \stdClass) {
if ($result instanceof stdClass) {
$result = $this->castObject($result, $className, $ctorArgs);
}
......@@ -289,7 +277,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
{
$row = $this->fetch(FetchMode::NUMERIC);
if (false === $row) {
if ($row === false) {
return false;
}
......@@ -325,7 +313,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
/**
* Casts a stdClass object to the given class name mapping its' properties.
*
* @param \stdClass $sourceObject Object to cast from.
* @param stdClass $sourceObject Object to cast from.
* @param string|object $destinationClass Name of the class or class instance to cast to.
* @param array $ctorArgs Arguments to use for constructing the destination class instance.
*
......@@ -333,21 +321,22 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
*
* @throws SQLAnywhereException
*/
private function castObject(\stdClass $sourceObject, $destinationClass, array $ctorArgs = [])
private function castObject(stdClass $sourceObject, $destinationClass, array $ctorArgs = [])
{
if ( ! is_string($destinationClass)) {
if ( ! is_object($destinationClass)) {
if (! is_string($destinationClass)) {
if (! is_object($destinationClass)) {
throw new SQLAnywhereException(sprintf(
'Destination class has to be of type string or object, %s given.', gettype($destinationClass)
'Destination class has to be of type string or object, %s given.',
gettype($destinationClass)
));
}
} else {
$destinationClass = new \ReflectionClass($destinationClass);
$destinationClass = new ReflectionClass($destinationClass);
$destinationClass = $destinationClass->newInstanceArgs($ctorArgs);
}
$sourceReflection = new \ReflectionObject($sourceObject);
$destinationClassReflection = new \ReflectionObject($destinationClass);
$sourceReflection = new ReflectionObject($sourceObject);
$destinationClassReflection = new ReflectionObject($destinationClass);
foreach ($sourceReflection->getProperties() as $sourceProperty) {
$sourceProperty->setAccessible(true);
......
......@@ -14,7 +14,7 @@ class Driver extends AbstractSQLServerDriver
*/
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
{
if (!isset($params['host'])) {
if (! isset($params['host'])) {
throw new SQLSrvException("Missing 'host' in configuration for sqlsrv driver.");
}
......@@ -34,7 +34,7 @@ class Driver extends AbstractSQLServerDriver
$driverOptions['UID'] = $username;
$driverOptions['PWD'] = $password;
if (!isset($driverOptions['ReturnDatesAsStrings'])) {
if (! isset($driverOptions['ReturnDatesAsStrings'])) {
$driverOptions['ReturnDatesAsStrings'] = 1;
}
......
......@@ -4,15 +4,10 @@ namespace Doctrine\DBAL\Driver\SQLSrv;
/**
* Last Id Data Container.
*
* @since 2.3
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class LastInsertId
{
/**
* @var int
*/
/** @var int */
private $id;
/**
......
......@@ -23,36 +23,29 @@ use function str_replace;
/**
* SQL Server implementation for the Connection interface.
*
* @since 2.3
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class SQLSrvConnection implements Connection, ServerInfoAwareConnection
{
/**
* @var resource
*/
/** @var resource */
protected $conn;
/**
* @var \Doctrine\DBAL\Driver\SQLSrv\LastInsertId
*/
/** @var LastInsertId */
protected $lastInsertId;
/**
* @param string $serverName
* @param array $connectionOptions
*
* @throws \Doctrine\DBAL\Driver\SQLSrv\SQLSrvException
* @throws SQLSrvException
*/
public function __construct($serverName, $connectionOptions)
{
if ( ! sqlsrv_configure('WarningsReturnAsErrors', 0)) {
if (! sqlsrv_configure('WarningsReturnAsErrors', 0)) {
throw SQLSrvException::fromSqlSrvErrors();
}
$this->conn = sqlsrv_connect($serverName, $connectionOptions);
if ( ! $this->conn) {
if (! $this->conn) {
throw SQLSrvException::fromSqlSrvErrors();
}
$this->lastInsertId = new LastInsertId();
......@@ -99,7 +92,6 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
/**
* {@inheritDoc}
* @license New BSD, code from Zend Framework
*/
public function quote($value, $type = ParameterType::STRING)
{
......@@ -119,7 +111,7 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
{
$stmt = sqlsrv_query($this->conn, $statement);
if (false === $stmt) {
if ($stmt === false) {
throw SQLSrvException::fromSqlSrvErrors();
}
......@@ -146,7 +138,7 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
*/
public function beginTransaction()
{
if ( ! sqlsrv_begin_transaction($this->conn)) {
if (! sqlsrv_begin_transaction($this->conn)) {
throw SQLSrvException::fromSqlSrvErrors();
}
}
......@@ -156,7 +148,7 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
*/
public function commit()
{
if ( ! sqlsrv_commit($this->conn)) {
if (! sqlsrv_commit($this->conn)) {
throw SQLSrvException::fromSqlSrvErrors();
}
}
......@@ -166,7 +158,7 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
*/
public function rollBack()
{
if ( ! sqlsrv_rollback($this->conn)) {
if (! sqlsrv_rollback($this->conn)) {
throw SQLSrvException::fromSqlSrvErrors();
}
}
......
......@@ -2,7 +2,6 @@
namespace Doctrine\DBAL\Driver\SQLSrv;
use Doctrine\DBAL\Driver\AbstractDriverException;
use const SQLSRV_ERR_ERRORS;
use function rtrim;
......@@ -18,23 +17,25 @@ class SQLSrvException extends AbstractDriverException
public static function fromSqlSrvErrors()
{
$errors = sqlsrv_errors(SQLSRV_ERR_ERRORS);
$message = "";
$message = '';
$sqlState = null;
$errorCode = null;
foreach ($errors as $error) {
$message .= "SQLSTATE [".$error['SQLSTATE'].", ".$error['code']."]: ". $error['message']."\n";
$message .= 'SQLSTATE [' . $error['SQLSTATE'] . ', ' . $error['code'] . ']: ' . $error['message'] . "\n";
if (null === $sqlState) {
if ($sqlState === null) {
$sqlState = $error['SQLSTATE'];
}
if (null === $errorCode) {
$errorCode = $error['code'];
if ($errorCode !== null) {
continue;
}
$errorCode = $error['code'];
}
if ( ! $message) {
$message = "SQL Server error occurred but no error message was retrieved from driver.";
if (! $message) {
$message = 'SQL Server error occurred but no error message was retrieved from driver.';
}
return new self(rtrim($message), $sqlState, $errorCode);
......
......@@ -2,11 +2,12 @@
namespace Doctrine\DBAL\Driver\SQLSrv;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Driver\StatementIterator;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use Doctrine\DBAL\Driver\Statement;
use PDO;
use const SQLSRV_ENC_BINARY;
use const SQLSRV_ERR_ERRORS;
use const SQLSRV_FETCH_ASSOC;
......@@ -35,9 +36,6 @@ use function stripos;
/**
* SQL Server Statement.
*
* @since 2.3
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class SQLSrvStatement implements IteratorAggregate, Statement
{
......@@ -111,7 +109,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
/**
* The last insert ID.
*
* @var \Doctrine\DBAL\Driver\SQLSrv\LastInsertId|null
* @var LastInsertId|null
*/
private $lastInsertId;
......@@ -124,33 +122,32 @@ class SQLSrvStatement implements IteratorAggregate, Statement
/**
* Append to any INSERT query to retrieve the last insert id.
*
* @var string
*/
const LAST_INSERT_ID_SQL = ';SELECT SCOPE_IDENTITY() AS LastInsertId;';
public const LAST_INSERT_ID_SQL = ';SELECT SCOPE_IDENTITY() AS LastInsertId;';
/**
* @param resource $conn
* @param string $sql
* @param \Doctrine\DBAL\Driver\SQLSrv\LastInsertId|null $lastInsertId
*/
public function __construct($conn, $sql, LastInsertId $lastInsertId = null)
public function __construct($conn, $sql, ?LastInsertId $lastInsertId = null)
{
$this->conn = $conn;
$this->sql = $sql;
if (stripos($sql, 'INSERT INTO ') === 0) {
if (stripos($sql, 'INSERT INTO ') !== 0) {
return;
}
$this->sql .= self::LAST_INSERT_ID_SQL;
$this->lastInsertId = $lastInsertId;
}
}
/**
* {@inheritdoc}
*/
public function bindValue($param, $value, $type = ParameterType::STRING)
{
if (!is_numeric($param)) {
if (! is_numeric($param)) {
throw new SQLSrvException(
'sqlsrv does not support named parameters to queries, use question mark (?) placeholders instead.'
);
......@@ -165,8 +162,8 @@ class SQLSrvStatement implements IteratorAggregate, Statement
*/
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null)
{
if (!is_numeric($column)) {
throw new SQLSrvException("sqlsrv does not support named parameters to queries, use question mark (?) placeholders instead.");
if (! is_numeric($column)) {
throw new SQLSrvException('sqlsrv does not support named parameters to queries, use question mark (?) placeholders instead.');
}
$this->variables[$column] =& $variable;
......@@ -182,7 +179,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
public function closeCursor()
{
// not having the result means there's nothing to close
if (!$this->result) {
if (! $this->result) {
return true;
}
......@@ -190,7 +187,8 @@ class SQLSrvStatement implements IteratorAggregate, Statement
// @link http://php.net/manual/en/pdostatement.closecursor.php
// @link https://github.com/php/php-src/blob/php-7.0.11/ext/pdo/pdo_stmt.c#L2075
// deliberately do not consider multiple result sets, since doctrine/dbal doesn't support them
while (sqlsrv_fetch($this->stmt));
while (sqlsrv_fetch($this->stmt)) {
}
$this->result = false;
......@@ -234,16 +232,16 @@ class SQLSrvStatement implements IteratorAggregate, Statement
if ($params) {
$hasZeroIndex = array_key_exists(0, $params);
foreach ($params as $key => $val) {
$key = ($hasZeroIndex && is_numeric($key)) ? $key + 1 : $key;
$key = $hasZeroIndex && is_numeric($key) ? $key + 1 : $key;
$this->bindValue($key, $val);
}
}
if ( ! $this->stmt) {
if (! $this->stmt) {
$this->stmt = $this->prepare();
}
if (!sqlsrv_execute($this->stmt)) {
if (! sqlsrv_execute($this->stmt)) {
throw SQLSrvException::fromSqlSrvErrors();
}
......@@ -260,6 +258,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
* Prepares SQL Server statement resource
*
* @return resource
*
* @throws SQLSrvException
*/
private function prepare()
......@@ -272,8 +271,8 @@ class SQLSrvStatement implements IteratorAggregate, Statement
$params[$column - 1] = [
&$variable,
SQLSRV_PARAM_IN,
SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_VARBINARY('max'),
sqlsrv_phptype_stream(SQLSRV_ENC_BINARY),
sqlsrv_sqltype_varbinary('max'),
];
break;
......@@ -281,7 +280,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
$params[$column - 1] = [
&$variable,
SQLSRV_PARAM_IN,
SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY),
sqlsrv_phptype_string(SQLSRV_ENC_BINARY),
];
break;
......@@ -293,7 +292,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
$stmt = sqlsrv_prepare($this->conn, $this->sql, $params);
if (!$stmt) {
if (! $stmt) {
throw SQLSrvException::fromSqlSrvErrors();
}
......@@ -325,11 +324,11 @@ class SQLSrvStatement implements IteratorAggregate, Statement
*
* @throws SQLSrvException
*/
public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
{
// do not try fetching from the statement if it's not expected to contain result
// in order to prevent exceptional situation
if (!$this->result) {
if (! $this->result) {
return false;
}
......@@ -395,7 +394,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
{
$row = $this->fetch(FetchMode::NUMERIC);
if (false === $row) {
if ($row === false) {
return false;
}
......
......@@ -5,9 +5,7 @@ namespace Doctrine\DBAL\Driver;
/**
* Contract for a connection that is able to provide information about the server it is connected to.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
interface ServerInfoAwareConnection
{
......
......@@ -10,10 +10,7 @@ use Doctrine\DBAL\ParameterType;
*
* This resembles (a subset of) the PDOStatement interface.
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Roman Borschel <roman@code-factory.org>
* @link www.doctrine-project.org
* @since 2.0
*/
interface Statement extends ResultStatement
{
......@@ -90,7 +87,6 @@ interface Statement extends ResultStatement
* if any, of their associated parameter markers or pass an array of input-only
* parameter values.
*
*
* @param array|null $params An array of values with as many elements as there are
* bound parameters in the SQL statement being executed.
*
......
......@@ -2,16 +2,13 @@
namespace Doctrine\DBAL\Driver;
class StatementIterator implements \IteratorAggregate
use IteratorAggregate;
class StatementIterator implements IteratorAggregate
{
/**
* @var Statement
*/
/** @var Statement */
private $statement;
/**
* @param Statement $statement
*/
public function __construct(Statement $statement)
{
$this->statement = $statement;
......@@ -22,7 +19,7 @@ class StatementIterator implements \IteratorAggregate
*/
public function getIterator()
{
while (false !== ($result = $this->statement->fetch())) {
while (($result = $this->statement->fetch()) !== false) {
yield $result;
}
}
......
......@@ -3,6 +3,7 @@
namespace Doctrine\DBAL;
use Doctrine\Common\EventManager;
use PDO;
use function array_keys;
use function array_map;
use function array_merge;
......@@ -18,9 +19,6 @@ use function substr;
/**
* Factory for creating Doctrine\DBAL\Connection instances.
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/
final class DriverManager
{
......@@ -116,23 +114,21 @@ final class DriverManager
* The driver class to use.
*
* @param array $params The parameters.
* @param \Doctrine\DBAL\Configuration|null $config The configuration to use.
* @param \Doctrine\Common\EventManager|null $eventManager The event manager to use.
*
* @return \Doctrine\DBAL\Connection
* @param Configuration|null $config The configuration to use.
* @param EventManager|null $eventManager The event manager to use.
*
* @throws \Doctrine\DBAL\DBALException
* @throws DBALException
*/
public static function getConnection(
array $params,
Configuration $config = null,
EventManager $eventManager = null): Connection
{
?Configuration $config = null,
?EventManager $eventManager = null
) : Connection {
// create default config and event manager, if not set
if ( ! $config) {
if (! $config) {
$config = new Configuration();
}
if ( ! $eventManager) {
if (! $eventManager) {
$eventManager = new EventManager();
}
......@@ -161,11 +157,11 @@ final class DriverManager
}
// check for existing pdo object
if (isset($params['pdo']) && ! $params['pdo'] instanceof \PDO) {
if (isset($params['pdo']) && ! $params['pdo'] instanceof PDO) {
throw DBALException::invalidPdoInstance();
} elseif (isset($params['pdo'])) {
$params['pdo']->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$params['driver'] = 'pdo_' . $params['pdo']->getAttribute(\PDO::ATTR_DRIVER_NAME);
$params['pdo']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$params['driver'] = 'pdo_' . $params['pdo']->getAttribute(PDO::ATTR_DRIVER_NAME);
} else {
self::_checkParams($params);
}
......@@ -176,11 +172,11 @@ final class DriverManager
$wrapperClass = 'Doctrine\DBAL\Connection';
if (isset($params['wrapperClass'])) {
if (is_subclass_of($params['wrapperClass'], $wrapperClass)) {
$wrapperClass = $params['wrapperClass'];
} else {
if (! is_subclass_of($params['wrapperClass'], $wrapperClass)) {
throw DBALException::invalidWrapperClass($params['wrapperClass']);
}
$wrapperClass = $params['wrapperClass'];
}
return new $wrapperClass($params, $driver, $config, $eventManager);
......@@ -191,7 +187,7 @@ final class DriverManager
*
* @return array
*/
public static function getAvailableDrivers(): array
public static function getAvailableDrivers() : array
{
return array_keys(self::$_driverMap);
}
......@@ -201,16 +197,14 @@ final class DriverManager
*
* @param array $params The list of parameters.
*
* @return void
*
* @throws \Doctrine\DBAL\DBALException
* @throws DBALException
*/
private static function _checkParams(array $params): void
private static function _checkParams(array $params) : void
{
// check existence of mandatory parameters
// driver
if ( ! isset($params['driver']) && ! isset($params['driverClass'])) {
if (! isset($params['driver']) && ! isset($params['driverClass'])) {
throw DBALException::driverRequired();
}
......@@ -229,11 +223,9 @@ final class DriverManager
/**
* Normalizes the given connection URL path.
*
* @param string $urlPath
*
* @return string The normalized connection URL path
*/
private static function normalizeDatabaseUrlPath(string $urlPath): string
private static function normalizeDatabaseUrlPath(string $urlPath) : string
{
// Trim leading slash from URL path.
return substr($urlPath, 1);
......@@ -250,9 +242,9 @@ final class DriverManager
*
* @throws DBALException
*/
private static function parseDatabaseUrl(array $params): array
private static function parseDatabaseUrl(array $params) : array
{
if (!isset($params['url'])) {
if (! isset($params['url'])) {
return $params;
}
......@@ -297,14 +289,14 @@ final class DriverManager
* Assumes that the connection URL scheme is already parsed and resolved into the given connection parameters
* via {@link parseDatabaseUrlScheme}.
*
* @see parseDatabaseUrlScheme
*
* @param array $url The URL parts to evaluate.
* @param array $params The connection parameters to resolve.
*
* @return array The resolved connection parameters.
*
* @see parseDatabaseUrlScheme
*/
private static function parseDatabaseUrlPath(array $url, array $params): array
private static function parseDatabaseUrlPath(array $url, array $params) : array
{
if (! isset($url['path'])) {
return $params;
......@@ -333,7 +325,7 @@ final class DriverManager
*
* @return array The resolved connection parameters.
*/
private static function parseDatabaseUrlQuery(array $url, array $params): array
private static function parseDatabaseUrlQuery(array $url, array $params) : array
{
if (! isset($url['query'])) {
return $params;
......@@ -351,14 +343,14 @@ final class DriverManager
*
* Assumes that the "path" URL part is already normalized via {@link normalizeDatabaseUrlPath}.
*
* @see normalizeDatabaseUrlPath
*
* @param array $url The regular connection URL parts to evaluate.
* @param array $params The connection parameters to resolve.
*
* @return array The resolved connection parameters.
*
* @see normalizeDatabaseUrlPath
*/
private static function parseRegularDatabaseUrlPath(array $url, array $params): array
private static function parseRegularDatabaseUrlPath(array $url, array $params) : array
{
$params['dbname'] = $url['path'];
......@@ -370,14 +362,14 @@ final class DriverManager
*
* Assumes that the "path" URL part is already normalized via {@link normalizeDatabaseUrlPath}.
*
* @see normalizeDatabaseUrlPath
*
* @param array $url The SQLite connection URL parts to evaluate.
* @param array $params The connection parameters to resolve.
*
* @return array The resolved connection parameters.
*
* @see normalizeDatabaseUrlPath
*/
private static function parseSqliteDatabaseUrlPath(array $url, array $params): array
private static function parseSqliteDatabaseUrlPath(array $url, array $params) : array
{
if ($url['path'] === ':memory:') {
$params['memory'] = true;
......@@ -400,7 +392,7 @@ final class DriverManager
*
* @throws DBALException if parsing failed or resolution is not possible.
*/
private static function parseDatabaseUrlScheme(array $url, array $params): array
private static function parseDatabaseUrlScheme(array $url, array $params) : array
{
if (isset($url['scheme'])) {
// The requested driver from the URL scheme takes precedence
......
......@@ -4,31 +4,27 @@ namespace Doctrine\DBAL\Event;
use Doctrine\Common\EventArgs;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
/**
* Event Arguments used when a Driver connection is established inside Doctrine\DBAL\Connection.
*
* @link www.doctrine-project.org
* @since 1.0
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class ConnectionEventArgs extends EventArgs
{
/**
* @var \Doctrine\DBAL\Connection
*/
/** @var Connection */
private $_connection;
/**
* @param \Doctrine\DBAL\Connection $connection
*/
public function __construct(Connection $connection)
{
$this->_connection = $connection;
}
/**
* @return \Doctrine\DBAL\Connection
* @return Connection
*/
public function getConnection()
{
......@@ -36,7 +32,7 @@ class ConnectionEventArgs extends EventArgs
}
/**
* @return \Doctrine\DBAL\Driver
* @return Driver
*/
public function getDriver()
{
......@@ -44,7 +40,7 @@ class ConnectionEventArgs extends EventArgs
}
/**
* @return \Doctrine\DBAL\Platforms\AbstractPlatform
* @return AbstractPlatform
*/
public function getDatabasePlatform()
{
......@@ -52,7 +48,7 @@ class ConnectionEventArgs extends EventArgs
}
/**
* @return \Doctrine\DBAL\Schema\AbstractSchemaManager
* @return AbstractSchemaManager
*/
public function getSchemaManager()
{
......
......@@ -2,17 +2,16 @@
namespace Doctrine\DBAL\Event\Listeners;
use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events;
use Doctrine\Common\EventSubscriber;
/**
* MySQL Session Init Event Subscriber which allows to set the Client Encoding of the Connection.
*
* @link www.doctrine-project.org
* @since 1.0
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @deprecated Use "charset" option to PDO MySQL Connection instead.
*
* @link www.doctrine-project.org
*/
class MysqlSessionInit implements EventSubscriber
{
......@@ -26,7 +25,7 @@ class MysqlSessionInit implements EventSubscriber
/**
* The collation, or FALSE if no collation.
*
* @var string|boolean
* @var string|bool
*/
private $_collation;
......@@ -34,7 +33,7 @@ class MysqlSessionInit implements EventSubscriber
* Configure Charset and Collation options of MySQL Client for each Connection.
*
* @param string $charset The charset.
* @param string|boolean $collation The collation, or FALSE if no collation.
* @param string|bool $collation The collation, or FALSE if no collation.
*/
public function __construct($charset = 'utf8', $collation = false)
{
......@@ -43,14 +42,12 @@ class MysqlSessionInit implements EventSubscriber
}
/**
* @param \Doctrine\DBAL\Event\ConnectionEventArgs $args
*
* @return void
*/
public function postConnect(ConnectionEventArgs $args)
{
$collation = ($this->_collation) ? " COLLATE ".$this->_collation : "";
$args->getConnection()->executeUpdate("SET NAMES ".$this->_charset . $collation);
$collation = $this->_collation ? ' COLLATE ' . $this->_collation : '';
$args->getConnection()->executeUpdate('SET NAMES ' . $this->_charset . $collation);
}
/**
......
......@@ -2,9 +2,10 @@
namespace Doctrine\DBAL\Event\Listeners;
use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events;
use Doctrine\Common\EventSubscriber;
use const CASE_UPPER;
use function array_change_key_case;
use function array_merge;
use function count;
......@@ -21,20 +22,16 @@ use function implode;
* NLS_TIMESTAMP_TZ_FORMAT="YYYY-MM-DD HH24:MI:SS TZH:TZM"
*
* @link www.doctrine-project.org
* @since 2.0
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class OracleSessionInit implements EventSubscriber
{
/**
* @var array
*/
/** @var array */
protected $_defaultSessionVars = [
'NLS_TIME_FORMAT' => "HH24:MI:SS",
'NLS_DATE_FORMAT' => "YYYY-MM-DD HH24:MI:SS",
'NLS_TIMESTAMP_FORMAT' => "YYYY-MM-DD HH24:MI:SS",
'NLS_TIMESTAMP_TZ_FORMAT' => "YYYY-MM-DD HH24:MI:SS TZH:TZM",
'NLS_NUMERIC_CHARACTERS' => ".,",
'NLS_TIME_FORMAT' => 'HH24:MI:SS',
'NLS_DATE_FORMAT' => 'YYYY-MM-DD HH24:MI:SS',
'NLS_TIMESTAMP_FORMAT' => 'YYYY-MM-DD HH24:MI:SS',
'NLS_TIMESTAMP_TZ_FORMAT' => 'YYYY-MM-DD HH24:MI:SS TZH:TZM',
'NLS_NUMERIC_CHARACTERS' => '.,',
];
/**
......@@ -46,26 +43,26 @@ class OracleSessionInit implements EventSubscriber
}
/**
* @param \Doctrine\DBAL\Event\ConnectionEventArgs $args
*
* @return void
*/
public function postConnect(ConnectionEventArgs $args)
{
if (count($this->_defaultSessionVars)) {
array_change_key_case($this->_defaultSessionVars, \CASE_UPPER);
if (! count($this->_defaultSessionVars)) {
return;
}
array_change_key_case($this->_defaultSessionVars, CASE_UPPER);
$vars = [];
foreach ($this->_defaultSessionVars as $option => $value) {
if ($option === 'CURRENT_SCHEMA') {
$vars[] = $option . " = " . $value;
$vars[] = $option . ' = ' . $value;
} else {
$vars[] = $option . " = '" . $value . "'";
}
}
$sql = "ALTER SESSION SET ".implode(" ", $vars);
$sql = 'ALTER SESSION SET ' . implode(' ', $vars);
$args->getConnection()->executeUpdate($sql);
}
}
/**
* {@inheritdoc}
......
......@@ -2,22 +2,18 @@
namespace Doctrine\DBAL\Event\Listeners;
use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events;
use Doctrine\Common\EventSubscriber;
/**
* Session init listener for executing a single SQL statement right after a connection is opened.
*
* @link www.doctrine-project.org
* @since 2.2
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class SQLSessionInit implements EventSubscriber
{
/**
* @var string
*/
/** @var string */
protected $sql;
/**
......@@ -29,8 +25,6 @@ class SQLSessionInit implements EventSubscriber
}
/**
* @param \Doctrine\DBAL\Event\ConnectionEventArgs $args
*
* @return void
*/
public function postConnect(ConnectionEventArgs $args)
......
......@@ -12,36 +12,21 @@ use function is_array;
* Event Arguments used when SQL queries for adding table columns are generated inside Doctrine\DBAL\Platform\*Platform.
*
* @link www.doctrine-project.org
* @since 2.2
* @author Jan Sorgalla <jsorgalla@googlemail.com>
*/
class SchemaAlterTableAddColumnEventArgs extends SchemaEventArgs
{
/**
* @var \Doctrine\DBAL\Schema\Column
*/
/** @var Column */
private $_column;
/**
* @var \Doctrine\DBAL\Schema\TableDiff
*/
/** @var TableDiff */
private $_tableDiff;
/**
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/
/** @var AbstractPlatform */
private $_platform;
/**
* @var array
*/
/** @var array */
private $_sql = [];
/**
* @param \Doctrine\DBAL\Schema\Column $column
* @param \Doctrine\DBAL\Schema\TableDiff $tableDiff
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
*/
public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatform $platform)
{
$this->_column = $column;
......@@ -50,7 +35,7 @@ class SchemaAlterTableAddColumnEventArgs extends SchemaEventArgs
}
/**
* @return \Doctrine\DBAL\Schema\Column
* @return Column
*/
public function getColumn()
{
......@@ -58,7 +43,7 @@ class SchemaAlterTableAddColumnEventArgs extends SchemaEventArgs
}
/**
* @return \Doctrine\DBAL\Schema\TableDiff
* @return TableDiff
*/
public function getTableDiff()
{
......@@ -66,7 +51,7 @@ class SchemaAlterTableAddColumnEventArgs extends SchemaEventArgs
}
/**
* @return \Doctrine\DBAL\Platforms\AbstractPlatform
* @return AbstractPlatform
*/
public function getPlatform()
{
......
......@@ -12,36 +12,21 @@ use function is_array;
* Event Arguments used when SQL queries for changing table columns are generated inside Doctrine\DBAL\Platform\*Platform.
*
* @link www.doctrine-project.org
* @since 2.2
* @author Jan Sorgalla <jsorgalla@googlemail.com>
*/
class SchemaAlterTableChangeColumnEventArgs extends SchemaEventArgs
{
/**
* @var \Doctrine\DBAL\Schema\ColumnDiff
*/
/** @var ColumnDiff */
private $_columnDiff;
/**
* @var \Doctrine\DBAL\Schema\TableDiff
*/
/** @var TableDiff */
private $_tableDiff;
/**
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/
/** @var AbstractPlatform */
private $_platform;
/**
* @var array
*/
/** @var array */
private $_sql = [];
/**
* @param \Doctrine\DBAL\Schema\ColumnDiff $columnDiff
* @param \Doctrine\DBAL\Schema\TableDiff $tableDiff
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
*/
public function __construct(ColumnDiff $columnDiff, TableDiff $tableDiff, AbstractPlatform $platform)
{
$this->_columnDiff = $columnDiff;
......@@ -50,7 +35,7 @@ class SchemaAlterTableChangeColumnEventArgs extends SchemaEventArgs
}
/**
* @return \Doctrine\DBAL\Schema\ColumnDiff
* @return ColumnDiff
*/
public function getColumnDiff()
{
......@@ -58,7 +43,7 @@ class SchemaAlterTableChangeColumnEventArgs extends SchemaEventArgs
}
/**
* @return \Doctrine\DBAL\Schema\TableDiff
* @return TableDiff
*/
public function getTableDiff()
{
......@@ -66,7 +51,7 @@ class SchemaAlterTableChangeColumnEventArgs extends SchemaEventArgs
}
/**
* @return \Doctrine\DBAL\Platforms\AbstractPlatform
* @return AbstractPlatform
*/
public function getPlatform()
{
......
......@@ -11,30 +11,18 @@ use function is_array;
* Event Arguments used when SQL queries for creating tables are generated inside Doctrine\DBAL\Platform\*Platform.
*
* @link www.doctrine-project.org
* @since 2.2
* @author Jan Sorgalla <jsorgalla@googlemail.com>
*/
class SchemaAlterTableEventArgs extends SchemaEventArgs
{
/**
* @var \Doctrine\DBAL\Schema\TableDiff
*/
/** @var TableDiff */
private $_tableDiff;
/**
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/
/** @var AbstractPlatform */
private $_platform;
/**
* @var array
*/
/** @var array */
private $_sql = [];
/**
* @param \Doctrine\DBAL\Schema\TableDiff $tableDiff
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
*/
public function __construct(TableDiff $tableDiff, AbstractPlatform $platform)
{
$this->_tableDiff = $tableDiff;
......@@ -42,7 +30,7 @@ class SchemaAlterTableEventArgs extends SchemaEventArgs
}
/**
* @return \Doctrine\DBAL\Schema\TableDiff
* @return TableDiff
*/
public function getTableDiff()
{
......@@ -50,7 +38,7 @@ class SchemaAlterTableEventArgs extends SchemaEventArgs
}
/**
* @return \Doctrine\DBAL\Platforms\AbstractPlatform
* @return AbstractPlatform
*/
public function getPlatform()
{
......
......@@ -12,36 +12,21 @@ use function is_array;
* Event Arguments used when SQL queries for removing table columns are generated inside Doctrine\DBAL\Platform\*Platform.
*
* @link www.doctrine-project.org
* @since 2.2
* @author Jan Sorgalla <jsorgalla@googlemail.com>
*/
class SchemaAlterTableRemoveColumnEventArgs extends SchemaEventArgs
{
/**
* @var \Doctrine\DBAL\Schema\Column
*/
/** @var Column */
private $_column;
/**
* @var \Doctrine\DBAL\Schema\TableDiff
*/
/** @var TableDiff */
private $_tableDiff;
/**
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/
/** @var AbstractPlatform */
private $_platform;
/**
* @var array
*/
/** @var array */
private $_sql = [];
/**
* @param \Doctrine\DBAL\Schema\Column $column
* @param \Doctrine\DBAL\Schema\TableDiff $tableDiff
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
*/
public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatform $platform)
{
$this->_column = $column;
......@@ -50,7 +35,7 @@ class SchemaAlterTableRemoveColumnEventArgs extends SchemaEventArgs
}
/**
* @return \Doctrine\DBAL\Schema\Column
* @return Column
*/
public function getColumn()
{
......@@ -58,7 +43,7 @@ class SchemaAlterTableRemoveColumnEventArgs extends SchemaEventArgs
}
/**
* @return \Doctrine\DBAL\Schema\TableDiff
* @return TableDiff
*/
public function getTableDiff()
{
......@@ -66,7 +51,7 @@ class SchemaAlterTableRemoveColumnEventArgs extends SchemaEventArgs
}
/**
* @return \Doctrine\DBAL\Platforms\AbstractPlatform
* @return AbstractPlatform
*/
public function getPlatform()
{
......
......@@ -12,41 +12,26 @@ use function is_array;
* Event Arguments used when SQL queries for renaming table columns are generated inside Doctrine\DBAL\Platform\*Platform.
*
* @link www.doctrine-project.org
* @since 2.2
* @author Jan Sorgalla <jsorgalla@googlemail.com>
*/
class SchemaAlterTableRenameColumnEventArgs extends SchemaEventArgs
{
/**
* @var string
*/
/** @var string */
private $_oldColumnName;
/**
* @var \Doctrine\DBAL\Schema\Column
*/
/** @var Column */
private $_column;
/**
* @var \Doctrine\DBAL\Schema\TableDiff
*/
/** @var TableDiff */
private $_tableDiff;
/**
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/
/** @var AbstractPlatform */
private $_platform;
/**
* @var array
*/
/** @var array */
private $_sql = [];
/**
* @param string $oldColumnName
* @param \Doctrine\DBAL\Schema\Column $column
* @param \Doctrine\DBAL\Schema\TableDiff $tableDiff
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
*/
public function __construct($oldColumnName, Column $column, TableDiff $tableDiff, AbstractPlatform $platform)
{
......@@ -65,7 +50,7 @@ class SchemaAlterTableRenameColumnEventArgs extends SchemaEventArgs
}
/**
* @return \Doctrine\DBAL\Schema\Column
* @return Column
*/
public function getColumn()
{
......@@ -73,7 +58,7 @@ class SchemaAlterTableRenameColumnEventArgs extends SchemaEventArgs
}
/**
* @return \Doctrine\DBAL\Schema\TableDiff
* @return TableDiff
*/
public function getTableDiff()
{
......@@ -81,7 +66,7 @@ class SchemaAlterTableRenameColumnEventArgs extends SchemaEventArgs
}
/**
* @return \Doctrine\DBAL\Platforms\AbstractPlatform
* @return AbstractPlatform
*/
public function getPlatform()
{
......
......@@ -3,20 +3,17 @@
namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Column;
/**
* Event Arguments used when the portable column definition is generated inside Doctrine\DBAL\Schema\AbstractSchemaManager.
*
* @link www.doctrine-project.org
* @since 2.2
* @author Jan Sorgalla <jsorgalla@googlemail.com>
*/
class SchemaColumnDefinitionEventArgs extends SchemaEventArgs
{
/**
* @var \Doctrine\DBAL\Schema\Column|null
*/
/** @var Column|null */
private $_column = null;
/**
......@@ -26,26 +23,19 @@ class SchemaColumnDefinitionEventArgs extends SchemaEventArgs
*/
private $_tableColumn;
/**
* @var string
*/
/** @var string */
private $_table;
/**
* @var string
*/
/** @var string */
private $_database;
/**
* @var \Doctrine\DBAL\Connection
*/
/** @var Connection */
private $_connection;
/**
* @param array $tableColumn
* @param string $table
* @param string $database
* @param \Doctrine\DBAL\Connection $connection
*/
public function __construct(array $tableColumn, $table, $database, Connection $connection)
{
......@@ -59,11 +49,9 @@ class SchemaColumnDefinitionEventArgs extends SchemaEventArgs
* Allows to clear the column which means the column will be excluded from
* tables column list.
*
* @param null|\Doctrine\DBAL\Schema\Column $column
*
* @return \Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs
*/
public function setColumn(Column $column = null)
public function setColumn(?Column $column = null)
{
$this->_column = $column;
......@@ -71,7 +59,7 @@ class SchemaColumnDefinitionEventArgs extends SchemaEventArgs
}
/**
* @return \Doctrine\DBAL\Schema\Column|null
* @return Column|null
*/
public function getColumn()
{
......@@ -103,7 +91,7 @@ class SchemaColumnDefinitionEventArgs extends SchemaEventArgs
}
/**
* @return \Doctrine\DBAL\Connection
* @return Connection
*/
public function getConnection()
{
......@@ -111,7 +99,7 @@ class SchemaColumnDefinitionEventArgs extends SchemaEventArgs
}
/**
* @return \Doctrine\DBAL\Platforms\AbstractPlatform
* @return AbstractPlatform
*/
public function getDatabasePlatform()
{
......
......@@ -8,14 +8,10 @@ use Doctrine\Common\EventArgs;
* Base class for schema related events.
*
* @link www.doctrine-project.org
* @since 2.2
* @author Jan Sorgalla <jsorgalla@googlemail.com>
*/
class SchemaEventArgs extends EventArgs
{
/**
* @var bool
*/
/** @var bool */
private $_preventDefault = false;
/**
......
This diff is collapsed.
......@@ -5,9 +5,7 @@ namespace Doctrine\DBAL\Exception;
/**
* Base class for all connection related errors detected in the driver.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
class ConnectionException extends DriverException
{
......
......@@ -5,9 +5,7 @@ namespace Doctrine\DBAL\Exception;
/**
* Base class for all constraint violation related errors detected in the driver.
*
* @author Steve Müller <st.mueller@dzh-online.de>
* @link www.doctrine-project.org
* @since 2.5
*/
class ConstraintViolationException extends ServerException
{
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment