From a299c622c35dc1b8149d3ad9e12cd9f4f1a0a498 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 11 Jul 2017 12:28:13 +0200 Subject: [PATCH] coding style: TRUE/FALSE/NULL -> true/false/null --- examples/connecting-to-databases.php | 2 +- examples/data/sample.s3db | Bin 4096 -> 4096 bytes examples/query-language-and-conditions.php | 6 +- examples/query-language-basic-examples.php | 4 +- examples/tracy-and-exceptions.php | 2 +- examples/tracy.php | 2 +- examples/using-fluent-syntax.php | 2 +- examples/using-logger.php | 2 +- examples/using-profiler.php | 2 +- readme.md | 2 +- src/Dibi/Bridges/Nette/DibiExtension22.php | 10 +-- src/Dibi/Bridges/Nette/config.sample.neon | 2 +- src/Dibi/Bridges/Tracy/Panel.php | 18 ++-- src/Dibi/Connection.php | 48 +++++----- src/Dibi/DataSource.php | 34 +++---- src/Dibi/DateTime.php | 4 +- src/Dibi/Drivers/FirebirdDriver.php | 80 ++++++++--------- src/Dibi/Drivers/MsSqlDriver.php | 38 ++++---- src/Dibi/Drivers/MsSqlReflector.php | 28 +++--- src/Dibi/Drivers/MySqlReflector.php | 12 +-- src/Dibi/Drivers/MySqliDriver.php | 46 +++++----- src/Dibi/Drivers/OdbcDriver.php | 48 +++++----- src/Dibi/Drivers/OracleDriver.php | 66 +++++++------- src/Dibi/Drivers/PdoDriver.php | 46 +++++----- src/Dibi/Drivers/PostgreDriver.php | 68 +++++++------- src/Dibi/Drivers/Sqlite3Driver.php | 50 +++++------ src/Dibi/Drivers/SqliteReflector.php | 22 ++--- src/Dibi/Drivers/SqlsrvDriver.php | 40 ++++----- src/Dibi/Drivers/SqlsrvReflector.php | 12 +-- src/Dibi/Event.php | 16 ++-- src/Dibi/Fluent.php | 60 ++++++------- src/Dibi/Helpers.php | 20 ++--- src/Dibi/Loggers/FileLogger.php | 2 +- src/Dibi/Loggers/FirePhpLogger.php | 2 +- src/Dibi/Reflection/Column.php | 28 +++--- src/Dibi/Reflection/Database.php | 2 +- src/Dibi/Reflection/Result.php | 6 +- src/Dibi/Reflection/Table.php | 4 +- src/Dibi/Result.php | 78 ++++++++-------- src/Dibi/Row.php | 8 +- src/Dibi/Strict.php | 12 +-- src/Dibi/Translator.php | 62 ++++++------- src/Dibi/dibi.php | 24 ++--- src/Dibi/exceptions.php | 6 +- src/Dibi/interfaces.php | 10 +-- tests/dibi/Connection.connect.phpt | 2 +- tests/dibi/Fluent.delete.phpt | 2 +- tests/dibi/Fluent.fetch.limit.mssql.phpt | 2 +- tests/dibi/Fluent.insert.phpt | 4 +- tests/dibi/Fluent.update.phpt | 2 +- tests/dibi/Helpers.getSuggestion().phpt | 14 +-- tests/dibi/Result.meta.phpt | 2 +- tests/dibi/Result.normalize.phpt | 88 +++++++++---------- tests/dibi/Translator.DateTimeInterface.phpt | 4 +- tests/dibi/Translator.conditions.phpt | 12 +-- tests/dibi/Translator.phpt | 22 ++--- tests/dibi/bootstrap.php | 2 +- tests/dibi/exceptions.sqlite.phpt | 6 +- 58 files changed, 599 insertions(+), 599 deletions(-) diff --git a/examples/connecting-to-databases.php b/examples/connecting-to-databases.php index 945809e3..d7ab1c0d 100644 --- a/examples/connecting-to-databases.php +++ b/examples/connecting-to-databases.php @@ -89,7 +89,7 @@ try { dibi::connect([ 'driver' => 'postgre', 'string' => 'host=localhost port=5432 dbname=mary', - 'persistent' => TRUE, + 'persistent' => true, ]); echo 'OK'; } catch (Dibi\Exception $e) { diff --git a/examples/data/sample.s3db b/examples/data/sample.s3db index db8a54dd55a6352aeec23c5d006cacd359c8b057..5729d48c2ff6b18ca3b8443bda0c8831c71d93ce 100644 GIT binary patch delta 108 zcmZorXi(UY$HbCXnv*lRh)ET~n9URbVZ3M3f-q#6Wg!eZW^o83k~u>Gq)UgFD>^SR iH#Jrv%rVH>!!bz1(7-@b0W3H9A+rQn_2$3K%sc>$86wgE delta 108 zcmZorXi(UY$Hd|n>fGq)UgFD>^SR iH#Jrv%rVH>!!bz1(7-@b0W3H9A+rQn_2$3K%sc>v${tbx diff --git a/examples/query-language-and-conditions.php b/examples/query-language-and-conditions.php index 16ddd8cc..63b5c69e 100644 --- a/examples/query-language-and-conditions.php +++ b/examples/query-language-and-conditions.php @@ -14,13 +14,13 @@ dibi::connect([ // some variables -$cond1 = TRUE; -$cond2 = FALSE; +$cond1 = true; +$cond2 = false; $foo = -1; $bar = 2; // conditional variable -$name = $cond1 ? 'K%' : NULL; +$name = $cond1 ? 'K%' : null; // if & end dibi::test(' diff --git a/examples/query-language-basic-examples.php b/examples/query-language-basic-examples.php index 6db4a1b2..c6167ad9 100644 --- a/examples/query-language-basic-examples.php +++ b/examples/query-language-basic-examples.php @@ -33,7 +33,7 @@ dibi::test(' REPLACE INTO products', [ 'title' => 'Super product', 'price' => 318, - 'active' => TRUE, + 'active' => true, ]); // -> REPLACE INTO products ([title], [price], [active]) VALUES ('Super product', 318, 1) @@ -42,7 +42,7 @@ dibi::test(' $array = [ 'title' => 'Super Product', 'price' => 12, - 'brand' => NULL, + 'brand' => null, 'created' => new DateTime, ]; dibi::test('INSERT INTO products', $array, $array, $array); diff --git a/examples/tracy-and-exceptions.php b/examples/tracy-and-exceptions.php index ba8984a6..ee9a00bf 100644 --- a/examples/tracy-and-exceptions.php +++ b/examples/tracy-and-exceptions.php @@ -14,7 +14,7 @@ $connection = dibi::connect([ 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', 'profiler' => [ - 'run' => TRUE, + 'run' => true, ], ]); diff --git a/examples/tracy.php b/examples/tracy.php index 36270c64..b1a819af 100644 --- a/examples/tracy.php +++ b/examples/tracy.php @@ -14,7 +14,7 @@ $connection = dibi::connect([ 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', 'profiler' => [ - 'run' => TRUE, + 'run' => true, ], ]); diff --git a/examples/using-fluent-syntax.php b/examples/using-fluent-syntax.php index b78d44eb..ab550888 100644 --- a/examples/using-fluent-syntax.php +++ b/examples/using-fluent-syntax.php @@ -19,7 +19,7 @@ $id = 10; $record = [ 'title' => 'Super product', 'price' => 318, - 'active' => TRUE, + 'active' => true, ]; // SELECT ... diff --git a/examples/using-logger.php b/examples/using-logger.php index a935eecd..1e794734 100644 --- a/examples/using-logger.php +++ b/examples/using-logger.php @@ -14,7 +14,7 @@ dibi::connect([ 'database' => 'data/sample.s3db', // enable query logging to this file 'profiler' => [ - 'run' => TRUE, + 'run' => true, 'file' => 'data/log.sql', ], ]); diff --git a/examples/using-profiler.php b/examples/using-profiler.php index 2aa6b58d..91b4ba07 100644 --- a/examples/using-profiler.php +++ b/examples/using-profiler.php @@ -13,7 +13,7 @@ dibi::connect([ 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', 'profiler' => [ - 'run' => TRUE, + 'run' => true, ], ]); diff --git a/readme.md b/readme.md index ac9039d9..aeef67ea 100644 --- a/readme.md +++ b/readme.md @@ -50,7 +50,7 @@ dibi::query('SELECT * FROM users WHERE id = ?', $id); $arr = [ 'name' => 'John', - 'is_admin' => TRUE, + 'is_admin' => true, ]; dibi::query('INSERT INTO users', $arr); // INSERT INTO users (`name`, `is_admin`) VALUES ('John', 1) diff --git a/src/Dibi/Bridges/Nette/DibiExtension22.php b/src/Dibi/Bridges/Nette/DibiExtension22.php index 1da095c0..a26203f1 100644 --- a/src/Dibi/Bridges/Nette/DibiExtension22.php +++ b/src/Dibi/Bridges/Nette/DibiExtension22.php @@ -23,7 +23,7 @@ class DibiExtension22 extends Nette\DI\CompilerExtension private $debugMode; - public function __construct($debugMode = NULL) + public function __construct($debugMode = null) { $this->debugMode = $debugMode; } @@ -34,7 +34,7 @@ class DibiExtension22 extends Nette\DI\CompilerExtension $container = $this->getContainerBuilder(); $config = $this->getConfig(); - if ($this->debugMode === NULL) { + if ($this->debugMode === null) { $this->debugMode = $container->parameters['debugMode']; } @@ -52,7 +52,7 @@ class DibiExtension22 extends Nette\DI\CompilerExtension $connection = $container->addDefinition($this->prefix('connection')) ->setClass(Dibi\Connection::class, [$config]) - ->setAutowired($config['autowired'] ?? TRUE); + ->setAutowired($config['autowired'] ?? true); if (class_exists(Tracy\Debugger::class)) { $connection->addSetup( @@ -63,8 +63,8 @@ class DibiExtension22 extends Nette\DI\CompilerExtension if ($useProfiler) { $panel = $container->addDefinition($this->prefix('panel')) ->setClass(Dibi\Bridges\Tracy\Panel::class, [ - $config['explain'] ?? TRUE, - isset($config['filter']) && $config['filter'] === FALSE ? Dibi\Event::ALL : Dibi\Event::QUERY, + $config['explain'] ?? true, + isset($config['filter']) && $config['filter'] === false ? Dibi\Event::ALL : Dibi\Event::QUERY, ]); $connection->addSetup([$panel, 'register'], [$connection]); } diff --git a/src/Dibi/Bridges/Nette/config.sample.neon b/src/Dibi/Bridges/Nette/config.sample.neon index f336b711..92ce2555 100644 --- a/src/Dibi/Bridges/Nette/config.sample.neon +++ b/src/Dibi/Bridges/Nette/config.sample.neon @@ -9,4 +9,4 @@ dibi: username: root password: *** database: foo - lazy: TRUE + lazy: true diff --git a/src/Dibi/Bridges/Tracy/Panel.php b/src/Dibi/Bridges/Tracy/Panel.php index 760c6d45..4403d5a7 100644 --- a/src/Dibi/Bridges/Tracy/Panel.php +++ b/src/Dibi/Bridges/Tracy/Panel.php @@ -35,7 +35,7 @@ class Panel implements Tracy\IBarPanel private $events = []; - public function __construct(bool $explain = TRUE, int $filter = NULL) + public function __construct(bool $explain = true, int $filter = null) { $this->filter = $filter ?: Event::QUERY; $this->explain = $explain; @@ -70,7 +70,7 @@ class Panel implements Tracy\IBarPanel if ($e instanceof Dibi\Exception && $e->getSql()) { return [ 'tab' => 'SQL', - 'panel' => Helpers::dump($e->getSql(), TRUE), + 'panel' => Helpers::dump($e->getSql(), true), ]; } } @@ -99,20 +99,20 @@ class Panel implements Tracy\IBarPanel public function getPanel(): ?string { if (!$this->events) { - return NULL; + return null; } - $totalTime = $s = NULL; + $totalTime = $s = null; foreach ($this->events as $event) { $totalTime += $event->time; $connection = $event->connection; - $explain = NULL; // EXPLAIN is called here to work SELECT FOUND_ROWS() + $explain = null; // EXPLAIN is called here to work SELECT FOUND_ROWS() if ($this->explain && $event->type === Event::SELECT) { try { $backup = [$connection->onEvent, \dibi::$numOfQueries, \dibi::$totalTime]; - $connection->onEvent = NULL; + $connection->onEvent = null; $cmd = is_string($this->explain) ? $this->explain : ($connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN FOR' : 'EXPLAIN'); - $explain = @Helpers::dump($connection->nativeQuery("$cmd $event->sql"), TRUE); + $explain = @Helpers::dump($connection->nativeQuery("$cmd $event->sql"), true); } catch (Dibi\Exception $e) { } [$connection->onEvent, \dibi::$numOfQueries, \dibi::$totalTime] = $backup; @@ -125,7 +125,7 @@ class Panel implements Tracy\IBarPanel $s .= "
explain"; } - $s .= '' . Helpers::dump(strlen($event->sql) > self::$maxLength ? substr($event->sql, 0, self::$maxLength) . '...' : $event->sql, TRUE); + $s .= '' . Helpers::dump(strlen($event->sql) > self::$maxLength ? substr($event->sql, 0, self::$maxLength) . '...' : $event->sql, true); if ($explain) { $s .= "
{$explain}
"; } @@ -140,7 +140,7 @@ class Panel implements Tracy\IBarPanel #tracy-debug .tracy-DibiProfiler-source { color: #999 !important } #tracy-debug tracy-DibiProfiler tr table { margin: 8px 0; max-height: 150px; overflow:auto }

Queries: ' . count($this->events) - . ($totalTime === NULL ? '' : ', time: ' . number_format($totalTime * 1000, 1, '.', ' ') . ' ms') . ', ' + . ($totalTime === null ? '' : ', time: ' . number_format($totalTime * 1000, 1, '.', ' ') . ' ms') . ', ' . htmlSpecialChars($connection->getConfig('driver') . ($connection->getConfig('name') ? '/' . $connection->getConfig('name') : '') . ($connection->getConfig('host') ? ' @ ' . $connection->getConfig('host') : '')) . '

diff --git a/src/Dibi/Connection.php b/src/Dibi/Connection.php index f22ed123..ad825230 100644 --- a/src/Dibi/Connection.php +++ b/src/Dibi/Connection.php @@ -35,7 +35,7 @@ class Connection private $translator; /** @var bool Is connected? */ - private $connected = FALSE; + private $connected = false; /** @var HashMap Substitutes for identifiers */ private $substitutes; @@ -43,7 +43,7 @@ class Connection /** * Connection options: (see driver-specific options too) - * - lazy (bool) => if TRUE, connection will be established only when required + * - lazy (bool) => if true, connection will be established only when required * - result (array) => result set options * - formatDateTime => date-time format (if empty, DateTime objects will be returned) * - profiler (array or bool) @@ -54,7 +54,7 @@ class Connection * @param string connection name * @throws Exception */ - public function __construct($config, string $name = NULL) + public function __construct($config, string $name = null) { if (is_string($config)) { parse_str($config, $config); @@ -142,10 +142,10 @@ class Connection */ final public function connect(): void { - $event = $this->onEvent ? new Event($this, Event::CONNECT) : NULL; + $event = $this->onEvent ? new Event($this, Event::CONNECT) : null; try { $this->driver->connect($this->config); - $this->connected = TRUE; + $this->connected = true; $event && $this->onEvent($event->done()); } catch (Exception $e) { @@ -161,12 +161,12 @@ class Connection final public function disconnect(): void { $this->driver->disconnect(); - $this->connected = FALSE; + $this->connected = false; } /** - * Returns TRUE when connection was established. + * Returns true when connection was established. */ final public function isConnected(): bool { @@ -179,9 +179,9 @@ class Connection * @see self::__construct * @return mixed */ - final public function getConfig(string $key = NULL, $default = NULL) + final public function getConfig(string $key = null, $default = null) { - return $key === NULL + return $key === null ? $this->config : ($this->config[$key] ?? $default); } @@ -228,7 +228,7 @@ class Connection { try { Helpers::dump($this->translateArgs($args)); - return TRUE; + return true; } catch (Exception $e) { if ($e->getSql()) { @@ -236,7 +236,7 @@ class Connection } else { echo get_class($e) . ': ' . $e->getMessage() . (PHP_SAPI === 'cli' ? "\n" : '
'); } - return FALSE; + return false; } } @@ -276,7 +276,7 @@ class Connection $this->connected || $this->connect(); \dibi::$sql = $sql; - $event = $this->onEvent ? new Event($this, Event::QUERY, $sql) : NULL; + $event = $this->onEvent ? new Event($this, Event::QUERY, $sql) : null; try { $res = $this->driver->query($sql); @@ -304,7 +304,7 @@ class Connection { $this->connected || $this->connect(); $rows = $this->driver->getAffectedRows(); - if ($rows === NULL || $rows < 0) { + if ($rows === null || $rows < 0) { throw new Exception('Cannot retrieve number of affected rows.'); } return $rows; @@ -325,7 +325,7 @@ class Connection * Retrieves the ID generated for an AUTO_INCREMENT column by the previous INSERT query. * @throws Exception */ - public function getInsertId(string $sequence = NULL): int + public function getInsertId(string $sequence = null): int { $this->connected || $this->connect(); $id = $this->driver->getInsertId($sequence); @@ -340,7 +340,7 @@ class Connection * Retrieves the ID generated for an AUTO_INCREMENT column. Alias for getInsertId(). * @throws Exception */ - public function insertId(string $sequence = NULL): int + public function insertId(string $sequence = null): int { return $this->getInsertId($sequence); } @@ -349,10 +349,10 @@ class Connection /** * Begins a transaction (if supported). */ - public function begin(string $savepoint = NULL): void + public function begin(string $savepoint = null): void { $this->connected || $this->connect(); - $event = $this->onEvent ? new Event($this, Event::BEGIN, $savepoint) : NULL; + $event = $this->onEvent ? new Event($this, Event::BEGIN, $savepoint) : null; try { $this->driver->begin($savepoint); $event && $this->onEvent($event->done()); @@ -367,10 +367,10 @@ class Connection /** * Commits statements in a transaction. */ - public function commit(string $savepoint = NULL): void + public function commit(string $savepoint = null): void { $this->connected || $this->connect(); - $event = $this->onEvent ? new Event($this, Event::COMMIT, $savepoint) : NULL; + $event = $this->onEvent ? new Event($this, Event::COMMIT, $savepoint) : null; try { $this->driver->commit($savepoint); $event && $this->onEvent($event->done()); @@ -385,10 +385,10 @@ class Connection /** * Rollback changes in a transaction. */ - public function rollback(string $savepoint = NULL): void + public function rollback(string $savepoint = null): void { $this->connected || $this->connect(); - $event = $this->onEvent ? new Event($this, Event::ROLLBACK, $savepoint) : NULL; + $event = $this->onEvent ? new Event($this, Event::ROLLBACK, $savepoint) : null; try { $this->driver->rollback($savepoint); $event && $this->onEvent($event->done()); @@ -470,7 +470,7 @@ class Connection */ public function substitute(string $value): string { - return strpos($value, ':') === FALSE + return strpos($value, ':') === false ? $value : preg_replace_callback('#:([^:\s]*):#', function ($m) { return $this->substitutes->{$m[1]}; }, $value); } @@ -540,7 +540,7 @@ class Connection * @param callable $onProgress function (int $count, ?float $percent): void * @return int count of sql commands */ - public function loadFile(string $file, callable $onProgress = NULL): int + public function loadFile(string $file, callable $onProgress = null): int { return Helpers::loadFromFile($this, $file, $onProgress); } @@ -552,7 +552,7 @@ class Connection public function getDatabaseInfo(): Reflection\Database { $this->connected || $this->connect(); - return new Reflection\Database($this->driver->getReflector(), $this->config['database'] ?? NULL); + return new Reflection\Database($this->driver->getReflector(), $this->config['database'] ?? null); } diff --git a/src/Dibi/DataSource.php b/src/Dibi/DataSource.php index 3872d975..30d74677 100644 --- a/src/Dibi/DataSource.php +++ b/src/Dibi/DataSource.php @@ -42,10 +42,10 @@ class DataSource implements IDataSource /** @var array */ private $conds = []; - /** @var int|NULL */ + /** @var int|null */ private $offset; - /** @var int|NULL */ + /** @var int|null */ private $limit; @@ -54,7 +54,7 @@ class DataSource implements IDataSource */ public function __construct(string $sql, Connection $connection) { - if (strpbrk($sql, " \t\r\n") === FALSE) { + if (strpbrk($sql, " \t\r\n") === false) { $this->sql = $connection->getDriver()->escapeIdentifier($sql); // table name } else { $this->sql = '(' . $sql . ') t'; // SQL command @@ -68,14 +68,14 @@ class DataSource implements IDataSource * @param string|array column name or array of column names * @param string column alias */ - public function select($col, string $as = NULL): self + public function select($col, string $as = null): self { if (is_array($col)) { $this->cols = $col; } else { $this->cols[$col] = $as; } - $this->result = NULL; + $this->result = null; return $this; } @@ -91,7 +91,7 @@ class DataSource implements IDataSource } else { $this->conds[] = func_get_args(); } - $this->result = $this->count = NULL; + $this->result = $this->count = null; return $this; } @@ -107,7 +107,7 @@ class DataSource implements IDataSource } else { $this->sorting[$row] = $direction; } - $this->result = NULL; + $this->result = null; return $this; } @@ -115,11 +115,11 @@ class DataSource implements IDataSource /** * Limits number of rows. */ - public function applyLimit(int $limit, int $offset = NULL): self + public function applyLimit(int $limit, int $offset = null): self { $this->limit = $limit; $this->offset = $offset; - $this->result = $this->count = NULL; + $this->result = $this->count = null; return $this; } @@ -141,7 +141,7 @@ class DataSource implements IDataSource */ public function getResult(): Result { - if ($this->result === NULL) { + if ($this->result === null) { $this->result = $this->connection->nativeQuery($this->__toString()); } return $this->result; @@ -166,7 +166,7 @@ class DataSource implements IDataSource /** * Like fetch(), but returns only first field. - * @return mixed value on success, NULL if no next record + * @return mixed value on success, null if no next record */ public function fetchSingle() { @@ -195,7 +195,7 @@ class DataSource implements IDataSource /** * Fetches all records from table like $key => $value pairs. */ - public function fetchPairs(string $key = NULL, string $value = NULL): array + public function fetchPairs(string $key = null, string $value = null): array { return $this->getResult()->fetchPairs($key, $value); } @@ -206,7 +206,7 @@ class DataSource implements IDataSource */ public function release(): void { - $this->result = $this->count = $this->totalCount = NULL; + $this->result = $this->count = $this->totalCount = null; } @@ -240,8 +240,8 @@ class DataSource implements IDataSource return $this->connection->translate(' SELECT %n', (empty($this->cols) ? '*' : $this->cols), ' FROM %SQL', $this->sql, ' -%ex', $this->conds ? ['WHERE %and', $this->conds] : NULL, ' -%ex', $this->sorting ? ['ORDER BY %by', $this->sorting] : NULL, ' +%ex', $this->conds ? ['WHERE %and', $this->conds] : null, ' +%ex', $this->sorting ? ['ORDER BY %by', $this->sorting] : null, ' %ofs %lmt', $this->offset, $this->limit ); } catch (\Throwable $e) { @@ -258,7 +258,7 @@ FROM %SQL', $this->sql, ' */ public function count(): int { - if ($this->count === NULL) { + if ($this->count === null) { $this->count = $this->conds || $this->offset || $this->limit ? (int) $this->connection->nativeQuery( 'SELECT COUNT(*) FROM (' . $this->__toString() . ') t' @@ -274,7 +274,7 @@ FROM %SQL', $this->sql, ' */ public function getTotalCount(): int { - if ($this->totalCount === NULL) { + if ($this->totalCount === null) { $this->totalCount = (int) $this->connection->nativeQuery( 'SELECT COUNT(*) FROM ' . $this->sql )->fetchSingle(); diff --git a/src/Dibi/DateTime.php b/src/Dibi/DateTime.php index e639f8b9..99740e5c 100644 --- a/src/Dibi/DateTime.php +++ b/src/Dibi/DateTime.php @@ -20,12 +20,12 @@ class DateTime extends \DateTime /** * @param string|int */ - public function __construct($time = 'now', \DateTimeZone $timezone = NULL) + public function __construct($time = 'now', \DateTimeZone $timezone = null) { if (is_numeric($time)) { parent::__construct('@' . $time); $this->setTimeZone($timezone ? $timezone : new \DateTimeZone(date_default_timezone_get())); - } elseif ($timezone === NULL) { + } elseif ($timezone === null) { parent::__construct($time); } else { parent::__construct($time, $timezone); diff --git a/src/Dibi/Drivers/FirebirdDriver.php b/src/Dibi/Drivers/FirebirdDriver.php index 19c0c7f2..f96ddf26 100644 --- a/src/Dibi/Drivers/FirebirdDriver.php +++ b/src/Dibi/Drivers/FirebirdDriver.php @@ -31,20 +31,20 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector const ERROR_EXCEPTION_THROWN = -836; - /** @var resource|NULL */ + /** @var resource|null */ private $connection; - /** @var resource|NULL */ + /** @var resource|null */ private $resultSet; /** @var bool */ - private $autoFree = TRUE; + private $autoFree = true; - /** @var resource|NULL */ + /** @var resource|null */ private $transaction; /** @var bool */ - private $inTransaction = FALSE; + private $inTransaction = false; /** @@ -110,7 +110,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector $resource = $this->inTransaction ? $this->transaction : $this->connection; $res = ibase_query($resource, $sql); - if ($res === FALSE) { + if ($res === false) { if (ibase_errcode() == self::ERROR_EXCEPTION_THROWN) { preg_match('/exception (\d+) (\w+) (.*)/i', ibase_errmsg(), $match); throw new Dibi\ProcedureException($match[3], $match[1], $match[2], $sql); @@ -122,7 +122,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector } elseif (is_resource($res)) { return $this->createResultDriver($res); } - return NULL; + return null; } @@ -148,13 +148,13 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector * Begins a transaction (if supported). * @throws Dibi\DriverException */ - public function begin(string $savepoint = NULL): void + public function begin(string $savepoint = null): void { - if ($savepoint !== NULL) { + if ($savepoint !== null) { throw new Dibi\NotSupportedException('Savepoints are not supported in Firebird/Interbase.'); } $this->transaction = ibase_trans($this->getResource()); - $this->inTransaction = TRUE; + $this->inTransaction = true; } @@ -162,9 +162,9 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector * Commits statements in a transaction. * @throws Dibi\DriverException */ - public function commit(string $savepoint = NULL): void + public function commit(string $savepoint = null): void { - if ($savepoint !== NULL) { + if ($savepoint !== null) { throw new Dibi\NotSupportedException('Savepoints are not supported in Firebird/Interbase.'); } @@ -172,7 +172,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector throw new Dibi\DriverException('Unable to handle operation - failure when commiting transaction.'); } - $this->inTransaction = FALSE; + $this->inTransaction = false; } @@ -180,9 +180,9 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector * Rollback changes in a transaction. * @throws Dibi\DriverException */ - public function rollback(string $savepoint = NULL): void + public function rollback(string $savepoint = null): void { - if ($savepoint !== NULL) { + if ($savepoint !== null) { throw new Dibi\NotSupportedException('Savepoints are not supported in Firebird/Interbase.'); } @@ -190,7 +190,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector throw new Dibi\DriverException('Unable to handle operation - failure when rolbacking transaction.'); } - $this->inTransaction = FALSE; + $this->inTransaction = false; } @@ -205,11 +205,11 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector /** * Returns the connection resource. - * @return resource|NULL + * @return resource|null */ public function getResource() { - return is_resource($this->connection) ? $this->connection : NULL; + return is_resource($this->connection) ? $this->connection : null; } @@ -341,7 +341,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector /** * Fetches the row at current position and moves the internal cursor to the next position. - * @param bool TRUE for associative array, FALSE for numeric + * @param bool true for associative array, false for numeric */ public function fetch(bool $assoc): ?array { @@ -377,18 +377,18 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector public function free(): void { ibase_free_result($this->resultSet); - $this->resultSet = NULL; + $this->resultSet = null; } /** * Returns the result set resource. - * @return resource|NULL + * @return resource|null */ public function getResultResource() { - $this->autoFree = FALSE; - return is_resource($this->resultSet) ? $this->resultSet : NULL; + $this->autoFree = false; + return is_resource($this->resultSet) ? $this->resultSet : null; } @@ -427,7 +427,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector WHERE RDB\$SYSTEM_FLAG = 0;" ); $tables = []; - while ($row = $res->fetch(FALSE)) { + while ($row = $res->fetch(false)) { $tables[] = [ 'name' => $row[0], 'view' => $row[1] === 'TRUE', @@ -474,7 +474,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector ); $columns = []; - while ($row = $res->fetch(TRUE)) { + while ($row = $res->fetch(true)) { $key = $row['FIELD_NAME']; $columns[$key] = [ 'name' => $key, @@ -483,7 +483,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector 'size' => $row['FIELD_LENGTH'], 'nullable' => $row['NULLABLE'] === 'TRUE', 'default' => $row['DEFAULT_VALUE'], - 'autoincrement' => FALSE, + 'autoincrement' => false, ]; } return $columns; @@ -510,7 +510,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector ORDER BY s.RDB\$FIELD_POSITION" ); $indexes = []; - while ($row = $res->fetch(TRUE)) { + while ($row = $res->fetch(true)) { $key = $row['INDEX_NAME']; $indexes[$key]['name'] = $key; $indexes[$key]['unique'] = $row['UNIQUE_FLAG'] === 1; @@ -538,7 +538,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector ORDER BY s.RDB\$FIELD_POSITION" ); $keys = []; - while ($row = $res->fetch(TRUE)) { + while ($row = $res->fetch(true)) { $key = $row['INDEX_NAME']; $keys[$key] = [ 'name' => $key, @@ -563,7 +563,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector AND RDB\$FOREIGN_KEY IS NULL;" ); $indices = []; - while ($row = $res->fetch(FALSE)) { + while ($row = $res->fetch(false)) { $indices[] = $row[0]; } return $indices; @@ -585,7 +585,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector );" ); $constraints = []; - while ($row = $res->fetch(FALSE)) { + while ($row = $res->fetch(false)) { $constraints[] = $row[0]; } return $constraints; @@ -596,7 +596,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector * Returns metadata for all triggers in a table or database. * (Only if user has permissions on ALTER TABLE, INSERT/UPDATE/DELETE record in table) */ - public function getTriggersMeta(string $table = NULL): array + public function getTriggersMeta(string $table = null): array { $res = $this->query(" SELECT TRIM(RDB\$TRIGGER_NAME) AS TRIGGER_NAME, @@ -622,10 +622,10 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector END AS TRIGGER_ENABLED FROM RDB\$TRIGGERS WHERE RDB\$SYSTEM_FLAG = 0" - . ($table === NULL ? ';' : " AND RDB\$RELATION_NAME = UPPER('$table');") + . ($table === null ? ';' : " AND RDB\$RELATION_NAME = UPPER('$table');") ); $triggers = []; - while ($row = $res->fetch(TRUE)) { + while ($row = $res->fetch(true)) { $triggers[$row['TRIGGER_NAME']] = [ 'name' => $row['TRIGGER_NAME'], 'table' => $row['TABLE_NAME'], @@ -642,16 +642,16 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector * Returns list of triggers for given table. * (Only if user has permissions on ALTER TABLE, INSERT/UPDATE/DELETE record in table) */ - public function getTriggers(string $table = NULL): array + public function getTriggers(string $table = null): array { $q = "SELECT TRIM(RDB\$TRIGGER_NAME) FROM RDB\$TRIGGERS WHERE RDB\$SYSTEM_FLAG = 0"; - $q .= $table === NULL ? ';' : " AND RDB\$RELATION_NAME = UPPER('$table')"; + $q .= $table === null ? ';' : " AND RDB\$RELATION_NAME = UPPER('$table')"; $res = $this->query($q); $triggers = []; - while ($row = $res->fetch(FALSE)) { + while ($row = $res->fetch(false)) { $triggers[] = $row[0]; } return $triggers; @@ -696,7 +696,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector ORDER BY p.RDB\$PARAMETER_TYPE, p.RDB\$PARAMETER_NUMBER;" ); $procedures = []; - while ($row = $res->fetch(TRUE)) { + while ($row = $res->fetch(true)) { $key = $row['PROCEDURE_NAME']; $io = trim($row['PARAMETER_TYPE']); $num = $row['PARAMETER_NUMBER']; @@ -719,7 +719,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector FROM RDB\$PROCEDURES;" ); $procedures = []; - while ($row = $res->fetch(FALSE)) { + while ($row = $res->fetch(false)) { $procedures[] = $row[0]; } return $procedures; @@ -737,7 +737,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector WHERE RDB\$SYSTEM_FLAG = 0;" ); $generators = []; - while ($row = $res->fetch(FALSE)) { + while ($row = $res->fetch(false)) { $generators[] = $row[0]; } return $generators; @@ -755,7 +755,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector WHERE RDB\$SYSTEM_FLAG = 0;" ); $functions = []; - while ($row = $res->fetch(FALSE)) { + while ($row = $res->fetch(false)) { $functions[] = $row[0]; } return $functions; diff --git a/src/Dibi/Drivers/MsSqlDriver.php b/src/Dibi/Drivers/MsSqlDriver.php index f59ecdaa..1d02276e 100644 --- a/src/Dibi/Drivers/MsSqlDriver.php +++ b/src/Dibi/Drivers/MsSqlDriver.php @@ -28,14 +28,14 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver { use Dibi\Strict; - /** @var resource|NULL */ + /** @var resource|null */ private $connection; - /** @var resource|NULL */ + /** @var resource|null */ private $resultSet; /** @var bool */ - private $autoFree = TRUE; + private $autoFree = true; /** @@ -58,7 +58,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver if (isset($config['resource'])) { $this->connection = $config['resource']; } elseif (empty($config['persistent'])) { - $this->connection = @mssql_connect($config['host'], $config['username'], $config['password'], TRUE); // intentionally @ + $this->connection = @mssql_connect($config['host'], $config['username'], $config['password'], true); // intentionally @ } else { $this->connection = @mssql_pconnect($config['host'], $config['username'], $config['password']); // intentionally @ } @@ -90,13 +90,13 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver { $res = @mssql_query($sql, $this->connection); // intentionally @ - if ($res === FALSE) { + if ($res === false) { throw new Dibi\DriverException(mssql_get_last_message(), 0, $sql); } elseif (is_resource($res)) { return $this->createResultDriver($res); } - return NULL; + return null; } @@ -119,7 +119,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver $row = mssql_fetch_row($res); return $row[0]; } - return NULL; + return null; } @@ -127,7 +127,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver * Begins a transaction (if supported). * @throws Dibi\DriverException */ - public function begin(string $savepoint = NULL): void + public function begin(string $savepoint = null): void { $this->query('BEGIN TRANSACTION'); } @@ -137,7 +137,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver * Commits statements in a transaction. * @throws Dibi\DriverException */ - public function commit(string $savepoint = NULL): void + public function commit(string $savepoint = null): void { $this->query('COMMIT'); } @@ -147,7 +147,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver * Rollback changes in a transaction. * @throws Dibi\DriverException */ - public function rollback(string $savepoint = NULL): void + public function rollback(string $savepoint = null): void { $this->query('ROLLBACK'); } @@ -155,11 +155,11 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver /** * Returns the connection resource. - * @return resource|NULL + * @return resource|null */ public function getResource() { - return is_resource($this->connection) ? $this->connection : NULL; + return is_resource($this->connection) ? $this->connection : null; } @@ -269,7 +269,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver } elseif ($limit < 0) { throw new Dibi\NotSupportedException('Negative offset or limit.'); - } elseif ($limit !== NULL) { + } elseif ($limit !== null) { $sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ') t'; } } @@ -298,7 +298,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver /** * Fetches the row at current position and moves the internal cursor to the next position. - * @param bool TRUE for associative array, FALSE for numeric + * @param bool true for associative array, false for numeric */ public function fetch(bool $assoc): ?array { @@ -308,7 +308,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver /** * Moves cursor position without fetching row. - * @return bool TRUE on success, FALSE if unable to seek to specified record + * @return bool true on success, false if unable to seek to specified record */ public function seek(int $row): bool { @@ -322,7 +322,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver public function free(): void { mssql_free_result($this->resultSet); - $this->resultSet = NULL; + $this->resultSet = null; } @@ -348,11 +348,11 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver /** * Returns the result set resource. - * @return resource|NULL + * @return resource|null */ public function getResultResource() { - $this->autoFree = FALSE; - return is_resource($this->resultSet) ? $this->resultSet : NULL; + $this->autoFree = false; + return is_resource($this->resultSet) ? $this->resultSet : null; } } diff --git a/src/Dibi/Drivers/MsSqlReflector.php b/src/Dibi/Drivers/MsSqlReflector.php index c7dc1618..43aae019 100644 --- a/src/Dibi/Drivers/MsSqlReflector.php +++ b/src/Dibi/Drivers/MsSqlReflector.php @@ -40,7 +40,7 @@ class MsSqlReflector implements Dibi\Reflector FROM INFORMATION_SCHEMA.TABLES '); $tables = []; - while ($row = $res->fetch(FALSE)) { + while ($row = $res->fetch(false)) { $tables[] = [ 'name' => $row[0], 'view' => isset($row[1]) && $row[1] === 'VIEW', @@ -53,24 +53,24 @@ class MsSqlReflector implements Dibi\Reflector /** * Returns count of rows in a table */ - public function getTableCount(string $table, bool $fallback = TRUE): int + public function getTableCount(string $table, bool $fallback = true): int { if (empty($table)) { - return NULL; + return null; } $result = $this->driver->query(" SELECT MAX(rowcnt) FROM sys.sysindexes WHERE id=OBJECT_ID({$this->driver->escapeIdentifier($table)}) "); - $row = $result->fetch(FALSE); + $row = $result->fetch(false); if (!is_array($row) || count($row) < 1) { if ($fallback) { - $row = $this->driver->query("SELECT COUNT(*) FROM {$this->driver->escapeIdentifier($table)}")->fetch(FALSE); + $row = $this->driver->query("SELECT COUNT(*) FROM {$this->driver->escapeIdentifier($table)}")->fetch(false); $count = intval($row[0]); } else { - $count = NULL; + $count = null; } } else { $count = intval($row[0]); @@ -92,8 +92,8 @@ class MsSqlReflector implements Dibi\Reflector ORDER BY TABLE_NAME, ORDINAL_POSITION "); $columns = []; - while ($row = $res->fetch(TRUE)) { - $size = FALSE; + while ($row = $res->fetch(true)) { + $size = false; $type = strtoupper($row['DATA_TYPE']); $size_cols = [ @@ -116,10 +116,10 @@ class MsSqlReflector implements Dibi\Reflector 'table' => $table, 'nativetype' => $type, 'size' => $size, - 'unsigned' => NULL, + 'unsigned' => null, 'nullable' => $row['IS_NULLABLE'] === 'YES', 'default' => $row['COLUMN_DEFAULT'], - 'autoincrement' => FALSE, + 'autoincrement' => false, 'vendor' => $row, ]; } @@ -150,7 +150,7 @@ class MsSqlReflector implements Dibi\Reflector "); $indexes = []; - while ($row = $res->fetch(TRUE)) { + while ($row = $res->fetch(true)) { $index_name = $row['index_name']; if (!isset($indexes[$index_name])) { @@ -188,7 +188,7 @@ class MsSqlReflector implements Dibi\Reflector "); $keys = []; - while ($row = $res->fetch(TRUE)) { + while ($row = $res->fetch(true)) { $key_name = $row['foreign_key']; if (!isset($keys[$key_name])) { @@ -196,8 +196,8 @@ class MsSqlReflector implements Dibi\Reflector $keys[$key_name]['local'] = [$row['column_name']]; // local columns $keys[$key_name]['table'] = $row['reference_table_name']; // referenced table $keys[$key_name]['foreign'] = [$row['reference_column_name']]; // referenced columns - $keys[$key_name]['onDelete'] = FALSE; - $keys[$key_name]['onUpdate'] = FALSE; + $keys[$key_name]['onDelete'] = false; + $keys[$key_name]['onUpdate'] = false; } else { $keys[$key_name]['local'][] = $row['column_name']; // local columns $keys[$key_name]['foreign'][] = $row['reference_column_name']; // referenced columns diff --git a/src/Dibi/Drivers/MySqlReflector.php b/src/Dibi/Drivers/MySqlReflector.php index 78a7adf5..16e939eb 100644 --- a/src/Dibi/Drivers/MySqlReflector.php +++ b/src/Dibi/Drivers/MySqlReflector.php @@ -37,7 +37,7 @@ class MySqlReflector implements Dibi\Reflector { $res = $this->driver->query('SHOW FULL TABLES'); $tables = []; - while ($row = $res->fetch(FALSE)) { + while ($row = $res->fetch(false)) { $tables[] = [ 'name' => $row[0], 'view' => isset($row[1]) && $row[1] === 'VIEW', @@ -54,13 +54,13 @@ class MySqlReflector implements Dibi\Reflector { $res = $this->driver->query("SHOW FULL COLUMNS FROM {$this->driver->escapeIdentifier($table)}"); $columns = []; - while ($row = $res->fetch(TRUE)) { + while ($row = $res->fetch(true)) { $type = explode('(', $row['Type']); $columns[] = [ 'name' => $row['Field'], 'table' => $table, 'nativetype' => strtoupper($type[0]), - 'size' => isset($type[1]) ? (int) $type[1] : NULL, + 'size' => isset($type[1]) ? (int) $type[1] : null, 'unsigned' => (bool) strstr($row['Type'], 'unsigned'), 'nullable' => $row['Null'] === 'YES', 'default' => $row['Default'], @@ -79,7 +79,7 @@ class MySqlReflector implements Dibi\Reflector { $res = $this->driver->query("SHOW INDEX FROM {$this->driver->escapeIdentifier($table)}"); $indexes = []; - while ($row = $res->fetch(TRUE)) { + while ($row = $res->fetch(true)) { $indexes[$row['Key_name']]['name'] = $row['Key_name']; $indexes[$row['Key_name']]['unique'] = !$row['Non_unique']; $indexes[$row['Key_name']]['primary'] = $row['Key_name'] === 'PRIMARY'; @@ -95,7 +95,7 @@ class MySqlReflector implements Dibi\Reflector */ public function getForeignKeys(string $table): array { - $data = $this->driver->query("SELECT `ENGINE` FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = {$this->driver->escapeText($table)}")->fetch(TRUE); + $data = $this->driver->query("SELECT `ENGINE` FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = {$this->driver->escapeText($table)}")->fetch(true); if ($data['ENGINE'] !== 'InnoDB') { throw new Dibi\NotSupportedException("Foreign keys are not supported in {$data['ENGINE']} tables."); } @@ -114,7 +114,7 @@ class MySqlReflector implements Dibi\Reflector "); $foreignKeys = []; - while ($row = $res->fetch(TRUE)) { + while ($row = $res->fetch(true)) { $keyName = $row['CONSTRAINT_NAME']; $foreignKeys[$keyName]['name'] = $keyName; diff --git a/src/Dibi/Drivers/MySqliDriver.php b/src/Dibi/Drivers/MySqliDriver.php index 3e6545a1..ca24aec7 100644 --- a/src/Dibi/Drivers/MySqliDriver.php +++ b/src/Dibi/Drivers/MySqliDriver.php @@ -39,14 +39,14 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver const ERROR_DUPLICATE_ENTRY = 1062; const ERROR_DATA_TRUNCATED = 1265; - /** @var \mysqli|NULL */ + /** @var \mysqli|null */ private $connection; - /** @var \mysqli_result|NULL */ + /** @var \mysqli_result|null */ private $resultSet; /** @var bool */ - private $autoFree = TRUE; + private $autoFree = true; /** @var bool Is buffered (seekable and countable)? */ private $buffered; @@ -81,7 +81,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver 'username' => ini_get('mysqli.default_user'), 'password' => ini_get('mysqli.default_pw'), 'socket' => (string) ini_get('mysqli.default_socket'), - 'port' => NULL, + 'port' => null, ]; if (!isset($config['host'])) { $host = ini_get('mysqli.default_host'); @@ -89,8 +89,8 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver $config['host'] = $host; $config['port'] = ini_get('mysqli.default_port'); } else { - $config['host'] = NULL; - $config['port'] = NULL; + $config['host'] = null; + $config['port'] = null; } } @@ -156,19 +156,19 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver } elseif (is_object($res)) { return $this->createResultDriver($res); } - return NULL; + return null; } public static function createException(string $message, $code, string $sql): Dibi\DriverException { - if (in_array($code, [1216, 1217, 1451, 1452, 1701], TRUE)) { + if (in_array($code, [1216, 1217, 1451, 1452, 1701], true)) { return new Dibi\ForeignKeyConstraintViolationException($message, $code, $sql); - } elseif (in_array($code, [1062, 1557, 1569, 1586], TRUE)) { + } elseif (in_array($code, [1062, 1557, 1569, 1586], true)) { return new Dibi\UniqueConstraintViolationException($message, $code, $sql); - } elseif (in_array($code, [1048, 1121, 1138, 1171, 1252, 1263, 1566], TRUE)) { + } elseif (in_array($code, [1048, 1121, 1138, 1171, 1252, 1263, 1566], true)) { return new Dibi\NotNullConstraintViolationException($message, $code, $sql); } else { @@ -200,7 +200,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver */ public function getAffectedRows(): ?int { - return mysqli_affected_rows($this->connection) === -1 ? NULL : mysqli_affected_rows($this->connection); + return mysqli_affected_rows($this->connection) === -1 ? null : mysqli_affected_rows($this->connection); } @@ -217,7 +217,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver * Begins a transaction (if supported). * @throws Dibi\DriverException */ - public function begin(string $savepoint = NULL): void + public function begin(string $savepoint = null): void { $this->query($savepoint ? "SAVEPOINT $savepoint" : 'START TRANSACTION'); } @@ -227,7 +227,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver * Commits statements in a transaction. * @throws Dibi\DriverException */ - public function commit(string $savepoint = NULL): void + public function commit(string $savepoint = null): void { $this->query($savepoint ? "RELEASE SAVEPOINT $savepoint" : 'COMMIT'); } @@ -237,7 +237,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver * Rollback changes in a transaction. * @throws Dibi\DriverException */ - public function rollback(string $savepoint = NULL): void + public function rollback(string $savepoint = null): void { $this->query($savepoint ? "ROLLBACK TO SAVEPOINT $savepoint" : 'ROLLBACK'); } @@ -248,7 +248,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver */ public function getResource(): \mysqli { - return @$this->connection->thread_id ? $this->connection : NULL; + return @$this->connection->thread_id ? $this->connection : null; } @@ -353,9 +353,9 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver if ($limit < 0 || $offset < 0) { throw new Dibi\NotSupportedException('Negative offset or limit.'); - } elseif ($limit !== NULL || $offset) { + } elseif ($limit !== null || $offset) { // see http://dev.mysql.com/doc/refman/5.0/en/select.html - $sql .= ' LIMIT ' . ($limit === NULL ? '18446744073709551615' : (int) $limit) + $sql .= ' LIMIT ' . ($limit === null ? '18446744073709551615' : (int) $limit) . ($offset ? ' OFFSET ' . (int) $offset : ''); } } @@ -387,7 +387,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver /** * Fetches the row at current position and moves the internal cursor to the next position. - * @param bool TRUE for associative array, FALSE for numeric + * @param bool true for associative array, false for numeric */ public function fetch(bool $assoc): ?array { @@ -414,7 +414,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver public function free(): void { mysqli_free_result($this->resultSet); - $this->resultSet = NULL; + $this->resultSet = null; } @@ -424,8 +424,8 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver public function getResultColumns(): array { static $types; - if ($types === NULL) { - $consts = get_defined_constants(TRUE); + if ($types === null) { + $consts = get_defined_constants(true); $types = []; foreach ($consts['mysqli'] ?? [] as $key => $value) { if (strncmp($key, 'MYSQLI_TYPE_', 12) === 0) { @@ -444,7 +444,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver 'table' => $row['orgtable'], 'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'], 'nativetype' => $types[$row['type']] ?? $row['type'], - 'type' => $row['type'] === MYSQLI_TYPE_TIME ? Dibi\Type::TIME_INTERVAL : NULL, + 'type' => $row['type'] === MYSQLI_TYPE_TIME ? Dibi\Type::TIME_INTERVAL : null, 'vendor' => $row, ]; } @@ -457,7 +457,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver */ public function getResultResource(): ?\mysqli_result { - $this->autoFree = FALSE; + $this->autoFree = false; return $this->resultSet; } } diff --git a/src/Dibi/Drivers/OdbcDriver.php b/src/Dibi/Drivers/OdbcDriver.php index dbc73928..155ad844 100644 --- a/src/Dibi/Drivers/OdbcDriver.php +++ b/src/Dibi/Drivers/OdbcDriver.php @@ -27,16 +27,16 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector { use Dibi\Strict; - /** @var resource|NULL */ + /** @var resource|null */ private $connection; - /** @var resource|NULL */ + /** @var resource|null */ private $resultSet; /** @var bool */ - private $autoFree = TRUE; + private $autoFree = true; - /** @var int|NULL Affected rows */ + /** @var int|null Affected rows */ private $affectedRows; /** @var int Cursor */ @@ -98,17 +98,17 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector */ public function query(string $sql): ?Dibi\ResultDriver { - $this->affectedRows = NULL; + $this->affectedRows = null; $res = @odbc_exec($this->connection, $sql); // intentionally @ - if ($res === FALSE) { + if ($res === false) { throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection), 0, $sql); } elseif (is_resource($res)) { $this->affectedRows = Dibi\Helpers::false2Null(odbc_num_rows($res)); return $this->createResultDriver($res); } - return NULL; + return null; } @@ -134,9 +134,9 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector * Begins a transaction (if supported). * @throws Dibi\DriverException */ - public function begin(string $savepoint = NULL): void + public function begin(string $savepoint = null): void { - if (!odbc_autocommit($this->connection, 0/*FALSE*/)) { + if (!odbc_autocommit($this->connection, 0/*false*/)) { throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection)); } } @@ -146,12 +146,12 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector * Commits statements in a transaction. * @throws Dibi\DriverException */ - public function commit(string $savepoint = NULL): void + public function commit(string $savepoint = null): void { if (!odbc_commit($this->connection)) { throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection)); } - odbc_autocommit($this->connection, 1/*TRUE*/); + odbc_autocommit($this->connection, 1/*true*/); } @@ -159,12 +159,12 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector * Rollback changes in a transaction. * @throws Dibi\DriverException */ - public function rollback(string $savepoint = NULL): void + public function rollback(string $savepoint = null): void { if (!odbc_rollback($this->connection)) { throw new Dibi\DriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection)); } - odbc_autocommit($this->connection, 1/*TRUE*/); + odbc_autocommit($this->connection, 1/*true*/); } @@ -179,11 +179,11 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector /** * Returns the connection resource. - * @return resource|NULL + * @return resource|null */ public function getResource() { - return is_resource($this->connection) ? $this->connection : NULL; + return is_resource($this->connection) ? $this->connection : null; } @@ -292,7 +292,7 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector } elseif ($limit < 0) { throw new Dibi\NotSupportedException('Negative offset or limit.'); - } elseif ($limit !== NULL) { + } elseif ($limit !== null) { $sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ') t'; } } @@ -322,7 +322,7 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector /** * Fetches the row at current position and moves the internal cursor to the next position. - * @param bool TRUE for associative array, FALSE for numeric + * @param bool true for associative array, false for numeric */ public function fetch(bool $assoc): ?array { @@ -331,7 +331,7 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector } else { $set = $this->resultSet; if (!odbc_fetch_row($set, ++$this->row)) { - return NULL; + return null; } $count = odbc_num_fields($set); $cols = []; @@ -349,7 +349,7 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector public function seek(int $row): bool { $this->row = $row; - return TRUE; + return true; } @@ -359,7 +359,7 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector public function free(): void { odbc_free_result($this->resultSet); - $this->resultSet = NULL; + $this->resultSet = null; } @@ -373,7 +373,7 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector for ($i = 1; $i <= $count; $i++) { $columns[] = [ 'name' => odbc_field_name($this->resultSet, $i), - 'table' => NULL, + 'table' => null, 'fullname' => odbc_field_name($this->resultSet, $i), 'nativetype' => odbc_field_type($this->resultSet, $i), ]; @@ -384,12 +384,12 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector /** * Returns the result set resource. - * @return resource|NULL + * @return resource|null */ public function getResultResource() { - $this->autoFree = FALSE; - return is_resource($this->resultSet) ? $this->resultSet : NULL; + $this->autoFree = false; + return is_resource($this->resultSet) ? $this->resultSet : null; } diff --git a/src/Dibi/Drivers/OracleDriver.php b/src/Dibi/Drivers/OracleDriver.php index 7bfbab3a..038be1c8 100644 --- a/src/Dibi/Drivers/OracleDriver.php +++ b/src/Dibi/Drivers/OracleDriver.php @@ -21,7 +21,7 @@ use Dibi; * - password (or pass) * - charset => character encoding to set * - schema => alters session schema - * - nativeDate => use native date format (defaults to TRUE) + * - nativeDate => use native date format (defaults to true) * - resource (resource) => existing connection resource * - persistent => Creates persistent connections with oci_pconnect instead of oci_new_connect * - lazy, profiler, result, substitutes, ... => see Dibi\Connection options @@ -30,22 +30,22 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector { use Dibi\Strict; - /** @var resource|NULL */ + /** @var resource|null */ private $connection; - /** @var resource|NULL */ + /** @var resource|null */ private $resultSet; /** @var bool */ - private $autoFree = TRUE; + private $autoFree = true; /** @var bool */ - private $autocommit = TRUE; + private $autocommit = true; /** @var bool use native datetime format */ private $nativeDate; - /** @var int|NULL Number of affected rows */ + /** @var int|null Number of affected rows */ private $affectedRows; @@ -71,7 +71,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector if (isset($config['formatDate']) || isset($config['formatDateTime'])) { trigger_error('OracleDriver: options formatDate and formatDateTime are deprecated.', E_USER_DEPRECATED); } - $this->nativeDate = $config['nativeDate'] ?? TRUE; + $this->nativeDate = $config['nativeDate'] ?? true; if (isset($config['resource'])) { $this->connection = $config['resource']; @@ -107,7 +107,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector */ public function query(string $sql): ?Dibi\ResultDriver { - $this->affectedRows = NULL; + $this->affectedRows = null; $res = oci_parse($this->connection, $sql); if ($res) { @oci_execute($res, $this->autocommit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT); @@ -123,19 +123,19 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector $err = oci_error($this->connection); throw new Dibi\DriverException($err['message'], $err['code'], $sql); } - return NULL; + return null; } public static function createException(string $message, $code, string $sql): Dibi\DriverException { - if (in_array($code, [1, 2299, 38911], TRUE)) { + if (in_array($code, [1, 2299, 38911], true)) { return new Dibi\UniqueConstraintViolationException($message, $code, $sql); - } elseif (in_array($code, [1400], TRUE)) { + } elseif (in_array($code, [1400], true)) { return new Dibi\NotNullConstraintViolationException($message, $code, $sql); - } elseif (in_array($code, [2266, 2291, 2292], TRUE)) { + } elseif (in_array($code, [2266, 2291, 2292], true)) { return new Dibi\ForeignKeyConstraintViolationException($message, $code, $sql); } else { @@ -158,17 +158,17 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector */ public function getInsertId(?string $sequence): ?int { - $row = $this->query("SELECT $sequence.CURRVAL AS ID FROM DUAL")->fetch(TRUE); - return isset($row['ID']) ? (int) $row['ID'] : NULL; + $row = $this->query("SELECT $sequence.CURRVAL AS ID FROM DUAL")->fetch(true); + return isset($row['ID']) ? (int) $row['ID'] : null; } /** * Begins a transaction (if supported). */ - public function begin(string $savepoint = NULL): void + public function begin(string $savepoint = null): void { - $this->autocommit = FALSE; + $this->autocommit = false; } @@ -176,13 +176,13 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector * Commits statements in a transaction. * @throws Dibi\DriverException */ - public function commit(string $savepoint = NULL): void + public function commit(string $savepoint = null): void { if (!oci_commit($this->connection)) { $err = oci_error($this->connection); throw new Dibi\DriverException($err['message'], $err['code']); } - $this->autocommit = TRUE; + $this->autocommit = true; } @@ -190,23 +190,23 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector * Rollback changes in a transaction. * @throws Dibi\DriverException */ - public function rollback(string $savepoint = NULL): void + public function rollback(string $savepoint = null): void { if (!oci_rollback($this->connection)) { $err = oci_error($this->connection); throw new Dibi\DriverException($err['message'], $err['code']); } - $this->autocommit = TRUE; + $this->autocommit = true; } /** * Returns the connection resource. - * @return resource|NULL + * @return resource|null */ public function getResource() { - return is_resource($this->connection) ? $this->connection : NULL; + return is_resource($this->connection) ? $this->connection : null; } @@ -321,10 +321,10 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector } elseif ($offset) { // see http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html $sql = 'SELECT * FROM (SELECT t.*, ROWNUM AS "__rnum" FROM (' . $sql . ') t ' - . ($limit !== NULL ? 'WHERE ROWNUM <= ' . ((int) $offset + (int) $limit) : '') + . ($limit !== null ? 'WHERE ROWNUM <= ' . ((int) $offset + (int) $limit) : '') . ') WHERE "__rnum" > '. (int) $offset; - } elseif ($limit !== NULL) { + } elseif ($limit !== null) { $sql = 'SELECT * FROM (' . $sql . ') WHERE ROWNUM <= ' . (int) $limit; } } @@ -353,7 +353,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector /** * Fetches the row at current position and moves the internal cursor to the next position. - * @param bool TRUE for associative array, FALSE for numeric + * @param bool true for associative array, false for numeric */ public function fetch(bool $assoc): ?array { @@ -376,7 +376,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector public function free(): void { oci_free_statement($this->resultSet); - $this->resultSet = NULL; + $this->resultSet = null; } @@ -391,7 +391,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector $type = oci_field_type($this->resultSet, $i); $columns[] = [ 'name' => oci_field_name($this->resultSet, $i), - 'table' => NULL, + 'table' => null, 'fullname' => oci_field_name($this->resultSet, $i), 'nativetype' => $type === 'NUMBER' && oci_field_scale($this->resultSet, $i) === 0 ? 'INTEGER' : $type, ]; @@ -402,12 +402,12 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector /** * Returns the result set resource. - * @return resource|NULL + * @return resource|null */ public function getResultResource() { - $this->autoFree = FALSE; - return is_resource($this->resultSet) ? $this->resultSet : NULL; + $this->autoFree = false; + return is_resource($this->resultSet) ? $this->resultSet : null; } @@ -421,7 +421,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector { $res = $this->query('SELECT * FROM cat'); $tables = []; - while ($row = $res->fetch(FALSE)) { + while ($row = $res->fetch(false)) { if ($row[1] === 'TABLE' || $row[1] === 'VIEW') { $tables[] = [ 'name' => $row[0], @@ -440,12 +440,12 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector { $res = $this->query('SELECT * FROM "ALL_TAB_COLUMNS" WHERE "TABLE_NAME" = ' . $this->escapeText($table)); $columns = []; - while ($row = $res->fetch(TRUE)) { + while ($row = $res->fetch(true)) { $columns[] = [ 'table' => $row['TABLE_NAME'], 'name' => $row['COLUMN_NAME'], 'nativetype' => $row['DATA_TYPE'], - 'size' => $row['DATA_LENGTH'] ?? NULL, + 'size' => $row['DATA_LENGTH'] ?? null, 'nullable' => $row['NULLABLE'] === 'Y', 'default' => $row['DATA_DEFAULT'], 'vendor' => $row, diff --git a/src/Dibi/Drivers/PdoDriver.php b/src/Dibi/Drivers/PdoDriver.php index d60dca0f..1f77dbd9 100644 --- a/src/Dibi/Drivers/PdoDriver.php +++ b/src/Dibi/Drivers/PdoDriver.php @@ -33,10 +33,10 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver /** @var PDO Connection resource */ private $connection; - /** @var \PDOStatement|NULL Resultset resource */ + /** @var \PDOStatement|null Resultset resource */ private $resultSet; - /** @var int|NULL Affected rows */ + /** @var int|null Affected rows */ private $affectedRows; /** @var string */ @@ -91,7 +91,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver */ public function disconnect(): void { - $this->connection = NULL; + $this->connection = null; } @@ -104,12 +104,12 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver // must detect if SQL returns result set or num of affected rows $cmd = strtoupper(substr(ltrim($sql), 0, 6)); static $list = ['UPDATE' => 1, 'DELETE' => 1, 'INSERT' => 1, 'REPLAC' => 1]; - $this->affectedRows = NULL; + $this->affectedRows = null; if (isset($list[$cmd])) { $this->affectedRows = Helpers::false2Null($this->connection->exec($sql)); - if ($this->affectedRows !== NULL) { - return NULL; + if ($this->affectedRows !== null) { + return null; } } else { $res = $this->connection->query($sql); @@ -161,7 +161,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver * Begins a transaction (if supported). * @throws Dibi\DriverException */ - public function begin(string $savepoint = NULL): void + public function begin(string $savepoint = null): void { if (!$this->connection->beginTransaction()) { $err = $this->connection->errorInfo(); @@ -174,7 +174,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver * Commits statements in a transaction. * @throws Dibi\DriverException */ - public function commit(string $savepoint = NULL): void + public function commit(string $savepoint = null): void { if (!$this->connection->commit()) { $err = $this->connection->errorInfo(); @@ -187,7 +187,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver * Rollback changes in a transaction. * @throws Dibi\DriverException */ - public function rollback(string $savepoint = NULL): void + public function rollback(string $savepoint = null): void { if (!$this->connection->rollBack()) { $err = $this->connection->errorInfo(); @@ -379,15 +379,15 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver switch ($this->driverName) { case 'mysql': - if ($limit !== NULL || $offset) { + if ($limit !== null || $offset) { // see http://dev.mysql.com/doc/refman/5.0/en/select.html - $sql .= ' LIMIT ' . ($limit === NULL ? '18446744073709551615' : (int) $limit) + $sql .= ' LIMIT ' . ($limit === null ? '18446744073709551615' : (int) $limit) . ($offset ? ' OFFSET ' . (int) $offset : ''); } break; case 'pgsql': - if ($limit !== NULL) { + if ($limit !== null) { $sql .= ' LIMIT ' . (int) $limit; } if ($offset) { @@ -396,8 +396,8 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver break; case 'sqlite': - if ($limit !== NULL || $offset) { - $sql .= ' LIMIT ' . ($limit === NULL ? '-1' : (int) $limit) + if ($limit !== null || $offset) { + $sql .= ' LIMIT ' . ($limit === null ? '-1' : (int) $limit) . ($offset ? ' OFFSET ' . (int) $offset : ''); } break; @@ -406,10 +406,10 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver if ($offset) { // see http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html $sql = 'SELECT * FROM (SELECT t.*, ROWNUM AS "__rnum" FROM (' . $sql . ') t ' - . ($limit !== NULL ? 'WHERE ROWNUM <= ' . ((int) $offset + (int) $limit) : '') + . ($limit !== null ? 'WHERE ROWNUM <= ' . ((int) $offset + (int) $limit) : '') . ') WHERE "__rnum" > '. (int) $offset; - } elseif ($limit !== NULL) { + } elseif ($limit !== null) { $sql = 'SELECT * FROM (' . $sql . ') WHERE ROWNUM <= ' . (int) $limit; } break; @@ -419,7 +419,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver case 'dblib': if (version_compare($this->serverVersion, '11.0') >= 0) { // 11 == SQL Server 2012 // requires ORDER BY, see https://technet.microsoft.com/en-us/library/gg699618(v=sql.110).aspx - if ($limit !== NULL) { + if ($limit !== null) { $sql = sprintf('%s OFFSET %d ROWS FETCH NEXT %d ROWS ONLY', rtrim($sql), $offset, $limit); } elseif ($offset) { $sql = sprintf('%s OFFSET %d ROWS', rtrim($sql), $offset); @@ -432,7 +432,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver if ($offset) { throw new Dibi\NotSupportedException('Offset is not supported by this database.'); - } elseif ($limit !== NULL) { + } elseif ($limit !== null) { $sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ') t'; break; } @@ -458,7 +458,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver /** * Fetches the row at current position and moves the internal cursor to the next position. - * @param bool TRUE for associative array, FALSE for numeric + * @param bool true for associative array, false for numeric */ public function fetch(bool $assoc): ?array { @@ -480,7 +480,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver */ public function free(): void { - $this->resultSet = NULL; + $this->resultSet = null; } @@ -494,11 +494,11 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver $columns = []; for ($i = 0; $i < $count; $i++) { $row = @$this->resultSet->getColumnMeta($i); // intentionally @ - if ($row === FALSE) { + if ($row === false) { throw new Dibi\NotSupportedException('Driver does not support meta data.'); } $row = $row + [ - 'table' => NULL, + 'table' => null, 'native_type' => 'VAR_STRING', ]; @@ -506,7 +506,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver 'name' => $row['name'], 'table' => $row['table'], 'nativetype' => $row['native_type'], - 'type' => $row['native_type'] === 'TIME' && $this->driverName === 'mysql' ? Dibi\Type::TIME_INTERVAL : NULL, + 'type' => $row['native_type'] === 'TIME' && $this->driverName === 'mysql' ? Dibi\Type::TIME_INTERVAL : null, 'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'], 'vendor' => $row, ]; diff --git a/src/Dibi/Drivers/PostgreDriver.php b/src/Dibi/Drivers/PostgreDriver.php index 088cc2fb..a2a6771e 100644 --- a/src/Dibi/Drivers/PostgreDriver.php +++ b/src/Dibi/Drivers/PostgreDriver.php @@ -29,16 +29,16 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector { use Dibi\Strict; - /** @var resource|NULL */ + /** @var resource|null */ private $connection; - /** @var resource|NULL */ + /** @var resource|null */ private $resultSet; /** @var bool */ - private $autoFree = TRUE; + private $autoFree = true; - /** @var int|NULL Affected rows */ + /** @var int|null Affected rows */ private $affectedRows; @@ -59,7 +59,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector */ public function connect(array &$config): void { - $error = NULL; + $error = null; if (isset($config['resource'])) { $this->connection = $config['resource']; @@ -132,11 +132,11 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector */ public function query(string $sql): ?Dibi\ResultDriver { - $this->affectedRows = NULL; + $this->affectedRows = null; $res = @pg_query($this->connection, $sql); // intentionally @ - if ($res === FALSE) { - throw self::createException(pg_last_error($this->connection), NULL, $sql); + if ($res === false) { + throw self::createException(pg_last_error($this->connection), null, $sql); } elseif (is_resource($res)) { $this->affectedRows = Helpers::false2Null(pg_affected_rows($res)); @@ -144,18 +144,18 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector return $this->createResultDriver($res); } } - return NULL; + return null; } - public static function createException(string $message, $code = NULL, string $sql = NULL): Dibi\DriverException + public static function createException(string $message, $code = null, string $sql = null): Dibi\DriverException { - if ($code === NULL && preg_match('#^ERROR:\s+(\S+):\s*#', $message, $m)) { + if ($code === null && preg_match('#^ERROR:\s+(\S+):\s*#', $message, $m)) { $code = $m[1]; $message = substr($message, strlen($m[0])); } - if ($code === '0A000' && strpos($message, 'truncate') !== FALSE) { + if ($code === '0A000' && strpos($message, 'truncate') !== false) { return new Dibi\ForeignKeyConstraintViolationException($message, $code, $sql); } elseif ($code === '23502') { @@ -187,7 +187,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector */ public function getInsertId(?string $sequence): ?int { - if ($sequence === NULL) { + if ($sequence === null) { // PostgreSQL 8.1 is needed $res = $this->query('SELECT LASTVAL()'); } else { @@ -195,11 +195,11 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector } if (!$res) { - return NULL; + return null; } - $row = $res->fetch(FALSE); - return is_array($row) ? $row[0] : NULL; + $row = $res->fetch(false); + return is_array($row) ? $row[0] : null; } @@ -207,7 +207,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector * Begins a transaction (if supported). * @throws Dibi\DriverException */ - public function begin(string $savepoint = NULL): void + public function begin(string $savepoint = null): void { $this->query($savepoint ? "SAVEPOINT $savepoint" : 'START TRANSACTION'); } @@ -217,7 +217,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector * Commits statements in a transaction. * @throws Dibi\DriverException */ - public function commit(string $savepoint = NULL): void + public function commit(string $savepoint = null): void { $this->query($savepoint ? "RELEASE SAVEPOINT $savepoint" : 'COMMIT'); } @@ -227,7 +227,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector * Rollback changes in a transaction. * @throws Dibi\DriverException */ - public function rollback(string $savepoint = NULL): void + public function rollback(string $savepoint = null): void { $this->query($savepoint ? "ROLLBACK TO SAVEPOINT $savepoint" : 'ROLLBACK'); } @@ -238,17 +238,17 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector */ public function inTransaction(): bool { - return !in_array(pg_transaction_status($this->connection), [PGSQL_TRANSACTION_UNKNOWN, PGSQL_TRANSACTION_IDLE], TRUE); + return !in_array(pg_transaction_status($this->connection), [PGSQL_TRANSACTION_UNKNOWN, PGSQL_TRANSACTION_IDLE], true); } /** * Returns the connection resource. - * @return resource|NULL + * @return resource|null */ public function getResource() { - return is_resource($this->connection) ? $this->connection : NULL; + return is_resource($this->connection) ? $this->connection : null; } @@ -363,7 +363,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector if ($limit < 0 || $offset < 0) { throw new Dibi\NotSupportedException('Negative offset or limit.'); } - if ($limit !== NULL) { + if ($limit !== null) { $sql .= ' LIMIT ' . (int) $limit; } if ($offset) { @@ -395,11 +395,11 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector /** * Fetches the row at current position and moves the internal cursor to the next position. - * @param bool TRUE for associative array, FALSE for numeric + * @param bool true for associative array, false for numeric */ public function fetch(bool $assoc): ?array { - return Helpers::false2Null(pg_fetch_array($this->resultSet, NULL, $assoc ? PGSQL_ASSOC : PGSQL_NUM)); + return Helpers::false2Null(pg_fetch_array($this->resultSet, null, $assoc ? PGSQL_ASSOC : PGSQL_NUM)); } @@ -418,7 +418,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector public function free(): void { pg_free_result($this->resultSet); - $this->resultSet = NULL; + $this->resultSet = null; } @@ -444,12 +444,12 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector /** * Returns the result set resource. - * @return resource|NULL + * @return resource|null */ public function getResultResource() { - $this->autoFree = FALSE; - return is_resource($this->resultSet) ? $this->resultSet : NULL; + $this->autoFree = false; + return is_resource($this->resultSet) ? $this->resultSet : null; } @@ -543,13 +543,13 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector } $columns = []; - while ($row = $res->fetch(TRUE)) { + while ($row = $res->fetch(true)) { $size = (int) max($row['character_maximum_length'], $row['numeric_precision']); $columns[] = [ 'name' => $row['column_name'], 'table' => $table, 'nativetype' => strtoupper($row['udt_name']), - 'size' => $size > 0 ? $size : NULL, + 'size' => $size > 0 ? $size : null, 'nullable' => $row['is_nullable'] === 'YES' || $row['is_nullable'] === 't', 'default' => $row['column_default'], 'autoincrement' => (int) $row['ordinal_position'] === $primary && substr($row['column_default'], 0, 7) === 'nextval', @@ -581,7 +581,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector "); $columns = []; - while ($row = $res->fetch(TRUE)) { + while ($row = $res->fetch(true)) { $columns[$row['ordinal_position']] = $row['column_name']; } @@ -594,7 +594,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector "); $indexes = []; - while ($row = $res->fetch(TRUE)) { + while ($row = $res->fetch(true)) { $indexes[$row['relname']]['name'] = $row['relname']; $indexes[$row['relname']]['unique'] = $row['indisunique'] === 't'; $indexes[$row['relname']]['primary'] = $row['indisprimary'] === 't'; @@ -653,7 +653,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector "); $fKeys = $references = []; - while ($row = $res->fetch(TRUE)) { + while ($row = $res->fetch(true)) { if (!isset($fKeys[$row['name']])) { $fKeys[$row['name']] = [ 'name' => $row['name'], diff --git a/src/Dibi/Drivers/Sqlite3Driver.php b/src/Dibi/Drivers/Sqlite3Driver.php index fc0461d6..6da6cf1d 100644 --- a/src/Dibi/Drivers/Sqlite3Driver.php +++ b/src/Dibi/Drivers/Sqlite3Driver.php @@ -29,14 +29,14 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver { use Dibi\Strict; - /** @var SQLite3|NULL */ + /** @var SQLite3|null */ private $connection; - /** @var \SQLite3Result|NULL */ + /** @var \SQLite3Result|null */ private $resultSet; /** @var bool */ - private $autoFree = TRUE; + private $autoFree = true; /** @var string Date and datetime format */ private $fmtDate, $fmtDateTime; @@ -79,7 +79,7 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver $this->dbcharset = empty($config['dbcharset']) ? 'UTF-8' : $config['dbcharset']; $this->charset = empty($config['charset']) ? 'UTF-8' : $config['charset']; if (strcasecmp($this->dbcharset, $this->charset) === 0) { - $this->dbcharset = $this->charset = NULL; + $this->dbcharset = $this->charset = null; } // enable foreign keys support (defaultly disabled; if disabled then foreign key constraints are not enforced) @@ -105,7 +105,7 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver */ public function query(string $sql): ?Dibi\ResultDriver { - if ($this->dbcharset !== NULL) { + if ($this->dbcharset !== null) { $sql = iconv($this->charset, $this->dbcharset . '//IGNORE', $sql); } @@ -116,7 +116,7 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver } elseif ($res instanceof \SQLite3Result) { return $this->createResultDriver($res); } - return NULL; + return null; } @@ -125,19 +125,19 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver if ($code !== 19) { return new Dibi\DriverException($message, $code, $sql); - } elseif (strpos($message, 'must be unique') !== FALSE - || strpos($message, 'is not unique') !== FALSE - || strpos($message, 'UNIQUE constraint failed') !== FALSE + } elseif (strpos($message, 'must be unique') !== false + || strpos($message, 'is not unique') !== false + || strpos($message, 'UNIQUE constraint failed') !== false ) { return new Dibi\UniqueConstraintViolationException($message, $code, $sql); - } elseif (strpos($message, 'may not be NULL') !== FALSE - || strpos($message, 'NOT NULL constraint failed') !== FALSE + } elseif (strpos($message, 'may not be null') !== false + || strpos($message, 'NOT NULL constraint failed') !== false ) { return new Dibi\NotNullConstraintViolationException($message, $code, $sql); - } elseif (strpos($message, 'foreign key constraint failed') !== FALSE - || strpos($message, 'FOREIGN KEY constraint failed') !== FALSE + } elseif (strpos($message, 'foreign key constraint failed') !== false + || strpos($message, 'FOREIGN KEY constraint failed') !== false ) { return new Dibi\ForeignKeyConstraintViolationException($message, $code, $sql); @@ -169,7 +169,7 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver * Begins a transaction (if supported). * @throws Dibi\DriverException */ - public function begin(string $savepoint = NULL): void + public function begin(string $savepoint = null): void { $this->query($savepoint ? "SAVEPOINT $savepoint" : 'BEGIN'); } @@ -179,7 +179,7 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver * Commits statements in a transaction. * @throws Dibi\DriverException */ - public function commit(string $savepoint = NULL): void + public function commit(string $savepoint = null): void { $this->query($savepoint ? "RELEASE SAVEPOINT $savepoint" : 'COMMIT'); } @@ -189,7 +189,7 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver * Rollback changes in a transaction. * @throws Dibi\DriverException */ - public function rollback(string $savepoint = NULL): void + public function rollback(string $savepoint = null): void { $this->query($savepoint ? "ROLLBACK TO SAVEPOINT $savepoint" : 'ROLLBACK'); } @@ -305,8 +305,8 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver if ($limit < 0 || $offset < 0) { throw new Dibi\NotSupportedException('Negative offset or limit.'); - } elseif ($limit !== NULL || $offset) { - $sql .= ' LIMIT ' . ($limit === NULL ? '-1' : (int) $limit) + } elseif ($limit !== null || $offset) { + $sql .= ' LIMIT ' . ($limit === null ? '-1' : (int) $limit) . ($offset ? ' OFFSET ' . (int) $offset : ''); } } @@ -336,19 +336,19 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver /** * Fetches the row at current position and moves the internal cursor to the next position. - * @param bool TRUE for associative array, FALSE for numeric + * @param bool true for associative array, false for numeric */ public function fetch(bool $assoc): ?array { $row = $this->resultSet->fetchArray($assoc ? SQLITE3_ASSOC : SQLITE3_NUM); if (!$row) { - return NULL; + return null; } - $charset = $this->charset === NULL ? NULL : $this->charset . '//TRANSLIT'; + $charset = $this->charset === null ? null : $this->charset . '//TRANSLIT'; if ($row && ($assoc || $charset)) { $tmp = []; foreach ($row as $k => $v) { - if ($charset !== NULL && is_string($v)) { + if ($charset !== null && is_string($v)) { $v = iconv($this->dbcharset, $charset, $v); } $tmp[str_replace(['[', ']'], '', $k)] = $v; @@ -375,7 +375,7 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver public function free(): void { $this->resultSet->finalize(); - $this->resultSet = NULL; + $this->resultSet = null; } @@ -390,7 +390,7 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver for ($i = 0; $i < $count; $i++) { $columns[] = [ 'name' => $this->resultSet->columnName($i), - 'table' => NULL, + 'table' => null, 'fullname' => $this->resultSet->columnName($i), 'nativetype' => $types[$this->resultSet->columnType($i)], ]; @@ -404,7 +404,7 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver */ public function getResultResource(): ?\SQLite3Result { - $this->autoFree = FALSE; + $this->autoFree = false; return $this->resultSet; } diff --git a/src/Dibi/Drivers/SqliteReflector.php b/src/Dibi/Drivers/SqliteReflector.php index dd8e37d7..c8d2bda3 100644 --- a/src/Dibi/Drivers/SqliteReflector.php +++ b/src/Dibi/Drivers/SqliteReflector.php @@ -42,7 +42,7 @@ class SqliteReflector implements Dibi\Reflector ORDER BY name "); $tables = []; - while ($row = $res->fetch(TRUE)) { + while ($row = $res->fetch(true)) { $tables[] = $row; } return $tables; @@ -56,7 +56,7 @@ class SqliteReflector implements Dibi\Reflector { $res = $this->driver->query("PRAGMA table_info({$this->driver->escapeIdentifier($table)})"); $columns = []; - while ($row = $res->fetch(TRUE)) { + while ($row = $res->fetch(true)) { $column = $row['name']; $type = explode('(', $row['type']); $columns[] = [ @@ -64,7 +64,7 @@ class SqliteReflector implements Dibi\Reflector 'table' => $table, 'fullname' => "$table.$column", 'nativetype' => strtoupper($type[0]), - 'size' => isset($type[1]) ? (int) $type[1] : NULL, + 'size' => isset($type[1]) ? (int) $type[1] : null, 'nullable' => $row['notnull'] == '0', 'default' => $row['dflt_value'], 'autoincrement' => $row['pk'] && $type[0] === 'INTEGER', @@ -82,14 +82,14 @@ class SqliteReflector implements Dibi\Reflector { $res = $this->driver->query("PRAGMA index_list({$this->driver->escapeIdentifier($table)})"); $indexes = []; - while ($row = $res->fetch(TRUE)) { + while ($row = $res->fetch(true)) { $indexes[$row['name']]['name'] = $row['name']; $indexes[$row['name']]['unique'] = (bool) $row['unique']; } foreach ($indexes as $index => $values) { $res = $this->driver->query("PRAGMA index_info({$this->driver->escapeIdentifier($index)})"); - while ($row = $res->fetch(TRUE)) { + while ($row = $res->fetch(true)) { $indexes[$index]['columns'][$row['seqno']] = $row['name']; } } @@ -97,7 +97,7 @@ class SqliteReflector implements Dibi\Reflector $columns = $this->getColumns($table); foreach ($indexes as $index => $values) { $column = $indexes[$index]['columns'][0]; - $primary = FALSE; + $primary = false; foreach ($columns as $info) { if ($column == $info['name']) { $primary = $info['vendor']['pk']; @@ -111,8 +111,8 @@ class SqliteReflector implements Dibi\Reflector if ($column['vendor']['pk']) { $indexes[] = [ 'name' => 'ROWID', - 'unique' => TRUE, - 'primary' => TRUE, + 'unique' => true, + 'primary' => true, 'columns' => [$column['name']], ]; break; @@ -131,7 +131,7 @@ class SqliteReflector implements Dibi\Reflector { $res = $this->driver->query("PRAGMA foreign_key_list({$this->driver->escapeIdentifier($table)})"); $keys = []; - while ($row = $res->fetch(TRUE)) { + while ($row = $res->fetch(true)) { $keys[$row['id']]['name'] = $row['id']; // foreign key name $keys[$row['id']]['local'][$row['seq']] = $row['from']; // local columns $keys[$row['id']]['table'] = $row['table']; // referenced table @@ -139,8 +139,8 @@ class SqliteReflector implements Dibi\Reflector $keys[$row['id']]['onDelete'] = $row['on_delete']; $keys[$row['id']]['onUpdate'] = $row['on_update']; - if ($keys[$row['id']]['foreign'][0] == NULL) { - $keys[$row['id']]['foreign'] = NULL; + if ($keys[$row['id']]['foreign'][0] == null) { + $keys[$row['id']]['foreign'] = null; } } return array_values($keys); diff --git a/src/Dibi/Drivers/SqlsrvDriver.php b/src/Dibi/Drivers/SqlsrvDriver.php index b536da11..d30f81d3 100644 --- a/src/Dibi/Drivers/SqlsrvDriver.php +++ b/src/Dibi/Drivers/SqlsrvDriver.php @@ -31,16 +31,16 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver { use Dibi\Strict; - /** @var resource|NULL */ + /** @var resource|null */ private $connection; - /** @var resource|NULL */ + /** @var resource|null */ private $resultSet; /** @var bool */ - private $autoFree = TRUE; + private $autoFree = true; - /** @var int|NULL Affected rows */ + /** @var int|null Affected rows */ private $affectedRows; /** @var string */ @@ -107,10 +107,10 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver */ public function query(string $sql): ?Dibi\ResultDriver { - $this->affectedRows = NULL; + $this->affectedRows = null; $res = sqlsrv_query($this->connection, $sql); - if ($res === FALSE) { + if ($res === false) { $info = sqlsrv_errors(); throw new Dibi\DriverException($info[0]['message'], $info[0]['code'], $sql); @@ -118,7 +118,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver $this->affectedRows = Helpers::false2Null(sqlsrv_rows_affected($res)); return $this->createResultDriver($res); } - return NULL; + return null; } @@ -141,7 +141,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver $row = sqlsrv_fetch_array($res, SQLSRV_FETCH_NUMERIC); return (int) $row[0]; } - return NULL; + return null; } @@ -149,7 +149,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver * Begins a transaction (if supported). * @throws Dibi\DriverException */ - public function begin(string $savepoint = NULL): void + public function begin(string $savepoint = null): void { sqlsrv_begin_transaction($this->connection); } @@ -159,7 +159,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver * Commits statements in a transaction. * @throws Dibi\DriverException */ - public function commit(string $savepoint = NULL): void + public function commit(string $savepoint = null): void { sqlsrv_commit($this->connection); } @@ -169,7 +169,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver * Rollback changes in a transaction. * @throws Dibi\DriverException */ - public function rollback(string $savepoint = NULL): void + public function rollback(string $savepoint = null): void { sqlsrv_rollback($this->connection); } @@ -177,11 +177,11 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver /** * Returns the connection resource. - * @return resource|NULL + * @return resource|null */ public function getResource() { - return is_resource($this->connection) ? $this->connection : NULL; + return is_resource($this->connection) ? $this->connection : null; } @@ -292,11 +292,11 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver if ($offset) { throw new Dibi\NotSupportedException('Offset is not supported by this database.'); - } elseif ($limit !== NULL) { + } elseif ($limit !== null) { $sql = sprintf('SELECT TOP (%d) * FROM (%s) t', $limit, $sql); } - } elseif ($limit !== NULL) { + } elseif ($limit !== null) { // requires ORDER BY, see https://technet.microsoft.com/en-us/library/gg699618(v=sql.110).aspx $sql = sprintf('%s OFFSET %d ROWS FETCH NEXT %d ROWS ONLY', rtrim($sql), $offset, $limit); } elseif ($offset) { @@ -329,7 +329,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver /** * Fetches the row at current position and moves the internal cursor to the next position. - * @param bool TRUE for associative array, FALSE for numeric + * @param bool true for associative array, false for numeric */ public function fetch(bool $assoc): ?array { @@ -352,7 +352,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver public function free(): void { sqlsrv_free_stmt($this->resultSet); - $this->resultSet = NULL; + $this->resultSet = null; } @@ -375,11 +375,11 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver /** * Returns the result set resource. - * @return resource|NULL + * @return resource|null */ public function getResultResource() { - $this->autoFree = FALSE; - return is_resource($this->resultSet) ? $this->resultSet : NULL; + $this->autoFree = false; + return is_resource($this->resultSet) ? $this->resultSet : null; } } diff --git a/src/Dibi/Drivers/SqlsrvReflector.php b/src/Dibi/Drivers/SqlsrvReflector.php index ac83b130..bc72e67b 100644 --- a/src/Dibi/Drivers/SqlsrvReflector.php +++ b/src/Dibi/Drivers/SqlsrvReflector.php @@ -37,7 +37,7 @@ class SqlsrvReflector implements Dibi\Reflector { $res = $this->driver->query("SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES WHERE [TABLE_SCHEMA] = 'dbo'"); $tables = []; - while ($row = $res->fetch(FALSE)) { + while ($row = $res->fetch(false)) { $tables[] = [ 'name' => $row[0], 'view' => isset($row[1]) && $row[1] === 'VIEW', @@ -60,7 +60,7 @@ class SqlsrvReflector implements Dibi\Reflector "); $autoIncrements = []; - while ($row = $res->fetch(TRUE)) { + while ($row = $res->fetch(true)) { $autoIncrements[$row['COLUMN_NAME']] = (bool) $row['AUTO_INCREMENT']; } @@ -80,13 +80,13 @@ class SqlsrvReflector implements Dibi\Reflector WHERE C.TABLE_NAME = {$this->driver->escapeText($table)} "); $columns = []; - while ($row = $res->fetch(TRUE)) { + while ($row = $res->fetch(true)) { $columns[] = [ 'name' => $row['COLUMN_NAME'], 'table' => $table, 'nativetype' => strtoupper($row['DATA_TYPE']), 'size' => $row['CHARACTER_MAXIMUM_LENGTH'], - 'unsigned' => TRUE, + 'unsigned' => true, 'nullable' => $row['IS_NULLABLE'] === 'YES', 'default' => $row['COLUMN_DEFAULT'], 'autoincrement' => $autoIncrements[$row['COLUMN_NAME']], @@ -104,13 +104,13 @@ class SqlsrvReflector implements Dibi\Reflector { $keyUsagesRes = $this->driver->query(sprintf("EXEC [sys].[sp_helpindex] @objname = N%s", $this->driver->escapeText($table))); $keyUsages = []; - while ($row = $keyUsagesRes->fetch(TRUE)) { + while ($row = $keyUsagesRes->fetch(true)) { $keyUsages[$row['index_name']] = explode(',', $row['index_keys']); } $res = $this->driver->query("SELECT [i].* FROM [sys].[indexes] [i] INNER JOIN [sys].[tables] [t] ON [i].[object_id] = [t].[object_id] WHERE [t].[name] = {$this->driver->escapeText($table)}"); $indexes = []; - while ($row = $res->fetch(TRUE)) { + while ($row = $res->fetch(true)) { $indexes[$row['name']]['name'] = $row['name']; $indexes[$row['name']]['unique'] = $row['is_unique'] === 1; $indexes[$row['name']]['primary'] = $row['is_primary_key'] === 1; diff --git a/src/Dibi/Event.php b/src/Dibi/Event.php index 13111cac..2b6a4d66 100644 --- a/src/Dibi/Event.php +++ b/src/Dibi/Event.php @@ -39,7 +39,7 @@ class Event /** @var string */ public $sql; - /** @var Result|DriverException|NULL */ + /** @var Result|DriverException|null */ public $result; /** @var float */ @@ -52,12 +52,12 @@ class Event public $source; - public function __construct(Connection $connection, $type, $sql = NULL) + public function __construct(Connection $connection, $type, $sql = null) { $this->connection = $connection; $this->type = $type; $this->sql = trim($sql); - $this->time = -microtime(TRUE); + $this->time = -microtime(true); if ($type === self::QUERY && preg_match('#\(?\s*(SELECT|UPDATE|INSERT|DELETE)#iA', $this->sql, $matches)) { static $types = [ @@ -76,22 +76,22 @@ class Event } } - \dibi::$elapsedTime = FALSE; + \dibi::$elapsedTime = false; \dibi::$numOfQueries++; \dibi::$sql = $sql; } - public function done($result = NULL) + public function done($result = null) { $this->result = $result; try { - $this->count = $result instanceof Result ? count($result) : NULL; + $this->count = $result instanceof Result ? count($result) : null; } catch (Exception $e) { - $this->count = NULL; + $this->count = null; } - $this->time += microtime(TRUE); + $this->time += microtime(true); \dibi::$elapsedTime = $this->time; \dibi::$totalTime += $this->time; return $this; diff --git a/src/Dibi/Fluent.php b/src/Dibi/Fluent.php index 0c0ba67b..4ccdf571 100644 --- a/src/Dibi/Fluent.php +++ b/src/Dibi/Fluent.php @@ -35,7 +35,7 @@ class Fluent implements IDataSource { use Strict; - const REMOVE = FALSE; + const REMOVE = false; /** @var array */ public static $masks = [ @@ -67,11 +67,11 @@ class Fluent implements IDataSource 'GROUP BY' => ',', 'HAVING' => 'AND', 'ORDER BY' => ',', - 'LIMIT' => FALSE, - 'OFFSET' => FALSE, + 'LIMIT' => false, + 'OFFSET' => false, 'SET' => ',', 'VALUES' => ',', - 'INTO' => FALSE, + 'INTO' => false, ]; /** @var array clauses */ @@ -108,7 +108,7 @@ class Fluent implements IDataSource { $this->connection = $connection; - if (self::$normalizer === NULL) { + if (self::$normalizer === null) { self::$normalizer = new HashMap([__CLASS__, '_formatClause']); } } @@ -122,9 +122,9 @@ class Fluent implements IDataSource $clause = self::$normalizer->$clause; // lazy initialization - if ($this->command === NULL) { + if ($this->command === null) { if (isset(self::$masks[$clause])) { - $this->clauses = array_fill_keys(self::$masks[$clause], NULL); + $this->clauses = array_fill_keys(self::$masks[$clause], null); } $this->cursor = &$this->clauses[$clause]; $this->cursor = []; @@ -142,13 +142,13 @@ class Fluent implements IDataSource // TODO: really delete? if ($args === [self::REMOVE]) { - $this->cursor = NULL; + $this->cursor = null; return $this; } if (isset(self::$separators[$clause])) { $sep = self::$separators[$clause]; - if ($sep === FALSE) { // means: replace + if ($sep === false) { // means: replace $this->cursor = []; } elseif (!empty($this->cursor)) { @@ -165,15 +165,15 @@ class Fluent implements IDataSource $this->cursor[] = $clause; } - if ($this->cursor === NULL) { + if ($this->cursor === null) { $this->cursor = []; } // special types or argument if (count($args) === 1) { $arg = $args[0]; - // TODO: really ignore TRUE? - if ($arg === TRUE) { // flag + // TODO: really ignore true? + if ($arg === true) { // flag return $this; } elseif (is_string($arg) && preg_match('#^[a-z:_][a-z0-9_.:]*\z#i', $arg)) { // identifier @@ -186,7 +186,7 @@ class Fluent implements IDataSource } elseif (is_string(key($arg))) { // associative array $args = ['%a', $arg]; } - } // case $arg === FALSE is handled above + } // case $arg === false is handled above } foreach ($args as $arg) { @@ -206,7 +206,7 @@ class Fluent implements IDataSource public function clause(string $clause): self { $this->cursor = &$this->clauses[self::$normalizer->$clause]; - if ($this->cursor === NULL) { + if ($this->cursor === null) { $this->cursor = []; } @@ -219,7 +219,7 @@ class Fluent implements IDataSource */ public function removeClause(string $clause): self { - $this->clauses[self::$normalizer->$clause] = NULL; + $this->clauses[self::$normalizer->$clause] = null; return $this; } @@ -227,11 +227,11 @@ class Fluent implements IDataSource /** * Change a SQL flag. */ - public function setFlag(string $flag, bool $value = TRUE): self + public function setFlag(string $flag, bool $value = true): self { $flag = strtoupper($flag); if ($value) { - $this->flags[$flag] = TRUE; + $this->flags[$flag] = true; } else { unset($this->flags[$flag]); } @@ -286,7 +286,7 @@ class Fluent implements IDataSource * @return Result|int result set or number of affected rows * @throws Exception */ - public function execute($return = NULL) + public function execute($return = null) { $res = $this->query($this->_export()); switch ($return) { @@ -307,7 +307,7 @@ class Fluent implements IDataSource public function fetch() { if ($this->command === 'SELECT' && !$this->clauses['LIMIT']) { - return $this->query($this->_export(NULL, ['%lmt', 1]))->fetch(); + return $this->query($this->_export(null, ['%lmt', 1]))->fetch(); } else { return $this->query($this->_export())->fetch(); } @@ -316,12 +316,12 @@ class Fluent implements IDataSource /** * Like fetch(), but returns only first field. - * @return mixed value on success, NULL if no next record + * @return mixed value on success, null if no next record */ public function fetchSingle() { if ($this->command === 'SELECT' && !$this->clauses['LIMIT']) { - return $this->query($this->_export(NULL, ['%lmt', 1]))->fetchSingle(); + return $this->query($this->_export(null, ['%lmt', 1]))->fetchSingle(); } else { return $this->query($this->_export())->fetchSingle(); } @@ -331,9 +331,9 @@ class Fluent implements IDataSource /** * Fetches all records from table. */ - public function fetchAll(int $offset = NULL, int $limit = NULL): array + public function fetchAll(int $offset = null, int $limit = null): array { - return $this->query($this->_export(NULL, ['%ofs %lmt', $offset, $limit]))->fetchAll(); + return $this->query($this->_export(null, ['%ofs %lmt', $offset, $limit]))->fetchAll(); } @@ -351,7 +351,7 @@ class Fluent implements IDataSource * Fetches all records from table like $key => $value pairs. * @param string associative key */ - public function fetchPairs(string $key = NULL, string $value = NULL): array + public function fetchPairs(string $key = null, string $value = null): array { return $this->query($this->_export())->fetchPairs($key, $value); } @@ -360,9 +360,9 @@ class Fluent implements IDataSource /** * Required by the IteratorAggregate interface. */ - public function getIterator(int $offset = NULL, int $limit = NULL): ResultIterator + public function getIterator(int $offset = null, int $limit = null): ResultIterator { - return $this->query($this->_export(NULL, ['%ofs %lmt', $offset, $limit]))->getIterator(); + return $this->query($this->_export(null, ['%ofs %lmt', $offset, $limit]))->getIterator(); } @@ -370,7 +370,7 @@ class Fluent implements IDataSource * Generates and prints SQL query or it's part. * @param string clause name */ - public function test(string $clause = NULL): bool + public function test(string $clause = null): bool { return $this->connection->test($this->_export($clause)); } @@ -421,9 +421,9 @@ class Fluent implements IDataSource * Generates parameters for Translator. * @param string clause name */ - protected function _export(string $clause = NULL, array $args = []): array + protected function _export(string $clause = null, array $args = []): array { - if ($clause === NULL) { + if ($clause === null) { $data = $this->clauses; if ($this->command === 'SELECT' && ($data['LIMIT'] || $data['OFFSET'])) { $args = array_merge(['%lmt %ofs', $data['LIMIT'][0], $data['OFFSET'][0]], $args); @@ -440,7 +440,7 @@ class Fluent implements IDataSource } foreach ($data as $clause => $statement) { - if ($statement !== NULL) { + if ($statement !== null) { $args[] = $clause; if ($clause === $this->command && $this->flags) { $args[] = implode(' ', array_keys($this->flags)); diff --git a/src/Dibi/Helpers.php b/src/Dibi/Helpers.php index 539b769b..2b1012f9 100644 --- a/src/Dibi/Helpers.php +++ b/src/Dibi/Helpers.php @@ -22,7 +22,7 @@ class Helpers * Prints out a syntax highlighted version of the SQL command or Result. * @param string|Result */ - public static function dump($sql = NULL, bool $return = FALSE): string + public static function dump($sql = null, bool $return = false): string { ob_start(); if ($sql instanceof Result && PHP_SAPI === 'cli') { @@ -68,7 +68,7 @@ class Helpers : "\n\n"; } else { - if ($sql === NULL) { + if ($sql === null) { $sql = \dibi::$sql; } @@ -140,7 +140,7 @@ class Helpers */ public static function getSuggestion(array $items, $value): ?string { - $best = NULL; + $best = null; $min = (strlen($value) / 4 + 1) * 10 + .1; foreach (array_unique($items, SORT_REGULAR) as $item) { $item = is_object($item) ? $item->getName() : $item; @@ -195,7 +195,7 @@ class Helpers return $val; } } - return NULL; + return null; } @@ -204,7 +204,7 @@ class Helpers */ public static function getTypeCache() { - if (self::$types === NULL) { + if (self::$types === null) { self::$types = new HashMap([__CLASS__, 'detectType']); } return self::$types; @@ -232,7 +232,7 @@ class Helpers * Import SQL dump from file. * @return int count of sql commands */ - public static function loadFromFile(Connection $connection, $file, callable $onProgress = NULL): int + public static function loadFromFile(Connection $connection, $file, callable $onProgress = null): int { @set_time_limit(0); // intentionally @ @@ -246,7 +246,7 @@ class Helpers $delimiter = ';'; $sql = ''; $driver = $connection->getDriver(); - while (($s = fgets($handle)) !== FALSE) { + while (($s = fgets($handle)) !== false) { $size += strlen($s); if (strtoupper(substr($s, 0, 10)) === 'DELIMITER ') { $delimiter = trim(substr($s, 10)); @@ -257,7 +257,7 @@ class Helpers $sql = ''; $count++; if ($onProgress) { - $onProgress($count, isset($stat['size']) ? $size * 100 / $stat['size'] : NULL); + $onProgress($count, isset($stat['size']) ? $size * 100 / $stat['size'] : null); } } else { @@ -269,7 +269,7 @@ class Helpers $driver->query($sql); $count++; if ($onProgress) { - $onProgress($count, isset($stat['size']) ? 100 : NULL); + $onProgress($count, isset($stat['size']) ? 100 : null); } } fclose($handle); @@ -282,6 +282,6 @@ class Helpers */ public static function false2Null($val) { - return $val === FALSE ? NULL : $val; + return $val === false ? null : $val; } } diff --git a/src/Dibi/Loggers/FileLogger.php b/src/Dibi/Loggers/FileLogger.php index cdb50f0e..c0bdb49d 100644 --- a/src/Dibi/Loggers/FileLogger.php +++ b/src/Dibi/Loggers/FileLogger.php @@ -26,7 +26,7 @@ class FileLogger public $filter; - public function __construct(string $file, int $filter = NULL) + public function __construct(string $file, int $filter = null) { $this->file = $file; $this->filter = $filter ?: Dibi\Event::QUERY; diff --git a/src/Dibi/Loggers/FirePhpLogger.php b/src/Dibi/Loggers/FirePhpLogger.php index 02ed083a..00732756 100644 --- a/src/Dibi/Loggers/FirePhpLogger.php +++ b/src/Dibi/Loggers/FirePhpLogger.php @@ -47,7 +47,7 @@ class FirePhpLogger } - public function __construct(int $filter = NULL) + public function __construct(int $filter = null) { $this->filter = $filter ?: Dibi\Event::QUERY; } diff --git a/src/Dibi/Reflection/Column.php b/src/Dibi/Reflection/Column.php index 29e7a935..ac6f3037 100644 --- a/src/Dibi/Reflection/Column.php +++ b/src/Dibi/Reflection/Column.php @@ -21,24 +21,24 @@ use Dibi\Type; * @property-read Table $table * @property-read string $type * @property-read mixed $nativeType - * @property-read int|NULL $size - * @property-read bool|NULL $unsigned - * @property-read bool|NULL $nullable - * @property-read bool|NULL $autoIncrement + * @property-read int|null $size + * @property-read bool|null $unsigned + * @property-read bool|null $nullable + * @property-read bool|null $autoIncrement * @property-read mixed $default */ class Column { use Dibi\Strict; - /** @var Dibi\Reflector|NULL when created by Result */ + /** @var Dibi\Reflector|null when created by Result */ private $reflector; /** @var array (name, nativetype, [table], [fullname], [size], [nullable], [default], [autoincrement], [vendor]) */ private $info; - public function __construct(Dibi\Reflector $reflector = NULL, array $info) + public function __construct(Dibi\Reflector $reflector = null, array $info) { $this->reflector = $reflector; $this->info = $info; @@ -53,7 +53,7 @@ class Column public function getFullName(): string { - return $this->info['fullname'] ?? NULL; + return $this->info['fullname'] ?? null; } @@ -74,7 +74,7 @@ class Column public function getTableName(): ?string { - return isset($this->info['table']) && $this->info['table'] != NULL ? $this->info['table'] : NULL; // intentionally == + return isset($this->info['table']) && $this->info['table'] != null ? $this->info['table'] : null; // intentionally == } @@ -92,25 +92,25 @@ class Column public function getSize(): ?int { - return isset($this->info['size']) ? (int) $this->info['size'] : NULL; + return isset($this->info['size']) ? (int) $this->info['size'] : null; } public function isUnsigned(): ?bool { - return isset($this->info['unsigned']) ? (bool) $this->info['unsigned'] : NULL; + return isset($this->info['unsigned']) ? (bool) $this->info['unsigned'] : null; } public function isNullable(): ?bool { - return isset($this->info['nullable']) ? (bool) $this->info['nullable'] : NULL; + return isset($this->info['nullable']) ? (bool) $this->info['nullable'] : null; } public function isAutoIncrement(): ?bool { - return isset($this->info['autoincrement']) ? (bool) $this->info['autoincrement'] : NULL; + return isset($this->info['autoincrement']) ? (bool) $this->info['autoincrement'] : null; } @@ -119,7 +119,7 @@ class Column */ public function getDefault() { - return $this->info['default'] ?? NULL; + return $this->info['default'] ?? null; } @@ -128,6 +128,6 @@ class Column */ public function getVendorInfo(string $key) { - return $this->info['vendor'][$key] ?? NULL; + return $this->info['vendor'][$key] ?? null; } } diff --git a/src/Dibi/Reflection/Database.php b/src/Dibi/Reflection/Database.php index 83422411..ebf25155 100644 --- a/src/Dibi/Reflection/Database.php +++ b/src/Dibi/Reflection/Database.php @@ -92,7 +92,7 @@ class Database protected function init(): void { - if ($this->tables === NULL) { + if ($this->tables === null) { $this->tables = []; foreach ($this->reflector->getTables() as $info) { $this->tables[strtolower($info['name'])] = new Table($this->reflector, $info); diff --git a/src/Dibi/Reflection/Result.php b/src/Dibi/Reflection/Result.php index f7ca85b5..06db575c 100644 --- a/src/Dibi/Reflection/Result.php +++ b/src/Dibi/Reflection/Result.php @@ -51,7 +51,7 @@ class Result /** * @return string[] */ - public function getColumnNames(bool $fullNames = FALSE): array + public function getColumnNames(bool $fullNames = false): array { $this->initColumns(); $res = []; @@ -84,9 +84,9 @@ class Result protected function initColumns(): void { - if ($this->columns === NULL) { + if ($this->columns === null) { $this->columns = []; - $reflector = $this->driver instanceof Dibi\Reflector ? $this->driver : NULL; + $reflector = $this->driver instanceof Dibi\Reflector ? $this->driver : null; foreach ($this->driver->getResultColumns() as $info) { $this->columns[] = $this->names[strtolower($info['name'])] = new Column($reflector, $info); } diff --git a/src/Dibi/Reflection/Table.php b/src/Dibi/Reflection/Table.php index e0cea327..c439c99d 100644 --- a/src/Dibi/Reflection/Table.php +++ b/src/Dibi/Reflection/Table.php @@ -142,7 +142,7 @@ class Table protected function initColumns(): void { - if ($this->columns === NULL) { + if ($this->columns === null) { $this->columns = []; foreach ($this->reflector->getColumns($this->name) as $info) { $this->columns[strtolower($info['name'])] = new Column($this->reflector, $info); @@ -153,7 +153,7 @@ class Table protected function initIndexes(): void { - if ($this->indexes === NULL) { + if ($this->indexes === null) { $this->initColumns(); $this->indexes = []; foreach ($this->reflector->getIndexes($this->name) as $info) { diff --git a/src/Dibi/Result.php b/src/Dibi/Result.php index b7732368..4503e85c 100644 --- a/src/Dibi/Result.php +++ b/src/Dibi/Result.php @@ -42,7 +42,7 @@ class Result implements IDataSource private $meta; /** @var bool Already fetched? Used for allowance for first seek(0) */ - private $fetched = FALSE; + private $fetched = false; /** @var string returned object class */ private $rowClass = Row::class; @@ -66,9 +66,9 @@ class Result implements IDataSource */ final public function free(): void { - if ($this->driver !== NULL) { + if ($this->driver !== null) { $this->driver->free(); - $this->driver = $this->meta = NULL; + $this->driver = $this->meta = null; } } @@ -79,7 +79,7 @@ class Result implements IDataSource */ final public function getResultDriver(): ResultDriver { - if ($this->driver === NULL) { + if ($this->driver === null) { throw new \RuntimeException('Result-set was released from memory.'); } @@ -96,7 +96,7 @@ class Result implements IDataSource */ final public function seek(int $row): bool { - return ($row !== 0 || $this->fetched) ? (bool) $this->getResultDriver()->seek($row) : TRUE; + return ($row !== 0 || $this->fetched) ? (bool) $this->getResultDriver()->seek($row) : true; } @@ -165,11 +165,11 @@ class Result implements IDataSource */ final public function fetch(): ?Row { - $row = $this->getResultDriver()->fetch(TRUE); - if ($row === NULL) { - return NULL; + $row = $this->getResultDriver()->fetch(true); + if ($row === null) { + return null; } - $this->fetched = TRUE; + $this->fetched = true; $this->normalize($row); if ($this->rowFactory) { return ($this->rowFactory)($row); @@ -182,15 +182,15 @@ class Result implements IDataSource /** * Like fetch(), but returns only first field. - * @return mixed value on success, NULL if no next record + * @return mixed value on success, null if no next record */ final public function fetchSingle() { - $row = $this->getResultDriver()->fetch(TRUE); - if ($row === NULL) { - return NULL; + $row = $this->getResultDriver()->fetch(true); + if ($row === null) { + return null; } - $this->fetched = TRUE; + $this->fetched = true; $this->normalize($row); return reset($row); } @@ -200,9 +200,9 @@ class Result implements IDataSource * Fetches all records from table. * @return Row[] */ - final public function fetchAll(int $offset = NULL, int $limit = NULL): array + final public function fetchAll(int $offset = null, int $limit = null): array { - $limit = $limit === NULL ? -1 : $limit; + $limit = $limit === null ? -1 : $limit; $this->seek($offset ?: 0); $row = $this->fetch(); if (!$row) { @@ -233,7 +233,7 @@ class Result implements IDataSource */ final public function fetchAssoc(string $assoc): array { - if (strpos($assoc, ',') !== FALSE) { + if (strpos($assoc, ',') !== false) { return $this->oldFetchAssoc($assoc); } @@ -243,12 +243,12 @@ class Result implements IDataSource return []; // empty result set } - $data = NULL; + $data = null; $assoc = preg_split('#(\[\]|->|=|\|)#', $assoc, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); // check columns foreach ($assoc as $as) { - // offsetExists ignores NULL in PHP 5.2.1, isset() surprisingly NULL accepts + // offsetExists ignores null in PHP 5.2.1, isset() surprisingly null accepts if ($as !== '[]' && $as !== '=' && $as !== '->' && $as !== '|' && !property_exists($row, $as)) { throw new \InvalidArgumentException("Unknown column '$as' in associative descriptor."); } @@ -276,10 +276,10 @@ class Result implements IDataSource continue 2; } elseif ($as === '->') { // "object" node - if ($x === NULL) { + if ($x === null) { $x = clone $row; $x = &$x->{$assoc[$i + 1]}; - $x = NULL; // prepare child node + $x = null; // prepare child node } else { $x = &$x->{$assoc[$i + 1]}; } @@ -289,7 +289,7 @@ class Result implements IDataSource } } - if ($x === NULL) { // build leaf + if ($x === null) { // build leaf $x = $row; } } while ($row = $this->fetch()); @@ -310,7 +310,7 @@ class Result implements IDataSource return []; // empty result set } - $data = NULL; + $data = null; $assoc = explode(',', $assoc); // strip leading = and @ @@ -335,19 +335,19 @@ class Result implements IDataSource $x = &$x[]; } elseif ($as === '=') { // "record" node - if ($x === NULL) { + if ($x === null) { $x = $row->toArray(); $x = &$x[ $assoc[$i + 1] ]; - $x = NULL; // prepare child node + $x = null; // prepare child node } else { $x = &$x[ $assoc[$i + 1] ]; } } elseif ($as === '@') { // "object" node - if ($x === NULL) { + if ($x === null) { $x = clone $row; $x = &$x->{$assoc[$i + 1]}; - $x = NULL; // prepare child node + $x = null; // prepare child node } else { $x = &$x->{$assoc[$i + 1]}; } @@ -357,7 +357,7 @@ class Result implements IDataSource } } - if ($x === NULL) { // build leaf + if ($x === null) { // build leaf if ($leaf === '=') { $x = $row->toArray(); } else { @@ -375,7 +375,7 @@ class Result implements IDataSource * Fetches all records from table like $key => $value pairs. * @throws \InvalidArgumentException */ - final public function fetchPairs(string $key = NULL, string $value = NULL): array + final public function fetchPairs(string $key = null, string $value = null): array { $this->seek(0); $row = $this->fetch(); @@ -385,8 +385,8 @@ class Result implements IDataSource $data = []; - if ($value === NULL) { - if ($key !== NULL) { + if ($value === null) { + if ($key !== null) { throw new \InvalidArgumentException('Either none or both columns must be specified.'); } @@ -407,7 +407,7 @@ class Result implements IDataSource throw new \InvalidArgumentException("Unknown value column '$value'."); } - if ($key === NULL) { // indexed-array + if ($key === null) { // indexed-array do { $data[] = $row[$value]; } while ($row = $this->fetch()); @@ -451,7 +451,7 @@ class Result implements IDataSource private function normalize(array &$row): void { foreach ($this->types as $key => $type) { - if (!isset($row[$key])) { // NULL + if (!isset($row[$key])) { // null continue; } $value = $row[$key]; @@ -466,7 +466,7 @@ class Result implements IDataSource } elseif ($type === Type::FLOAT) { $value = ltrim((string) $value, '0'); $p = strpos($value, '.'); - if ($p !== FALSE) { + if ($p !== false) { $value = rtrim(rtrim($value, '0'), '.'); } if ($value === '' || $value[0] === '.') { @@ -480,11 +480,11 @@ class Result implements IDataSource $row[$key] = ((bool) $value) && $value !== 'f' && $value !== 'F'; } elseif ($type === Type::DATETIME || $type === Type::DATE || $type === Type::TIME) { - if ($value && substr((string) $value, 0, 3) !== '000') { // '', NULL, FALSE, '0000-00-00', ... + if ($value && substr((string) $value, 0, 3) !== '000') { // '', null, false, '0000-00-00', ... $value = new DateTime($value); $row[$key] = empty($this->formats[$type]) ? $value : $value->format($this->formats[$type]); } else { - $row[$key] = NULL; + $row[$key] = null; } } elseif ($type === Type::TIME_INTERVAL) { @@ -515,7 +515,7 @@ class Result implements IDataSource */ final public function getType($column): string { - return $this->types[$column] ?? NULL; + return $this->types[$column] ?? null; } @@ -534,7 +534,7 @@ class Result implements IDataSource */ final public function getFormat($type): ?string { - return $this->formats[$type] ?? NULL; + return $this->formats[$type] ?? null; } @@ -546,7 +546,7 @@ class Result implements IDataSource */ public function getInfo(): Reflection\Result { - if ($this->meta === NULL) { + if ($this->meta === null) { $this->meta = new Reflection\Result($this->getResultDriver()); } return $this->meta; diff --git a/src/Dibi/Row.php b/src/Dibi/Row.php index fbff6b5e..3ff38393 100644 --- a/src/Dibi/Row.php +++ b/src/Dibi/Row.php @@ -32,16 +32,16 @@ class Row implements \ArrayAccess, \IteratorAggregate, \Countable /** * Converts value to DateTime object. */ - public function asDateTime(string $key, string $format = NULL): \DateTime + public function asDateTime(string $key, string $format = null): \DateTime { $time = $this[$key]; if (!$time instanceof DateTime) { - if (!$time || substr((string) $time, 0, 3) === '000') { // '', NULL, FALSE, '0000-00-00', ... - return NULL; + if (!$time || substr((string) $time, 0, 3) === '000') { // '', null, false, '0000-00-00', ... + return null; } $time = new DateTime($time); } - return $format === NULL ? $time : $time->format($format); + return $format === null ? $time : $time->format($format); } diff --git a/src/Dibi/Strict.php b/src/Dibi/Strict.php index 05b1cd6b..3365e446 100644 --- a/src/Dibi/Strict.php +++ b/src/Dibi/Strict.php @@ -87,7 +87,7 @@ trait Strict public function __isset($name): bool { - return FALSE; + return false; } @@ -105,9 +105,9 @@ trait Strict /** * @return mixed */ - public static function extensionMethod(string $name, callable $callback = NULL) + public static function extensionMethod(string $name, callable $callback = null) { - if (strpos($name, '::') === FALSE) { + if (strpos($name, '::') === false) { $class = get_called_class(); } else { [$class, $name] = explode('::', $name); @@ -115,7 +115,7 @@ trait Strict } $list = & self::$extMethods[strtolower($name)]; - if ($callback === NULL) { // getter + if ($callback === null) { // getter $cache = &$list[''][$class]; if (isset($cache)) { return $cache; @@ -126,11 +126,11 @@ trait Strict return $cache = $list[$cl]; } } - return $cache = FALSE; + return $cache = false; } else { // setter $list[$class] = $callback; - $list[''] = NULL; + $list[''] = null; } } } diff --git a/src/Dibi/Translator.php b/src/Dibi/Translator.php index 0aee2efd..9df5553c 100644 --- a/src/Dibi/Translator.php +++ b/src/Dibi/Translator.php @@ -33,7 +33,7 @@ final class Translator private $errors; /** @var bool */ - private $comment = FALSE; + private $comment = false; /** @var int */ private $ifLevel = 0; @@ -71,8 +71,8 @@ final class Translator } $this->args = $args; - $commandIns = NULL; - $lastArr = NULL; + $commandIns = null; + $lastArr = null; $cursor = &$this->cursor; $comment = &$this->comment; @@ -127,7 +127,7 @@ final class Translator if (is_array($arg) && is_string(key($arg))) { // associative array -> autoselect between SET or VALUES & LIST - if ($commandIns === NULL) { + if ($commandIns === null) { $commandIns = strtoupper(substr(ltrim($this->args[0]), 0, 6)); $commandIns = $commandIns === 'INSERT' || $commandIns === 'REPLAC'; $sql[] = $this->formatValue($arg, $commandIns ? 'v' : 'a'); @@ -142,7 +142,7 @@ final class Translator } // default processing - $sql[] = $this->formatValue($arg, NULL); + $sql[] = $this->formatValue($arg, null); } // while @@ -157,7 +157,7 @@ final class Translator } // apply limit - if ($this->limit !== NULL || $this->offset !== NULL) { + if ($this->limit !== null || $this->offset !== null) { $this->driver->applyLimit($sql, $this->limit, $this->offset); } @@ -194,7 +194,7 @@ final class Translator $pair = explode('%', $k, 2); // split into identifier & modifier $k = $this->identifiers->{$pair[0]} . ' '; if (!isset($pair[1])) { - $v = $this->formatValue($v, NULL); + $v = $this->formatValue($v, null); $vx[] = $k . ($v === 'NULL' ? 'IS ' : '= ') . $v; } elseif ($pair[1] === 'ex') { @@ -204,7 +204,7 @@ final class Translator $v = $this->formatValue($v, $pair[1]); if ($pair[1] === 'l' || $pair[1] === 'in') { $op = 'IN '; - } elseif (strpos($pair[1], 'like') !== FALSE) { + } elseif (strpos($pair[1], 'like') !== false) { $op = 'LIKE '; } elseif ($v === 'NULL') { $op = 'IS '; @@ -236,7 +236,7 @@ final class Translator foreach ($value as $k => $v) { $pair = explode('%', $k, 2); // split into identifier & modifier $vx[] = $this->identifiers->{$pair[0]} . '=' - . $this->formatValue($v, $pair[1] ?? (is_array($v) ? 'ex' : NULL)); + . $this->formatValue($v, $pair[1] ?? (is_array($v) ? 'ex' : null)); } return implode(', ', $vx); @@ -245,7 +245,7 @@ final class Translator case 'l': // (val, val, ...) foreach ($value as $k => $v) { $pair = explode('%', (string) $k, 2); // split into identifier & modifier - $vx[] = $this->formatValue($v, $pair[1] ?? (is_array($v) ? 'ex' : NULL)); + $vx[] = $this->formatValue($v, $pair[1] ?? (is_array($v) ? 'ex' : null)); } return '(' . (($vx || $modifier === 'l') ? implode(', ', $vx) : 'NULL') . ')'; @@ -254,7 +254,7 @@ final class Translator foreach ($value as $k => $v) { $pair = explode('%', $k, 2); // split into identifier & modifier $kx[] = $this->identifiers->{$pair[0]}; - $vx[] = $this->formatValue($v, $pair[1] ?? (is_array($v) ? 'ex' : NULL)); + $vx[] = $this->formatValue($v, $pair[1] ?? (is_array($v) ? 'ex' : null)); } return '(' . implode(', ', $kx) . ') VALUES (' . implode(', ', $vx) . ')'; @@ -275,7 +275,7 @@ final class Translator $pair = explode('%', $k, 2); // split into identifier & modifier $kx[] = $this->identifiers->{$pair[0]}; foreach ($v as $k2 => $v2) { - $vx[$k2][] = $this->formatValue($v2, $pair[1] ?? (is_array($v2) ? 'ex' : NULL)); + $vx[$k2][] = $this->formatValue($v2, $pair[1] ?? (is_array($v2) ? 'ex' : null)); } } foreach ($vx as $k => $v) { @@ -311,7 +311,7 @@ final class Translator // with modifier procession if ($modifier) { - if ($value !== NULL && !is_scalar($value)) { // array is already processed + if ($value !== null && !is_scalar($value)) { // array is already processed if ($value instanceof Literal && ($modifier === 'sql' || $modifier === 'SQL')) { $modifier = 'SQL'; } elseif ($value instanceof \DateTimeInterface && ($modifier === 'd' || $modifier === 't')) { @@ -324,27 +324,27 @@ final class Translator switch ($modifier) { case 's': // string - return $value === NULL ? 'NULL' : $this->driver->escapeText((string) $value); + return $value === null ? 'NULL' : $this->driver->escapeText((string) $value); case 'bin':// binary - return $value === NULL ? 'NULL' : $this->driver->escapeBinary($value); + return $value === null ? 'NULL' : $this->driver->escapeBinary($value); case 'b': // boolean - return $value === NULL ? 'NULL' : $this->driver->escapeBool($value); + return $value === null ? 'NULL' : $this->driver->escapeBool($value); - case 'sN': // string or NULL + case 'sN': // string or null case 'sn': return $value == '' ? 'NULL' : $this->driver->escapeText((string) $value); // notice two equal signs - case 'iN': // signed int or NULL + case 'iN': // signed int or null if ($value == '') { - $value = NULL; + $value = null; } // intentionally break omitted case 'i': // signed int case 'u': // unsigned int, ignored - if ($value === NULL) { + if ($value === null) { return 'NULL'; } elseif (is_string($value) && preg_match('#[+-]?\d++(?:e\d+)?\z#A', $value)) { return $value; // support for long numbers - keep them unchanged @@ -353,7 +353,7 @@ final class Translator } case 'f': // float - if ($value === NULL) { + if ($value === null) { return 'NULL'; } elseif (is_string($value) && is_numeric($value) && substr($value, 1, 1) !== 'x') { return $value; // support for extreme numbers - keep them unchanged @@ -364,7 +364,7 @@ final class Translator case 'd': // date case 't': // datetime case 'dt': // datetime - if ($value === NULL) { + if ($value === null) { return 'NULL'; } else { return $modifier === 'd' ? $this->driver->escapeDate($value) : $this->driver->escapeDateTime($value); @@ -434,7 +434,7 @@ final class Translator } elseif (is_bool($value)) { return $this->driver->escapeBool($value); - } elseif ($value === NULL) { + } elseif ($value === null) { return 'NULL'; } elseif ($value instanceof \DateTimeInterface) { @@ -476,7 +476,7 @@ final class Translator } $cursor++; - return $this->formatValue($this->args[$cursor - 1], NULL); + return $this->formatValue($this->args[$cursor - 1], null); } if (!empty($matches[10])) { // modifier @@ -493,7 +493,7 @@ final class Translator if (!$this->comment && !$this->args[$cursor - 1]) { // open comment $this->ifLevelStart = $this->ifLevel; - $this->comment = TRUE; + $this->comment = true; return '/*'; } return ''; @@ -501,11 +501,11 @@ final class Translator } elseif ($mod === 'else') { if ($this->ifLevelStart === $this->ifLevel) { $this->ifLevelStart = 0; - $this->comment = FALSE; + $this->comment = false; return '*/'; } elseif (!$this->comment) { $this->ifLevelStart = $this->ifLevel; - $this->comment = TRUE; + $this->comment = true; return '/*'; } @@ -514,7 +514,7 @@ final class Translator if ($this->ifLevelStart === $this->ifLevel + 1) { // close comment $this->ifLevelStart = 0; - $this->comment = FALSE; + $this->comment = false; return '*/'; } return ''; @@ -525,7 +525,7 @@ final class Translator } elseif ($mod === 'lmt') { // apply limit $arg = $this->args[$cursor++]; - if ($arg === NULL) { + if ($arg === null) { } elseif ($this->comment) { return "(limit $arg)"; } else { @@ -535,7 +535,7 @@ final class Translator } elseif ($mod === 'ofs') { // apply offset $arg = $this->args[$cursor++]; - if ($arg === NULL) { + if ($arg === null) { } elseif ($this->comment) { return "(offset $arg)"; } else { @@ -572,7 +572,7 @@ final class Translator if ($matches[8]) { // SQL identifier substitution $m = substr($matches[8], 0, -1); $m = $this->connection->getSubstitutes()->$m; - return $matches[9] == '' ? $this->formatValue($m, NULL) : $m . $matches[9]; // value or identifier + return $matches[9] == '' ? $this->formatValue($m, null) : $m . $matches[9]; // value or identifier } throw new \Exception('this should be never executed'); diff --git a/src/Dibi/dibi.php b/src/Dibi/dibi.php index d38271d5..c0764081 100644 --- a/src/Dibi/dibi.php +++ b/src/Dibi/dibi.php @@ -83,11 +83,11 @@ class dibi /** - * Returns TRUE when connection was established. + * Returns true when connection was established. */ public static function isConnected(): bool { - return (self::$connection !== NULL) && self::$connection->isConnected(); + return (self::$connection !== null) && self::$connection->isConnected(); } @@ -95,10 +95,10 @@ class dibi * Retrieve active connection. * @throws Dibi\Exception */ - public static function getConnection(string $name = NULL): Dibi\Connection + public static function getConnection(string $name = null): Dibi\Connection { - if ($name === NULL) { - if (self::$connection === NULL) { + if ($name === null) { + if (self::$connection === null) { throw new Dibi\Exception('Dibi is not connected to database.'); } @@ -240,7 +240,7 @@ class dibi * Monostate for Dibi\Connection::getInsertId() * @throws Dibi\Exception */ - public static function getInsertId(string $sequence = NULL): int + public static function getInsertId(string $sequence = null): int { return self::getConnection()->getInsertId($sequence); } @@ -250,7 +250,7 @@ class dibi * Retrieves the ID generated for an AUTO_INCREMENT column. Alias for getInsertId(). * @throws Dibi\Exception */ - public static function insertId(string $sequence = NULL): int + public static function insertId(string $sequence = null): int { return self::getConnection()->getInsertId($sequence); } @@ -260,17 +260,17 @@ class dibi * Begins a transaction - Monostate for Dibi\Connection::begin(). * @throws Dibi\Exception */ - public static function begin(string $savepoint = NULL): void + public static function begin(string $savepoint = null): void { self::getConnection()->begin($savepoint); } /** - * Commits statements in a transaction - Monostate for Dibi\Connection::commit($savepoint = NULL). + * Commits statements in a transaction - Monostate for Dibi\Connection::commit($savepoint = null). * @throws Dibi\Exception */ - public static function commit(string $savepoint = NULL): void + public static function commit(string $savepoint = null): void { self::getConnection()->commit($savepoint); } @@ -280,7 +280,7 @@ class dibi * Rollback changes in a transaction - Monostate for Dibi\Connection::rollback(). * @throws Dibi\Exception */ - public static function rollback(string $savepoint = NULL): void + public static function rollback(string $savepoint = null): void { self::getConnection()->rollback($savepoint); } @@ -358,7 +358,7 @@ class dibi * @param string|Result * @param bool return output instead of printing it? */ - public static function dump($sql = NULL, bool $return = FALSE): string + public static function dump($sql = null, bool $return = false): string { return Dibi\Helpers::dump($sql, $return); } diff --git a/src/Dibi/exceptions.php b/src/Dibi/exceptions.php index 4ad6644d..dc52951c 100644 --- a/src/Dibi/exceptions.php +++ b/src/Dibi/exceptions.php @@ -15,14 +15,14 @@ namespace Dibi; */ class Exception extends \Exception { - /** @var string|NULL */ + /** @var string|null */ private $sql; /** * Construct a dibi exception. */ - public function __construct(string $message = '', $code = 0, string $sql = NULL) + public function __construct(string $message = '', $code = 0, string $sql = null) { parent::__construct($message); $this->code = $code; @@ -93,7 +93,7 @@ class ProcedureException extends Exception /** * Construct the exception. */ - public function __construct(string $message = NULL, int $code = 0, string $severity = NULL, $sql = NULL) + public function __construct(string $message = null, int $code = 0, string $severity = null, $sql = null) { parent::__construct($message, $code, $sql); $this->severity = $severity; diff --git a/src/Dibi/interfaces.php b/src/Dibi/interfaces.php index 0363507c..35fd217c 100644 --- a/src/Dibi/interfaces.php +++ b/src/Dibi/interfaces.php @@ -58,19 +58,19 @@ interface Driver * Begins a transaction (if supported). * @throws DriverException */ - function begin(string $savepoint = NULL): void; + function begin(string $savepoint = null): void; /** * Commits statements in a transaction. * @throws DriverException */ - function commit(string $savepoint = NULL): void; + function commit(string $savepoint = null): void; /** * Rollback changes in a transaction. * @throws DriverException */ - function rollback(string $savepoint = NULL): void; + function rollback(string $savepoint = null): void; /** * Returns the connection resource. @@ -129,14 +129,14 @@ interface ResultDriver /** * Moves cursor position without fetching row. - * @return bool TRUE on success, FALSE if unable to seek to specified record + * @return bool true on success, false if unable to seek to specified record * @throws Exception */ function seek(int $row): bool; /** * Fetches the row at current position and moves the internal cursor to the next position. - * @param bool TRUE for associative array, FALSE for numeric + * @param bool true for associative array, false for numeric * @internal */ function fetch(bool $type): ?array; diff --git a/tests/dibi/Connection.connect.phpt b/tests/dibi/Connection.connect.phpt index 36238565..44e84eca 100644 --- a/tests/dibi/Connection.connect.phpt +++ b/tests/dibi/Connection.connect.phpt @@ -22,7 +22,7 @@ test(function () use ($config) { test(function () use ($config) { // lazy - $conn = new Connection($config + ['lazy' => TRUE]); + $conn = new Connection($config + ['lazy' => true]); Assert::false($conn->isConnected()); $conn->query('SELECT 1'); diff --git a/tests/dibi/Fluent.delete.phpt b/tests/dibi/Fluent.delete.phpt index c18e2ed1..5a0a9771 100644 --- a/tests/dibi/Fluent.delete.phpt +++ b/tests/dibi/Fluent.delete.phpt @@ -31,7 +31,7 @@ Assert::same( (string) $fluent ); -$fluent->setFlag('IGNORE', FALSE); +$fluent->setFlag('IGNORE', false); Assert::same( reformat('DELETE FROM [anotherTable] USING [thirdTable]'), diff --git a/tests/dibi/Fluent.fetch.limit.mssql.phpt b/tests/dibi/Fluent.fetch.limit.mssql.phpt index c5bb7ded..1e8b002f 100644 --- a/tests/dibi/Fluent.fetch.limit.mssql.phpt +++ b/tests/dibi/Fluent.fetch.limit.mssql.phpt @@ -32,7 +32,7 @@ class MockDriver extends Dibi\Drivers\SqlsrvDriver function fetch(bool $type): ?array { - return NULL; + return null; } } diff --git a/tests/dibi/Fluent.insert.phpt b/tests/dibi/Fluent.insert.phpt index 72e6254b..7b97e403 100644 --- a/tests/dibi/Fluent.insert.phpt +++ b/tests/dibi/Fluent.insert.phpt @@ -12,7 +12,7 @@ $conn = new Dibi\Connection($config); $arr = [ 'title' => 'Super Product', 'price' => 12, - 'brand' => NULL, + 'brand' => null, ]; $fluent = $conn->insert('table', $arr) @@ -23,7 +23,7 @@ Assert::same( (string) $fluent ); -$fluent->setFlag('IGNORE', FALSE); +$fluent->setFlag('IGNORE', false); Assert::same( reformat('INSERT DELAYED INTO [table] ([title], [price], [brand]) VALUES (\'Super Product\', 12, NULL)'), diff --git a/tests/dibi/Fluent.update.phpt b/tests/dibi/Fluent.update.phpt index b68530a4..d4d160d0 100644 --- a/tests/dibi/Fluent.update.phpt +++ b/tests/dibi/Fluent.update.phpt @@ -12,7 +12,7 @@ $conn = new Dibi\Connection($config); $arr = [ 'title' => 'Super Product', 'price' => 12, - 'brand' => NULL, + 'brand' => null, ]; $fluent = $conn->update('table', $arr) diff --git a/tests/dibi/Helpers.getSuggestion().phpt b/tests/dibi/Helpers.getSuggestion().phpt index 813587cc..317a14a9 100644 --- a/tests/dibi/Helpers.getSuggestion().phpt +++ b/tests/dibi/Helpers.getSuggestion().phpt @@ -7,19 +7,19 @@ use Tester\Assert; require __DIR__ . '/bootstrap.php'; -Assert::same(NULL, Helpers::getSuggestion([], '')); -Assert::same(NULL, Helpers::getSuggestion([], 'a')); -Assert::same(NULL, Helpers::getSuggestion(['a'], 'a')); +Assert::same(null, Helpers::getSuggestion([], '')); +Assert::same(null, Helpers::getSuggestion([], 'a')); +Assert::same(null, Helpers::getSuggestion(['a'], 'a')); Assert::same('a', Helpers::getSuggestion(['a', 'b'], '')); Assert::same('b', Helpers::getSuggestion(['a', 'b'], 'a')); // ignore 100% match Assert::same('a1', Helpers::getSuggestion(['a1', 'a2'], 'a')); // take first -Assert::same(NULL, Helpers::getSuggestion(['aaa', 'bbb'], 'a')); -Assert::same(NULL, Helpers::getSuggestion(['aaa', 'bbb'], 'ab')); -Assert::same(NULL, Helpers::getSuggestion(['aaa', 'bbb'], 'abc')); +Assert::same(null, Helpers::getSuggestion(['aaa', 'bbb'], 'a')); +Assert::same(null, Helpers::getSuggestion(['aaa', 'bbb'], 'ab')); +Assert::same(null, Helpers::getSuggestion(['aaa', 'bbb'], 'abc')); Assert::same('bar', Helpers::getSuggestion(['foo', 'bar', 'baz'], 'baz')); Assert::same('abcd', Helpers::getSuggestion(['abcd'], 'acbd')); Assert::same('abcd', Helpers::getSuggestion(['abcd'], 'axbd')); -Assert::same(NULL, Helpers::getSuggestion(['abcd'], 'axyd')); +Assert::same(null, Helpers::getSuggestion(['abcd'], 'axyd')); /* diff --git a/tests/dibi/Result.meta.phpt b/tests/dibi/Result.meta.phpt index fdd12551..26b0149e 100644 --- a/tests/dibi/Result.meta.phpt +++ b/tests/dibi/Result.meta.phpt @@ -30,7 +30,7 @@ Assert::same( if (!in_array($config['driver'], ['sqlite3', 'pdo', 'sqlsrv'])) { Assert::same( ['products.product_id', 'orders.order_id', 'customers.name', 'xXx'], - $info->getColumnNames(TRUE) + $info->getColumnNames(true) ); } diff --git a/tests/dibi/Result.normalize.phpt b/tests/dibi/Result.normalize.phpt index 90020a01..e01f8ee3 100644 --- a/tests/dibi/Result.normalize.phpt +++ b/tests/dibi/Result.normalize.phpt @@ -17,7 +17,7 @@ class MockResult extends Dibi\Result function test($row) { $normalize = new ReflectionMethod(Dibi\Result::class, 'normalize'); - $normalize->setAccessible(TRUE); + $normalize->setAccessible(true); $normalize->invokeArgs($this, [&$row]); return $row; } @@ -28,21 +28,21 @@ test(function () { $result = new MockResult; $result->setType('col', Type::BOOL); - Assert::same(['col' => NULL], $result->test(['col' => NULL])); - Assert::same(['col' => TRUE], $result->test(['col' => TRUE])); - Assert::same(['col' => FALSE], $result->test(['col' => FALSE])); + Assert::same(['col' => null], $result->test(['col' => null])); + Assert::same(['col' => true], $result->test(['col' => true])); + Assert::same(['col' => false], $result->test(['col' => false])); - Assert::same(['col' => FALSE], $result->test(['col' => ''])); - Assert::same(['col' => FALSE], $result->test(['col' => '0'])); - Assert::same(['col' => TRUE], $result->test(['col' => '1'])); - Assert::same(['col' => TRUE], $result->test(['col' => 't'])); - Assert::same(['col' => FALSE], $result->test(['col' => 'f'])); - Assert::same(['col' => TRUE], $result->test(['col' => 'T'])); - Assert::same(['col' => FALSE], $result->test(['col' => 'F'])); - Assert::same(['col' => FALSE], $result->test(['col' => 0])); - Assert::same(['col' => FALSE], $result->test(['col' => 0.0])); - Assert::same(['col' => TRUE], $result->test(['col' => 1])); - Assert::same(['col' => TRUE], $result->test(['col' => 1.0])); + Assert::same(['col' => false], $result->test(['col' => ''])); + Assert::same(['col' => false], $result->test(['col' => '0'])); + Assert::same(['col' => true], $result->test(['col' => '1'])); + Assert::same(['col' => true], $result->test(['col' => 't'])); + Assert::same(['col' => false], $result->test(['col' => 'f'])); + Assert::same(['col' => true], $result->test(['col' => 'T'])); + Assert::same(['col' => false], $result->test(['col' => 'F'])); + Assert::same(['col' => false], $result->test(['col' => 0])); + Assert::same(['col' => false], $result->test(['col' => 0.0])); + Assert::same(['col' => true], $result->test(['col' => 1])); + Assert::same(['col' => true], $result->test(['col' => 1.0])); }); @@ -50,9 +50,9 @@ test(function () { $result = new MockResult; $result->setType('col', Type::TEXT); - Assert::same(['col' => NULL], $result->test(['col' => NULL])); - Assert::same(['col' => '1'], $result->test(['col' => TRUE])); - Assert::same(['col' => ''], $result->test(['col' => FALSE])); + Assert::same(['col' => null], $result->test(['col' => null])); + Assert::same(['col' => '1'], $result->test(['col' => true])); + Assert::same(['col' => ''], $result->test(['col' => false])); Assert::same(['col' => ''], $result->test(['col' => ''])); Assert::same(['col' => '0'], $result->test(['col' => '0'])); @@ -66,9 +66,9 @@ test(function () { $result = new MockResult; $result->setType('col', Type::FLOAT); - Assert::same(['col' => NULL], $result->test(['col' => NULL])); - Assert::same(['col' => 1.0], $result->test(['col' => TRUE])); - Assert::same(['col' => 0.0], $result->test(['col' => FALSE])); + Assert::same(['col' => null], $result->test(['col' => null])); + Assert::same(['col' => 1.0], $result->test(['col' => true])); + Assert::same(['col' => 0.0], $result->test(['col' => false])); Assert::same(['col' => 0.0], $result->test(['col' => ''])); Assert::same(['col' => 0.0], $result->test(['col' => '0'])); @@ -138,9 +138,9 @@ test(function () { $result = new MockResult; $result->setType('col', Type::INTEGER); - Assert::same(['col' => NULL], $result->test(['col' => NULL])); - Assert::same(['col' => 1], $result->test(['col' => TRUE])); - Assert::same(['col' => 0], $result->test(['col' => FALSE])); + Assert::same(['col' => null], $result->test(['col' => null])); + Assert::same(['col' => 1], $result->test(['col' => true])); + Assert::same(['col' => 0], $result->test(['col' => false])); Assert::same(['col' => 0], @$result->test(['col' => ''])); // triggers warning in PHP 7.1 Assert::same(['col' => 0], $result->test(['col' => '0'])); @@ -164,14 +164,14 @@ test(function () { $result = new MockResult; $result->setType('col', Type::DATETIME); - Assert::same(['col' => NULL], $result->test(['col' => NULL])); + Assert::same(['col' => null], $result->test(['col' => null])); Assert::exception(function () use ($result) { - $result->test(['col' => TRUE]); + $result->test(['col' => true]); }, TypeError::class); - Assert::same(['col' => NULL], $result->test(['col' => FALSE])); + Assert::same(['col' => null], $result->test(['col' => false])); - Assert::same(['col' => NULL], $result->test(['col' => ''])); - Assert::same(['col' => NULL], $result->test(['col' => '0000-00-00'])); + Assert::same(['col' => null], $result->test(['col' => ''])); + Assert::same(['col' => null], $result->test(['col' => '0000-00-00'])); Assert::equal(['col' => new Dibi\DateTime('00:00:00')], $result->test(['col' => '00:00:00'])); Assert::equal(['col' => new Dibi\DateTime('2015-10-13')], $result->test(['col' => '2015-10-13'])); Assert::equal(['col' => new Dibi\DateTime('2015-10-13 14:30')], $result->test(['col' => '2015-10-13 14:30'])); @@ -183,14 +183,14 @@ test(function () { $result->setType('col', Type::DATETIME); $result->setFormat(Type::DATETIME, 'Y-m-d H:i:s'); - Assert::same(['col' => NULL], $result->test(['col' => NULL])); + Assert::same(['col' => null], $result->test(['col' => null])); Assert::exception(function () use ($result) { - $result->test(['col' => TRUE]); + $result->test(['col' => true]); }, TypeError::class); - Assert::same(['col' => NULL], $result->test(['col' => FALSE])); + Assert::same(['col' => null], $result->test(['col' => false])); - Assert::same(['col' => NULL], $result->test(['col' => ''])); - Assert::same(['col' => NULL], $result->test(['col' => '0000-00-00'])); + Assert::same(['col' => null], $result->test(['col' => ''])); + Assert::same(['col' => null], $result->test(['col' => '0000-00-00'])); Assert::same(['col' => date('Y-m-d 00:00:00')], $result->test(['col' => '00:00:00'])); Assert::equal(['col' => '2015-10-13 00:00:00'], $result->test(['col' => '2015-10-13'])); Assert::equal(['col' => '2015-10-13 14:30:00'], $result->test(['col' => '2015-10-13 14:30'])); @@ -201,14 +201,14 @@ test(function () { $result = new MockResult; $result->setType('col', Type::DATE); - Assert::same(['col' => NULL], $result->test(['col' => NULL])); + Assert::same(['col' => null], $result->test(['col' => null])); Assert::exception(function () use ($result) { - $result->test(['col' => TRUE]); + $result->test(['col' => true]); }, TypeError::class); - Assert::same(['col' => NULL], $result->test(['col' => FALSE])); + Assert::same(['col' => null], $result->test(['col' => false])); - Assert::same(['col' => NULL], $result->test(['col' => ''])); - Assert::same(['col' => NULL], $result->test(['col' => '0000-00-00'])); + Assert::same(['col' => null], $result->test(['col' => ''])); + Assert::same(['col' => null], $result->test(['col' => '0000-00-00'])); Assert::equal(['col' => new Dibi\DateTime('2015-10-13')], $result->test(['col' => '2015-10-13'])); }); @@ -217,14 +217,14 @@ test(function () { $result = new MockResult; $result->setType('col', Type::TIME); - Assert::same(['col' => NULL], $result->test(['col' => NULL])); + Assert::same(['col' => null], $result->test(['col' => null])); Assert::exception(function () use ($result) { - $result->test(['col' => TRUE]); + $result->test(['col' => true]); }, TypeError::class); - Assert::same(['col' => NULL], $result->test(['col' => FALSE])); + Assert::same(['col' => null], $result->test(['col' => false])); - Assert::same(['col' => NULL], $result->test(['col' => ''])); - Assert::same(['col' => NULL], $result->test(['col' => '0000-00-00'])); + Assert::same(['col' => null], $result->test(['col' => ''])); + Assert::same(['col' => null], $result->test(['col' => '0000-00-00'])); Assert::equal(['col' => new Dibi\DateTime('00:00:00')], $result->test(['col' => '00:00:00'])); Assert::equal(['col' => new Dibi\DateTime('14:30')], $result->test(['col' => '14:30'])); }); diff --git a/tests/dibi/Translator.DateTimeInterface.phpt b/tests/dibi/Translator.DateTimeInterface.phpt index f5c7ba99..99094214 100644 --- a/tests/dibi/Translator.DateTimeInterface.phpt +++ b/tests/dibi/Translator.DateTimeInterface.phpt @@ -15,5 +15,5 @@ $translator = new Dibi\Translator($conn); $datetime = new DateTime('1978-01-23 00:00:00'); -Assert::equal($datetime->format('U'), $translator->formatValue(new DateTime($datetime->format('c')), NULL)); -Assert::equal($datetime->format('U'), $translator->formatValue(new DateTimeImmutable($datetime->format('c')), NULL)); +Assert::equal($datetime->format('U'), $translator->formatValue(new DateTime($datetime->format('c')), null)); +Assert::equal($datetime->format('U'), $translator->formatValue(new DateTimeImmutable($datetime->format('c')), null)); diff --git a/tests/dibi/Translator.conditions.phpt b/tests/dibi/Translator.conditions.phpt index fbd25a30..4af754d6 100644 --- a/tests/dibi/Translator.conditions.phpt +++ b/tests/dibi/Translator.conditions.phpt @@ -35,7 +35,7 @@ FROM [customers] /* ... */'), $conn->translate(' SELECT * -FROM %if', TRUE, '[customers] %else [products]' +FROM %if', true, '[customers] %else [products]' )); @@ -53,8 +53,8 @@ WHERE [id] > 0 SELECT * FROM [people] WHERE [id] > 0 - %if', FALSE, 'AND [foo]=%i', 1, ' - %else %if', TRUE, 'AND [bar]=%i', 1, ' + %if', false, 'AND [foo]=%i', 1, ' + %else %if', true, 'AND [bar]=%i', 1, ' ')); @@ -72,8 +72,8 @@ WHERE SELECT * FROM [customers] WHERE - %if', TRUE, '[name] LIKE %s', 'xxx', ' - %if', FALSE, 'AND [admin]=1 %end + %if', true, '[name] LIKE %s', 'xxx', ' + %if', false, 'AND [admin]=1 %end %else 1 LIMIT 10 %end' )); @@ -83,7 +83,7 @@ Assert::same( 'SELECT * FROM foo /* (limit 3) (offset 5) */', $conn->translate( 'SELECT * FROM foo', - '%if', FALSE, + '%if', false, '%lmt', 3, '%ofs', 5, '%end' diff --git a/tests/dibi/Translator.phpt b/tests/dibi/Translator.phpt index 42bb8c38..5aaa1708 100644 --- a/tests/dibi/Translator.phpt +++ b/tests/dibi/Translator.phpt @@ -27,7 +27,7 @@ Assert::same( $array = [ 'title' => 'Super Product', 'price' => 12, - 'brand' => NULL, + 'brand' => null, ]; Assert::same( reformat('INSERT INTO [products] ([title], [price], [brand]) VALUES (\'Super Product\', 12, NULL) , (\'Super Product\', 12, NULL) , (\'Super Product\', 12, NULL)'), @@ -108,7 +108,7 @@ Assert::same( $where = []; -$where['age'] = NULL; +$where['age'] = null; $where['email'] = 'ahoj'; $where['id%l'] = [10, 20, 30]; Assert::same( @@ -130,8 +130,8 @@ $order = [ 'field2' => 'desc', 'field3' => 1, 'field4' => -1, - 'field5' => TRUE, - 'field6' => FALSE, + 'field5' => true, + 'field6' => false, ]; Assert::same( reformat('SELECT * FROM [people] ORDER BY [field1] ASC, [field2] DESC, [field3] ASC, [field4] DESC, [field5] ASC, [field6] DESC'), @@ -193,8 +193,8 @@ Assert::same( 'b5' => new DateTime('1212-09-26'), 'b6%d' => new DateTime('1212-09-26'), 'b7%t' => new DateTime('1212-09-26'), - 'b8%d' => NULL, - 'b9%t' => NULL, + 'b8%d' => null, + 'b9%t' => null, 'c1%t' => new DateTime('1212-09-26 16:51:34.0124'), ])); @@ -287,7 +287,7 @@ $array3 = [ ]; $array4 = [ 'a' => 12, - 'b' => NULL, + 'b' => null, 'c' => new DateTime('12.3.2007'), 'd' => 'any string', ]; @@ -398,9 +398,9 @@ WHERE ([test.a] LIKE %d', '1995-03-01', ' OR [b10] IN (', [], ") AND [c] = 'embedded '' string' OR [d]=%i", 10.3, ' - OR [e]=%i', NULL, ' - OR [true]=', TRUE, ' - OR [false]=', FALSE, ' + OR [e]=%i', null, ' + OR [true]=', true, ' + OR [false]=', false, ' OR [str_null]=%sn', '', ' OR [str_not_null]=%sn', 'hello', ' LIMIT 10') @@ -452,7 +452,7 @@ Assert::same( Assert::same( reformat('SELECT FROM ... '), - $conn->translate('SELECT FROM ... %lmt', NULL) + $conn->translate('SELECT FROM ... %lmt', null) ); Assert::same( diff --git a/tests/dibi/bootstrap.php b/tests/dibi/bootstrap.php index 34e68d41..5bfee69e 100644 --- a/tests/dibi/bootstrap.php +++ b/tests/dibi/bootstrap.php @@ -19,7 +19,7 @@ date_default_timezone_set('Europe/Prague'); try { $config = Tester\Environment::loadData(); } catch (Exception $e) { - $config = parse_ini_file(__DIR__ . '/../databases.ini', TRUE); + $config = parse_ini_file(__DIR__ . '/../databases.ini', true); $config = reset($config); } diff --git a/tests/dibi/exceptions.sqlite.phpt b/tests/dibi/exceptions.sqlite.phpt index b59f1fcf..3f65c842 100644 --- a/tests/dibi/exceptions.sqlite.phpt +++ b/tests/dibi/exceptions.sqlite.phpt @@ -24,14 +24,14 @@ Assert::same('SELECT', $e->getSql()); $e = Assert::exception(function () use ($conn) { $conn->query('INSERT INTO products (product_id, title) VALUES (1, "New")'); -}, Dibi\UniqueConstraintViolationException::class, NULL, 19); +}, Dibi\UniqueConstraintViolationException::class, null, 19); Assert::same("INSERT INTO products (product_id, title) VALUES (1, 'New')", $e->getSql()); $e = Assert::exception(function () use ($conn) { $conn->query('INSERT INTO products (title) VALUES (NULL)'); -}, Dibi\NotNullConstraintViolationException::class, NULL, 19); +}, Dibi\NotNullConstraintViolationException::class, null, 19); Assert::same('INSERT INTO products (title) VALUES (NULL)', $e->getSql()); @@ -39,6 +39,6 @@ Assert::same('INSERT INTO products (title) VALUES (NULL)', $e->getSql()); $e = Assert::exception(function () use ($conn) { $conn->query('PRAGMA foreign_keys=true'); $conn->query('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)'); -}, Dibi\ForeignKeyConstraintViolationException::class, NULL, 19); +}, Dibi\ForeignKeyConstraintViolationException::class, null, 19); Assert::same('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)', $e->getSql());