From ca99b0b822bd045287ab80eb212fd6db4a7f43af Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 19 Jun 2015 03:11:36 +0200 Subject: [PATCH] improved coding style --- dibi/bridges/Nette-2.1/DibiNettePanel.php | 3 +- .../Nette-2.2/DibiNette22Extension.php | 4 +- dibi/bridges/Tracy/Panel.php | 9 +- dibi/drivers/DibiFirebirdDriver.php | 13 +- dibi/drivers/DibiMsSql2005Driver.php | 4 +- dibi/drivers/DibiMsSql2005Reflector.php | 2 +- dibi/drivers/DibiMsSqlDriver.php | 1 - dibi/drivers/DibiMsSqlReflector.php | 36 +++--- dibi/drivers/DibiMySqlDriver.php | 4 +- dibi/drivers/DibiMySqlReflector.php | 6 +- dibi/drivers/DibiMySqliDriver.php | 4 +- dibi/drivers/DibiOdbcDriver.php | 16 +-- dibi/drivers/DibiOracleDriver.php | 4 +- dibi/drivers/DibiPdoDriver.php | 23 ++-- dibi/drivers/DibiPostgreDriver.php | 20 ++-- dibi/drivers/DibiSqlite3Driver.php | 19 +-- dibi/drivers/DibiSqliteDriver.php | 6 +- dibi/libs/Dibi.php | 24 ++-- dibi/libs/DibiConnection.php | 2 +- dibi/libs/DibiException.php | 4 +- dibi/libs/DibiFileLogger.php | 2 +- dibi/libs/DibiFirePhpLogger.php | 2 +- dibi/libs/DibiFluent.php | 2 +- dibi/libs/DibiObject.php | 2 +- dibi/libs/DibiResult.php | 28 ++--- dibi/libs/DibiTranslator.php | 18 +-- examples/connecting-to-databases.php | 46 +++----- examples/database-reflection.php | 4 +- examples/dumping-sql-and-result-set.php | 2 +- examples/fetching-examples.php | 2 +- examples/importing-dump-from-file.php | 2 +- examples/query-language-and-conditions.php | 10 +- examples/query-language-basic-examples.php | 22 ++-- examples/result-set-data-types.php | 6 +- examples/tracy-and-exceptions.php | 4 +- examples/tracy.php | 6 +- examples/using-datetime.php | 10 +- examples/using-extension-methods.php | 5 +- examples/using-fluent-syntax.php | 6 +- examples/using-limit-and-offset.php | 2 +- examples/using-logger.php | 5 +- examples/using-profiler.php | 6 +- examples/using-substitutions.php | 4 +- examples/using-transactions.php | 2 +- tests/dibi/DataSource.phpt | 12 +- tests/dibi/DibiConnection.connect.phpt | 6 +- tests/dibi/DibiConnection.transactions.phpt | 6 +- tests/dibi/DibiFluent.cloning.phpt | 20 ++-- tests/dibi/DibiFluent.insert.phpt | 6 +- tests/dibi/DibiFluent.select.phpt | 2 +- tests/dibi/DibiFluent.update.phpt | 6 +- tests/dibi/DibiTranslator.conditions.phpt | 20 ++-- tests/dibi/DibiTranslator.phpt | 111 +++++++++--------- tests/dibi/PdoMssql.limits.phpt | 4 +- tests/dibi/Postgre.like.phpt | 8 +- 55 files changed, 297 insertions(+), 306 deletions(-) diff --git a/dibi/bridges/Nette-2.1/DibiNettePanel.php b/dibi/bridges/Nette-2.1/DibiNettePanel.php index c8104d6..b2e8191 100644 --- a/dibi/bridges/Nette-2.1/DibiNettePanel.php +++ b/dibi/bridges/Nette-2.1/DibiNettePanel.php @@ -106,7 +106,8 @@ class DibiNettePanel extends DibiObject implements Nette\Diagnostics\IBarPanel $event->connection->onEvent = NULL; $cmd = is_string($this->explain) ? $this->explain : ($event->connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN FOR' : 'EXPLAIN'); $explain = dibi::dump($event->connection->nativeQuery("$cmd $event->sql"), TRUE); - } catch (DibiException $e) {} + } catch (DibiException $e) { + } list($event->connection->onEvent, dibi::$numOfQueries, dibi::$totalTime) = $backup; } diff --git a/dibi/bridges/Nette-2.2/DibiNette22Extension.php b/dibi/bridges/Nette-2.2/DibiNette22Extension.php index 72b6a18..dcb8821 100644 --- a/dibi/bridges/Nette-2.2/DibiNette22Extension.php +++ b/dibi/bridges/Nette-2.2/DibiNette22Extension.php @@ -7,8 +7,8 @@ namespace Dibi\Bridges\Nette; -use dibi, - Nette; +use dibi; +use Nette; /** diff --git a/dibi/bridges/Tracy/Panel.php b/dibi/bridges/Tracy/Panel.php index dac19e4..ff79a80 100644 --- a/dibi/bridges/Tracy/Panel.php +++ b/dibi/bridges/Tracy/Panel.php @@ -7,8 +7,8 @@ namespace Dibi\Bridges\Tracy; -use dibi, - Tracy; +use dibi; +use Tracy; /** @@ -85,7 +85,7 @@ class Panel extends \DibiObject implements Tracy\IBarPanel foreach ($this->events as $event) { $totalTime += $event->time; } - return '' + return '' . $count . ' queries' . ($totalTime ? sprintf(' / %0.1f ms', $totalTime * 1000) : '') . ''; @@ -109,7 +109,8 @@ class Panel extends \DibiObject implements Tracy\IBarPanel $event->connection->onEvent = NULL; $cmd = is_string($this->explain) ? $this->explain : ($event->connection->getConfig('driver') === 'oracle' ? 'EXPLAIN PLAN FOR' : 'EXPLAIN'); $explain = dibi::dump($event->connection->nativeQuery("$cmd $event->sql"), TRUE); - } catch (\DibiException $e) {} + } catch (\DibiException $e) { + } list($event->connection->onEvent, dibi::$numOfQueries, dibi::$totalTime) = $backup; } diff --git a/dibi/drivers/DibiFirebirdDriver.php b/dibi/drivers/DibiFirebirdDriver.php index 876854f..f8d8093 100644 --- a/dibi/drivers/DibiFirebirdDriver.php +++ b/dibi/drivers/DibiFirebirdDriver.php @@ -88,7 +88,6 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD throw new DibiDriverException(ibase_errmsg(), ibase_errcode()); } } - } @@ -349,7 +348,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD */ public function getRowCount() { - throw new DibiNotSupportedException("Firebird/Interbase do not support returning number of rows in result set."); + throw new DibiNotSupportedException('Firebird/Interbase do not support returning number of rows in result set.'); } @@ -379,13 +378,13 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD /** * Moves cursor position without fetching row. - * @param int the 0-based cursor pos to seek to - * @return boolean TRUE on success, FALSE if unable to seek to specified record + * @param int the 0-based cursor pos to seek to + * @return bool TRUE on success, FALSE if unable to seek to specified record * @throws DibiException */ public function seek($row) { - throw new DibiNotSupportedException("Firebird/Interbase do not support seek in result set."); + throw new DibiNotSupportedException('Firebird/Interbase do not support seek in result set.'); } @@ -656,7 +655,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD 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 = array(); while ($row = $res->fetch(TRUE)) { @@ -683,7 +682,7 @@ class DibiFirebirdDriver extends DibiObject implements IDibiDriver, IDibiResultD $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 = array(); diff --git a/dibi/drivers/DibiMsSql2005Driver.php b/dibi/drivers/DibiMsSql2005Driver.php index 23731cc..4168dfd 100644 --- a/dibi/drivers/DibiMsSql2005Driver.php +++ b/dibi/drivers/DibiMsSql2005Driver.php @@ -327,8 +327,8 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver, IDibiResult /** * Moves cursor position without fetching row. - * @param int the 0-based cursor pos to seek to - * @return boolean TRUE on success, FALSE if unable to seek to specified record + * @param int the 0-based cursor pos to seek to + * @return bool TRUE on success, FALSE if unable to seek to specified record */ public function seek($row) { diff --git a/dibi/drivers/DibiMsSql2005Reflector.php b/dibi/drivers/DibiMsSql2005Reflector.php index a13e812..38b3491 100644 --- a/dibi/drivers/DibiMsSql2005Reflector.php +++ b/dibi/drivers/DibiMsSql2005Reflector.php @@ -104,7 +104,7 @@ class DibiMsSql2005Reflector extends DibiObject implements IDibiReflector { $keyUsagesRes = $this->driver->query("SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE TABLE_NAME = {$this->driver->escape($table, dibi::TEXT)}"); $keyUsages = array(); - while( $row = $keyUsagesRes->fetch(TRUE) ) { + while ($row = $keyUsagesRes->fetch(TRUE)) { $keyUsages[$row['CONSTRAINT_NAME']][(int) $row['ORDINAL_POSITION'] - 1] = $row['COLUMN_NAME']; } diff --git a/dibi/drivers/DibiMsSqlDriver.php b/dibi/drivers/DibiMsSqlDriver.php index aeae95d..3627558 100644 --- a/dibi/drivers/DibiMsSqlDriver.php +++ b/dibi/drivers/DibiMsSqlDriver.php @@ -363,5 +363,4 @@ class DibiMsSqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv return is_resource($this->resultSet) ? $this->resultSet : NULL; } - } diff --git a/dibi/drivers/DibiMsSqlReflector.php b/dibi/drivers/DibiMsSqlReflector.php index d097476..d2ea990 100644 --- a/dibi/drivers/DibiMsSqlReflector.php +++ b/dibi/drivers/DibiMsSqlReflector.php @@ -34,10 +34,10 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector */ public function getTables() { - $res = $this->driver->query(" + $res = $this->driver->query(' SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES - "); + '); $tables = array(); while ($row = $res->fetch(FALSE)) { $tables[] = array( @@ -52,12 +52,12 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector /** * Returns count of rows in a table * @param string - * @return integer + * @return int */ - public function getTableCount($table, $fallback=true) + public function getTableCount($table, $fallback = TRUE) { if (empty($table)) { - return false; + return FALSE; } $result = $this->driver->query(" SELECT MAX(rowcnt) @@ -71,7 +71,7 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector $row = $this->driver->query("SELECT COUNT(*) FROM {$this->driver->escape($table, dibi::IDENTIFIER)}")->fetch(FALSE); $count = intval($row[0]); } else { - $count = false; + $count = FALSE; } } else { $count = intval($row[0]); @@ -96,16 +96,16 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector "); $columns = array(); while ($row = $res->fetch(TRUE)) { - $size = false; + $size = FALSE; $type = strtoupper($row['DATA_TYPE']); $size_cols = array( - 'DATETIME'=>'DATETIME_PRECISION', - 'DECIMAL'=>'NUMERIC_PRECISION', - 'CHAR'=>'CHARACTER_MAXIMUM_LENGTH', - 'NCHAR'=>'CHARACTER_OCTET_LENGTH', - 'NVARCHAR'=>'CHARACTER_OCTET_LENGTH', - 'VARCHAR'=>'CHARACTER_OCTET_LENGTH' + 'DATETIME' => 'DATETIME_PRECISION', + 'DECIMAL' => 'NUMERIC_PRECISION', + 'CHAR' => 'CHARACTER_MAXIMUM_LENGTH', + 'NCHAR' => 'CHARACTER_OCTET_LENGTH', + 'NVARCHAR' => 'CHARACTER_OCTET_LENGTH', + 'VARCHAR' => 'CHARACTER_OCTET_LENGTH', ); if (isset($size_cols[$type])) { @@ -122,7 +122,7 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector 'unsigned' => NULL, 'nullable' => $row['IS_NULLABLE'] === 'YES', 'default' => $row['COLUMN_DEFAULT'], - 'autoincrement' => false, + 'autoincrement' => FALSE, 'vendor' => $row, ); } @@ -161,8 +161,8 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector if (!isset($indexes[$index_name])) { $indexes[$index_name] = array(); $indexes[$index_name]['name'] = $index_name; - $indexes[$index_name]['unique'] = (bool)$row['is_unique']; - $indexes[$index_name]['primary'] = (bool)$row['is_primary_key']; + $indexes[$index_name]['unique'] = (bool) $row['is_unique']; + $indexes[$index_name]['primary'] = (bool) $row['is_primary_key']; $indexes[$index_name]['columns'] = array(); } $indexes[$index_name]['columns'][] = $row['column_name']; @@ -203,8 +203,8 @@ class DibiMsSqlReflector extends DibiObject implements IDibiReflector $keys[$key_name]['local'] = array($row['column_name']); // local columns $keys[$key_name]['table'] = $row['reference_table_name']; // referenced table $keys[$key_name]['foreign'] = array($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/dibi/drivers/DibiMySqlDriver.php b/dibi/drivers/DibiMySqlDriver.php index 84f0f6d..c0101b3 100644 --- a/dibi/drivers/DibiMySqlDriver.php +++ b/dibi/drivers/DibiMySqlDriver.php @@ -406,8 +406,8 @@ class DibiMySqlDriver extends DibiObject implements IDibiDriver, IDibiResultDriv /** * Moves cursor position without fetching row. - * @param int the 0-based cursor pos to seek to - * @return boolean TRUE on success, FALSE if unable to seek to specified record + * @param int the 0-based cursor pos to seek to + * @return bool TRUE on success, FALSE if unable to seek to specified record * @throws DibiException */ public function seek($row) diff --git a/dibi/drivers/DibiMySqlReflector.php b/dibi/drivers/DibiMySqlReflector.php index 57aff89..32542c4 100644 --- a/dibi/drivers/DibiMySqlReflector.php +++ b/dibi/drivers/DibiMySqlReflector.php @@ -36,7 +36,7 @@ class DibiMySqlReflector extends DibiObject implements IDibiReflector FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = DATABASE() ");*/ - $res = $this->driver->query("SHOW FULL TABLES"); + $res = $this->driver->query('SHOW FULL TABLES'); $tables = array(); while ($row = $res->fetch(FALSE)) { $tables[] = array( @@ -138,9 +138,9 @@ class DibiMySqlReflector extends DibiObject implements IDibiReflector $keyName = $row['CONSTRAINT_NAME']; $foreignKeys[$keyName]['name'] = $keyName; - $foreignKeys[$keyName]['local'] = explode(",", $row['COLUMNS']); + $foreignKeys[$keyName]['local'] = explode(',', $row['COLUMNS']); $foreignKeys[$keyName]['table'] = $row['REFERENCED_TABLE_NAME']; - $foreignKeys[$keyName]['foreign'] = explode(",", $row['REFERENCED_COLUMNS']); + $foreignKeys[$keyName]['foreign'] = explode(',', $row['REFERENCED_COLUMNS']); $foreignKeys[$keyName]['onDelete'] = $row['DELETE_RULE']; $foreignKeys[$keyName]['onUpdate'] = $row['UPDATE_RULE']; } diff --git a/dibi/drivers/DibiMySqliDriver.php b/dibi/drivers/DibiMySqliDriver.php index 602fe0a..47860c9 100644 --- a/dibi/drivers/DibiMySqliDriver.php +++ b/dibi/drivers/DibiMySqliDriver.php @@ -389,8 +389,8 @@ class DibiMySqliDriver extends DibiObject implements IDibiDriver, IDibiResultDri /** * Moves cursor position without fetching row. - * @param int the 0-based cursor pos to seek to - * @return boolean TRUE on success, FALSE if unable to seek to specified record + * @param int the 0-based cursor pos to seek to + * @return bool TRUE on success, FALSE if unable to seek to specified record * @throws DibiException */ public function seek($row) diff --git a/dibi/drivers/DibiOdbcDriver.php b/dibi/drivers/DibiOdbcDriver.php index c91de6e..b5d4edf 100644 --- a/dibi/drivers/DibiOdbcDriver.php +++ b/dibi/drivers/DibiOdbcDriver.php @@ -339,7 +339,9 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive } $count = odbc_num_fields($set); $cols = array(); - for ($i = 1; $i <= $count; $i++) $cols[] = odbc_result($set, $i); + for ($i = 1; $i <= $count; $i++) { + $cols[] = odbc_result($set, $i); + } return $cols; } } @@ -347,8 +349,8 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive /** * Moves cursor position without fetching row. - * @param int the 0-based cursor pos to seek to - * @return boolean TRUE on success, FALSE if unable to seek to specified record + * @param int the 0-based cursor pos to seek to + * @return bool TRUE on success, FALSE if unable to seek to specified record */ public function seek($row) { @@ -378,10 +380,10 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver, IDibiResultDrive $columns = array(); for ($i = 1; $i <= $count; $i++) { $columns[] = array( - 'name' => odbc_field_name($this->resultSet, $i), - 'table' => NULL, - 'fullname' => odbc_field_name($this->resultSet, $i), - 'nativetype'=> odbc_field_type($this->resultSet, $i), + 'name' => odbc_field_name($this->resultSet, $i), + 'table' => NULL, + 'fullname' => odbc_field_name($this->resultSet, $i), + 'nativetype' => odbc_field_type($this->resultSet, $i), ); } return $columns; diff --git a/dibi/drivers/DibiOracleDriver.php b/dibi/drivers/DibiOracleDriver.php index 7ec760f..52a585b 100644 --- a/dibi/drivers/DibiOracleDriver.php +++ b/dibi/drivers/DibiOracleDriver.php @@ -336,8 +336,8 @@ class DibiOracleDriver extends DibiObject implements IDibiDriver, IDibiResultDri /** * Moves cursor position without fetching row. - * @param int the 0-based cursor pos to seek to - * @return boolean TRUE on success, FALSE if unable to seek to specified record + * @param int the 0-based cursor pos to seek to + * @return bool TRUE on success, FALSE if unable to seek to specified record */ public function seek($row) { diff --git a/dibi/drivers/DibiPdoDriver.php b/dibi/drivers/DibiPdoDriver.php index da0101e..f17112f 100644 --- a/dibi/drivers/DibiPdoDriver.php +++ b/dibi/drivers/DibiPdoDriver.php @@ -68,14 +68,15 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver if ($config['resource'] instanceof PDO) { $this->connection = $config['resource']; - } else try { - $this->connection = new PDO($config['dsn'], $config['username'], $config['password'], $config['options']); - - } catch (PDOException $e) { - if ($e->getMessage() === 'could not find driver') { - throw new DibiNotSupportedException("PHP extension for PDO is not loaded."); + } else { + try { + $this->connection = new PDO($config['dsn'], $config['username'], $config['password'], $config['options']); + } catch (PDOException $e) { + if ($e->getMessage() === 'could not find driver') { + throw new DibiNotSupportedException('PHP extension for PDO is not loaded.'); + } + throw new DibiDriverException($e->getMessage(), $e->getCode()); } - throw new DibiDriverException($e->getMessage(), $e->getCode()); } $this->driverName = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME); @@ -105,7 +106,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver { // must detect if SQL returns result set or num of affected rows $cmd = strtoupper(substr(ltrim($sql), 0, 6)); - static $list = array('UPDATE'=>1, 'DELETE'=>1, 'INSERT'=>1, 'REPLAC'=>1); + static $list = array('UPDATE' => 1, 'DELETE' => 1, 'INSERT' => 1, 'REPLAC' => 1); $this->affectedRows = FALSE; if (isset($list[$cmd])) { @@ -296,7 +297,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver $value = new DibiDateTime($value); } if ($this->driverName === 'odbc') { - return $value->format($type === dibi::DATETIME ? "#m/d/Y H:i:s#" : "#m/d/Y#"); + return $value->format($type === dibi::DATETIME ? '#m/d/Y H:i:s#' : '#m/d/Y#'); } else { return $value->format($type === dibi::DATETIME ? "'Y-m-d H:i:s'" : "'Y-m-d'"); } @@ -456,8 +457,8 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver /** * Moves cursor position without fetching row. - * @param int the 0-based cursor pos to seek to - * @return boolean TRUE on success, FALSE if unable to seek to specified record + * @param int the 0-based cursor pos to seek to + * @return bool TRUE on success, FALSE if unable to seek to specified record */ public function seek($row) { diff --git a/dibi/drivers/DibiPostgreDriver.php b/dibi/drivers/DibiPostgreDriver.php index 90eccfa..fbf2d30 100644 --- a/dibi/drivers/DibiPostgreDriver.php +++ b/dibi/drivers/DibiPostgreDriver.php @@ -67,7 +67,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr $string = ''; DibiConnection::alias($config, 'user', 'username'); DibiConnection::alias($config, 'dbname', 'database'); - foreach (array('host','hostaddr','port','dbname','user','password','connect_timeout','options','sslmode','service') as $key) { + foreach (array('host', 'hostaddr', 'port', 'dbname', 'user', 'password', 'connect_timeout', 'options', 'sslmode', 'service') as $key) { if (isset($config[$key])) { $string .= $key . '=' . $config[$key] . ' '; } @@ -115,7 +115,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr /** * Pings database. - * @return boolean + * @return bool */ public function ping() { @@ -164,7 +164,7 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr { if ($sequence === NULL) { // PostgreSQL 8.1 is needed - $res = $this->query("SELECT LASTVAL()"); + $res = $this->query('SELECT LASTVAL()'); } else { $res = $this->query("SELECT CURRVAL('$sequence')"); } @@ -385,8 +385,8 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr /** * Moves cursor position without fetching row. - * @param int the 0-based cursor pos to seek to - * @return boolean TRUE on success, FALSE if unable to seek to specified record + * @param int the 0-based cursor pos to seek to + * @return bool TRUE on success, FALSE if unable to seek to specified record */ public function seek($row) { @@ -415,9 +415,9 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr $columns = array(); for ($i = 0; $i < $count; $i++) { $row = array( - 'name' => pg_field_name($this->resultSet, $i), - 'table' => pg_field_table($this->resultSet, $i), - 'nativetype'=> pg_field_type($this->resultSet, $i), + 'name' => pg_field_name($this->resultSet, $i), + 'table' => pg_field_table($this->resultSet, $i), + 'nativetype' => pg_field_type($this->resultSet, $i), ); $row['fullname'] = $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name']; $columns[] = $row; @@ -464,14 +464,14 @@ class DibiPostgreDriver extends DibiObject implements IDibiDriver, IDibiResultDr table_schema = ANY (current_schemas(false))"; if ($version >= 9.3) { - $query .= " + $query .= ' UNION ALL SELECT matviewname, 1 FROM pg_matviews WHERE - schemaname = ANY (current_schemas(false))"; + schemaname = ANY (current_schemas(false))'; } $res = $this->query($query); diff --git a/dibi/drivers/DibiSqlite3Driver.php b/dibi/drivers/DibiSqlite3Driver.php index 83310b8..e43f458 100644 --- a/dibi/drivers/DibiSqlite3Driver.php +++ b/dibi/drivers/DibiSqlite3Driver.php @@ -66,11 +66,12 @@ class DibiSqlite3Driver extends DibiObject implements IDibiDriver, IDibiResultDr if (isset($config['resource']) && $config['resource'] instanceof SQLite3) { $this->connection = $config['resource']; - } else try { - $this->connection = new SQLite3($config['database']); - - } catch (Exception $e) { - throw new DibiDriverException($e->getMessage(), $e->getCode()); + } else { + try { + $this->connection = new SQLite3($config['database']); + } catch (Exception $e) { + throw new DibiDriverException($e->getMessage(), $e->getCode()); + } } $this->dbcharset = empty($config['dbcharset']) ? 'UTF-8' : $config['dbcharset']; @@ -82,7 +83,7 @@ class DibiSqlite3Driver extends DibiObject implements IDibiDriver, IDibiResultDr // enable foreign keys support (defaultly disabled; if disabled then foreign key constraints are not enforced) $version = SQLite3::version(); if ($version['versionNumber'] >= '3006019') { - $this->query("PRAGMA foreign_keys = ON"); + $this->query('PRAGMA foreign_keys = ON'); } } @@ -336,8 +337,8 @@ class DibiSqlite3Driver extends DibiObject implements IDibiDriver, IDibiResultDr /** * Moves cursor position without fetching row. - * @param int the 0-based cursor pos to seek to - * @return boolean TRUE on success, FALSE if unable to seek to specified record + * @param int the 0-based cursor pos to seek to + * @return bool TRUE on success, FALSE if unable to seek to specified record * @throws DibiNotSupportedException */ public function seek($row) @@ -368,7 +369,7 @@ class DibiSqlite3Driver extends DibiObject implements IDibiDriver, IDibiResultDr static $types = array(SQLITE3_INTEGER => 'int', SQLITE3_FLOAT => 'float', SQLITE3_TEXT => 'text', SQLITE3_BLOB => 'blob', SQLITE3_NULL => 'null'); for ($i = 0; $i < $count; $i++) { $columns[] = array( - 'name' => $this->resultSet->columnName($i), + 'name' => $this->resultSet->columnName($i), 'table' => NULL, 'fullname' => $this->resultSet->columnName($i), 'nativetype' => $types[$this->resultSet->columnType($i)], diff --git a/dibi/drivers/DibiSqliteDriver.php b/dibi/drivers/DibiSqliteDriver.php index 7d61e84..9a6d3b5 100644 --- a/dibi/drivers/DibiSqliteDriver.php +++ b/dibi/drivers/DibiSqliteDriver.php @@ -332,8 +332,8 @@ class DibiSqliteDriver extends DibiObject implements IDibiDriver, IDibiResultDri /** * Moves cursor position without fetching row. - * @param int the 0-based cursor pos to seek to - * @return boolean TRUE on success, FALSE if unable to seek to specified record + * @param int the 0-based cursor pos to seek to + * @return bool TRUE on success, FALSE if unable to seek to specified record * @throws DibiException */ public function seek($row) @@ -367,7 +367,7 @@ class DibiSqliteDriver extends DibiObject implements IDibiDriver, IDibiResultDri $name = str_replace(array('[', ']'), '', sqlite_field_name($this->resultSet, $i)); $pair = explode('.', $name); $columns[] = array( - 'name' => isset($pair[1]) ? $pair[1] : $pair[0], + 'name' => isset($pair[1]) ? $pair[1] : $pair[0], 'table' => isset($pair[1]) ? $pair[0] : NULL, 'fullname' => $name, 'nativetype' => NULL, diff --git a/dibi/libs/Dibi.php b/dibi/libs/Dibi.php index cde5bf1..5bb66f8 100644 --- a/dibi/libs/Dibi.php +++ b/dibi/libs/Dibi.php @@ -29,14 +29,14 @@ class dibi AFFECTED_ROWS = 'a'; /** @deprecated */ - const FIELD_TEXT = dibi::TEXT, - FIELD_BINARY = dibi::BINARY, - FIELD_BOOL = dibi::BOOL, - FIELD_INTEGER = dibi::INTEGER, - FIELD_FLOAT = dibi::FLOAT, - FIELD_DATE = dibi::DATE, - FIELD_DATETIME = dibi::DATETIME, - FIELD_TIME = dibi::TIME; + const FIELD_TEXT = self::TEXT, + FIELD_BINARY = self::BINARY, + FIELD_BOOL = self::BOOL, + FIELD_INTEGER = self::INTEGER, + FIELD_FLOAT = self::FLOAT, + FIELD_DATE = self::DATE, + FIELD_DATETIME = self::DATETIME, + FIELD_TIME = self::TIME; /** version */ const VERSION = '2.3.2', @@ -76,7 +76,7 @@ class dibi */ final public function __construct() { - throw new LogicException("Cannot instantiate static class " . get_class($this)); + throw new LogicException('Cannot instantiate static class ' . get_class($this)); } @@ -294,7 +294,7 @@ class dibi * @return int * @throws DibiException */ - public static function getInsertId($sequence=NULL) + public static function getInsertId($sequence = NULL) { return self::getConnection()->getInsertId($sequence); } @@ -306,7 +306,7 @@ class dibi * @return int * @throws DibiException */ - public static function insertId($sequence=NULL) + public static function insertId($sequence = NULL) { return self::getConnection()->getInsertId($sequence); } @@ -477,7 +477,7 @@ class dibi $sql = preg_replace("#(?<=[\\s,(])($keywords1)(?=[\\s,)])#i", "\n\$1", $sql); // reduce spaces - $sql = preg_replace('#[ \t]{2,}#', " ", $sql); + $sql = preg_replace('#[ \t]{2,}#', ' ', $sql); $sql = wordwrap($sql, 100); $sql = preg_replace("#([ \t]*\r?\n){2,}#", "\n", $sql); diff --git a/dibi/libs/DibiConnection.php b/dibi/libs/DibiConnection.php index 256740b..11e1a20 100644 --- a/dibi/libs/DibiConnection.php +++ b/dibi/libs/DibiConnection.php @@ -21,7 +21,7 @@ */ class DibiConnection extends DibiObject { - /** @var array of function(DibiEvent $event); Occurs after query is executed */ + /** @var array of function (DibiEvent $event); Occurs after query is executed */ public $onEvent; /** @var array Current connection configuration */ diff --git a/dibi/libs/DibiException.php b/dibi/libs/DibiException.php index 6d48e75..7cbb498 100644 --- a/dibi/libs/DibiException.php +++ b/dibi/libs/DibiException.php @@ -117,8 +117,8 @@ class DibiDriverException extends DibiException * @author David Grudl * @package dibi */ -class DibiPcreException extends Exception { - +class DibiPcreException extends Exception +{ public function __construct($message = '%msg.') { static $messages = array( diff --git a/dibi/libs/DibiFileLogger.php b/dibi/libs/DibiFileLogger.php index fd26a8d..0aeaef1 100644 --- a/dibi/libs/DibiFileLogger.php +++ b/dibi/libs/DibiFileLogger.php @@ -58,7 +58,7 @@ class DibiFileLogger extends DibiObject ); } else { fwrite($handle, - "OK: " . $event->sql + 'OK: ' . $event->sql . ($event->count ? ";\n-- rows: " . $event->count : '') . "\n-- takes: " . sprintf('%0.3f ms', $event->time * 1000) . "\n-- source: " . implode(':', $event->source) diff --git a/dibi/libs/DibiFirePhpLogger.php b/dibi/libs/DibiFirePhpLogger.php index 3de3144..7f29ad8 100644 --- a/dibi/libs/DibiFirePhpLogger.php +++ b/dibi/libs/DibiFirePhpLogger.php @@ -72,7 +72,7 @@ class DibiFirePhpLogger extends DibiObject sprintf('%0.3f', $event->time * 1000), strlen($event->sql) > self::$maxLength ? substr($event->sql, 0, self::$maxLength) . '...' : $event->sql, $event->result instanceof Exception ? 'ERROR' : (string) $event->count, - $event->connection->getConfig('driver') . '/' . $event->connection->getConfig('name') + $event->connection->getConfig('driver') . '/' . $event->connection->getConfig('name'), ); $payload = json_encode(array( diff --git a/dibi/libs/DibiFluent.php b/dibi/libs/DibiFluent.php index bdf2222..1ce6f04 100644 --- a/dibi/libs/DibiFluent.php +++ b/dibi/libs/DibiFluent.php @@ -405,7 +405,7 @@ class DibiFluent extends DibiObject implements IDataSource public function count() { return (int) $this->query(array( - 'SELECT COUNT(*) FROM (%ex', $this->_export(), ') AS [data]' + 'SELECT COUNT(*) FROM (%ex', $this->_export(), ') AS [data]', ))->fetchSingle(); } diff --git a/dibi/libs/DibiObject.php b/dibi/libs/DibiObject.php index 3bdbb3c..b02f7ae 100644 --- a/dibi/libs/DibiObject.php +++ b/dibi/libs/DibiObject.php @@ -39,7 +39,7 @@ * Adding method to class (i.e. to all instances) works similar to JavaScript * prototype property. The syntax for adding a new method is: * - * MyClass::extensionMethod('newMethod', function(MyClass $obj, $arg, ...) { ... }); + * MyClass::extensionMethod('newMethod', function (MyClass $obj, $arg, ...) { ... }); * $obj = new MyClass; * $obj->newMethod($x); * diff --git a/dibi/libs/DibiResult.php b/dibi/libs/DibiResult.php index 2dcd4a6..21fdc54 100644 --- a/dibi/libs/DibiResult.php +++ b/dibi/libs/DibiResult.php @@ -109,7 +109,7 @@ class DibiResult extends DibiObject implements IDataSource /** * Moves cursor position without fetching row. * @param int the 0-based cursor pos to seek to - * @return boolean 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 DibiException */ final public function seek($row) @@ -188,7 +188,7 @@ class DibiResult extends DibiObject implements IDataSource /** * Fetches the row at current position, process optional type conversion. * and moves the internal cursor to the next position - * @return DibiRow|FALSE array on success, FALSE if no next record + * @return DibiRow|FALSE array on success, FALSE if no next record */ final public function fetch() { @@ -209,7 +209,7 @@ class DibiResult extends DibiObject implements IDataSource /** * Like fetch(), but returns only first field. - * @return mixed value on success, FALSE if no next record + * @return mixed value on success, FALSE if no next record */ final public function fetchSingle() { @@ -303,16 +303,16 @@ class DibiResult extends DibiObject implements IDataSource $x = & $x[]; } elseif ($as === '=') { // "value" node - $x = $row->{$assoc[$i+1]}; + $x = $row->{$assoc[$i + 1]}; continue 2; } elseif ($as === '->') { // "object" node if ($x === NULL) { $x = clone $row; - $x = & $x->{$assoc[$i+1]}; + $x = & $x->{$assoc[$i + 1]}; $x = NULL; // prepare child node } else { - $x = & $x->{$assoc[$i+1]}; + $x = & $x->{$assoc[$i + 1]}; } } elseif ($as !== '|') { // associative-array node @@ -369,22 +369,21 @@ class DibiResult extends DibiObject implements IDataSource } elseif ($as === '=') { // "record" node if ($x === NULL) { $x = $row->toArray(); - $x = & $x[ $assoc[$i+1] ]; + $x = & $x[ $assoc[$i + 1] ]; $x = NULL; // prepare child node } else { - $x = & $x[ $assoc[$i+1] ]; + $x = & $x[ $assoc[$i + 1] ]; } } elseif ($as === '@') { // "object" node if ($x === NULL) { $x = clone $row; - $x = & $x->{$assoc[$i+1]}; + $x = & $x->{$assoc[$i + 1]}; $x = NULL; // prepare child node } else { - $x = & $x->{$assoc[$i+1]}; + $x = & $x->{$assoc[$i + 1]}; } - } else { // associative-array node $x = & $x[$row->$as]; } @@ -424,7 +423,7 @@ class DibiResult extends DibiObject implements IDataSource if ($value === NULL) { if ($key !== NULL) { - throw new InvalidArgumentException("Either none or both columns must be specified."); + throw new InvalidArgumentException('Either none or both columns must be specified.'); } // autodetect @@ -478,7 +477,8 @@ class DibiResult extends DibiObject implements IDataSource foreach ($this->getResultDriver()->getResultColumns() as $col) { $this->types[$col['name']] = $cache->{$col['nativetype']}; } - } catch (DibiNotSupportedException $e) {} + } catch (DibiNotSupportedException $e) { + } } @@ -619,7 +619,7 @@ class DibiResult extends DibiObject implements IDataSource foreach ($row as $col => $val) { $spaces = $maxLen - mb_strlen($col) + 2; - echo "$col" . str_repeat(" ", $spaces) . "$val\n"; + echo "$col" . str_repeat(' ', $spaces) . "$val\n"; } echo "\n"; diff --git a/dibi/libs/DibiTranslator.php b/dibi/libs/DibiTranslator.php index b38ee5f..bc862d1 100644 --- a/dibi/libs/DibiTranslator.php +++ b/dibi/libs/DibiTranslator.php @@ -160,7 +160,7 @@ final class DibiTranslator extends DibiObject if ($comment) { - $sql[] = "*/"; + $sql[] = '*/'; } $sql = implode(' ', $sql); @@ -187,7 +187,7 @@ final class DibiTranslator extends DibiObject public function formatValue($value, $modifier) { if ($this->comment) { - return "..."; + return '...'; } if (!$this->driver) { @@ -494,7 +494,7 @@ final class DibiTranslator extends DibiObject if ($cursor >= count($this->args)) { $this->hasError = TRUE; - return "**Extra placeholder**"; + return '**Extra placeholder**'; } $cursor++; @@ -517,7 +517,7 @@ final class DibiTranslator extends DibiObject // open comment $this->ifLevelStart = $this->ifLevel; $this->comment = TRUE; - return "/*"; + return '/*'; } return ''; @@ -525,11 +525,11 @@ final class DibiTranslator extends DibiObject if ($this->ifLevelStart === $this->ifLevel) { $this->ifLevelStart = 0; $this->comment = FALSE; - return "*/"; + return '*/'; } elseif (!$this->comment) { $this->ifLevelStart = $this->ifLevel; $this->comment = TRUE; - return "/*"; + return '/*'; } } elseif ($mod === 'end') { @@ -538,7 +538,7 @@ final class DibiTranslator extends DibiObject // close comment $this->ifLevelStart = 0; $this->comment = FALSE; - return "*/"; + return '*/'; } return ''; @@ -583,10 +583,10 @@ final class DibiTranslator extends DibiObject return $this->identifiers->{$matches[2]}; } elseif ($matches[3]) { // SQL strings: '...' - return $this->driver->escape( str_replace("''", "'", $matches[4]), dibi::TEXT); + return $this->driver->escape(str_replace("''", "'", $matches[4]), dibi::TEXT); } elseif ($matches[5]) { // SQL strings: "..." - return $this->driver->escape( str_replace('""', '"', $matches[6]), dibi::TEXT); + return $this->driver->escape(str_replace('""', '"', $matches[6]), dibi::TEXT); } elseif ($matches[7]) { // string quote $this->hasError = TRUE; diff --git a/examples/connecting-to-databases.php b/examples/connecting-to-databases.php index bd383a4..dd64cd2 100644 --- a/examples/connecting-to-databases.php +++ b/examples/connecting-to-databases.php @@ -11,11 +11,10 @@ require __DIR__ . '/../dibi/dibi.php'; echo '

Connecting to Sqlite: '; try { dibi::connect(array( - 'driver' => 'sqlite3', + 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', )); echo 'OK'; - } catch (DibiException $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; } @@ -26,11 +25,10 @@ echo "

\n"; echo '

Connecting to Sqlite: '; try { $connection = new DibiConnection(array( - 'driver' => 'sqlite3', + 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', )); echo 'OK'; - } catch (DibiException $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; } @@ -42,7 +40,6 @@ echo '

Connecting to MySQL: '; try { dibi::connect('driver=mysql&host=localhost&username=root&password=xxx&database=test&charset=cp1250'); echo 'OK'; - } catch (DibiException $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; } @@ -53,18 +50,17 @@ echo "

\n"; echo '

Connecting to MySQLi: '; try { dibi::connect(array( - 'driver' => 'mysqli', - 'host' => 'localhost', + 'driver' => 'mysqli', + 'host' => 'localhost', 'username' => 'root', 'password' => 'xxx', 'database' => 'dibi', - 'options' => array( - MYSQLI_OPT_CONNECT_TIMEOUT => 30 + 'options' => array( + MYSQLI_OPT_CONNECT_TIMEOUT => 30, ), - 'flags' => MYSQLI_CLIENT_COMPRESS, + 'flags' => MYSQLI_CLIENT_COMPRESS, )); echo 'OK'; - } catch (DibiException $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; } @@ -75,13 +71,12 @@ echo "

\n"; echo '

Connecting to ODBC: '; try { dibi::connect(array( - 'driver' => 'odbc', + 'driver' => 'odbc', 'username' => 'root', 'password' => '***', - 'dsn' => 'Driver={Microsoft Access Driver (*.mdb)};Dbq='.__DIR__.'/data/sample.mdb', + 'dsn' => 'Driver={Microsoft Access Driver (*.mdb)};Dbq='.__DIR__.'/data/sample.mdb', )); echo 'OK'; - } catch (DibiException $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; } @@ -92,12 +87,11 @@ echo "

\n"; echo '

Connecting to PostgreSql: '; try { dibi::connect(array( - 'driver' => 'postgre', - 'string' => 'host=localhost port=5432 dbname=mary', + 'driver' => 'postgre', + 'string' => 'host=localhost port=5432 dbname=mary', 'persistent' => TRUE, )); echo 'OK'; - } catch (DibiException $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; } @@ -108,11 +102,10 @@ echo "

\n"; echo '

Connecting to Sqlite via PDO: '; try { dibi::connect(array( - 'driver' => 'pdo', - 'dsn' => 'sqlite2::memory:', + 'driver' => 'pdo', + 'dsn' => 'sqlite2::memory:', )); echo 'OK'; - } catch (DibiException $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; } @@ -123,13 +116,12 @@ echo "

\n"; echo '

Connecting to MS SQL: '; try { dibi::connect(array( - 'driver' => 'mssql', - 'host' => 'localhost', + 'driver' => 'mssql', + 'host' => 'localhost', 'username' => 'root', 'password' => 'xxx', )); echo 'OK'; - } catch (DibiException $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; } @@ -140,14 +132,13 @@ echo "

\n"; echo '

Connecting to MS SQL 2005: '; try { dibi::connect(array( - 'driver' => 'mssql2005', - 'host' => '(local)', + 'driver' => 'mssql2005', + 'host' => '(local)', 'username' => 'Administrator', 'password' => 'xxx', 'database' => 'main', )); echo 'OK'; - } catch (DibiException $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; } @@ -158,13 +149,12 @@ echo "

\n"; echo '

Connecting to Oracle: '; try { dibi::connect(array( - 'driver' => 'oracle', + 'driver' => 'oracle', 'username' => 'root', 'password' => 'xxx', 'database' => 'db', )); echo 'OK'; - } catch (DibiException $e) { echo get_class($e), ': ', $e->getMessage(), "\n"; } diff --git a/examples/database-reflection.php b/examples/database-reflection.php index 73da28f..e166000 100644 --- a/examples/database-reflection.php +++ b/examples/database-reflection.php @@ -8,7 +8,7 @@ require __DIR__ . '/../dibi/dibi.php'; dibi::connect(array( - 'driver' => 'sqlite3', + 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', )); @@ -37,7 +37,7 @@ foreach ($table->getColumns() as $column) { echo "\n"; -echo "Indexes"; +echo 'Indexes'; echo "

    \n"; foreach ($table->getIndexes() as $index) { echo "
  • {$index->name} " . ($index->primary ? 'primary ' : '') . ($index->unique ? 'unique' : '') . ' ('; diff --git a/examples/dumping-sql-and-result-set.php b/examples/dumping-sql-and-result-set.php index fedc3e0..5d7b4a0 100644 --- a/examples/dumping-sql-and-result-set.php +++ b/examples/dumping-sql-and-result-set.php @@ -8,7 +8,7 @@ require __DIR__ . '/../dibi/dibi.php'; dibi::connect(array( - 'driver' => 'sqlite3', + 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', )); diff --git a/examples/fetching-examples.php b/examples/fetching-examples.php index 6710b6a..329ae35 100644 --- a/examples/fetching-examples.php +++ b/examples/fetching-examples.php @@ -12,7 +12,7 @@ Tracy\Debugger::enable(); dibi::connect(array( - 'driver' => 'sqlite3', + 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', )); diff --git a/examples/importing-dump-from-file.php b/examples/importing-dump-from-file.php index 35972ff..9ef0ef7 100644 --- a/examples/importing-dump-from-file.php +++ b/examples/importing-dump-from-file.php @@ -8,7 +8,7 @@ require __DIR__ . '/../dibi/dibi.php'; dibi::connect(array( - 'driver' => 'sqlite3', + 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', )); diff --git a/examples/query-language-and-conditions.php b/examples/query-language-and-conditions.php index 69df521..13e5eea 100644 --- a/examples/query-language-and-conditions.php +++ b/examples/query-language-and-conditions.php @@ -8,7 +8,7 @@ require __DIR__ . '/../dibi/dibi.php'; dibi::connect(array( - 'driver' => 'sqlite3', + 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', )); @@ -32,13 +32,13 @@ dibi::test(' // if & else & (optional) end -dibi::test(" +dibi::test(' SELECT * FROM people WHERE id > 0 - %if", ($foo > 0), "AND foo=?", $foo, " - %else %if", ($bar > 0), "AND bar=?", $bar, " -"); + %if', ($foo > 0), 'AND foo=?', $foo, ' + %else %if', ($bar > 0), 'AND bar=?', $bar, ' +'); // -> SELECT * FROM people WHERE id > 0 AND bar=2 diff --git a/examples/query-language-basic-examples.php b/examples/query-language-basic-examples.php index bb829b8..450e2ec 100644 --- a/examples/query-language-basic-examples.php +++ b/examples/query-language-basic-examples.php @@ -10,7 +10,7 @@ date_default_timezone_set('Europe/Prague'); dibi::connect(array( - 'driver' => 'sqlite3', + 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', )); @@ -45,26 +45,26 @@ $array = array( 'brand' => NULL, 'created' => new DateTime, ); -dibi::test("INSERT INTO products", $array, $array, $array); +dibi::test('INSERT INTO products', $array, $array, $array); // -> INSERT INTO products ([title], [price], [brand], [created]) VALUES ('Super Product', ...) , (...) , (...) // dibi detects UPDATE command -dibi::test(" - UPDATE colors SET", array( +dibi::test(' + UPDATE colors SET', array( 'color' => 'blue', 'order' => 12, - ), " - WHERE id=?", 123); + ), ' + WHERE id=?', 123); // -> UPDATE colors SET [color]='blue', [order]=12 WHERE id=123 // modifier applied to array $array = array(1, 2, 3); -dibi::test(" +dibi::test(' SELECT * FROM people - WHERE id IN (?)", $array + WHERE id IN (?)', $array ); // -> SELECT * FROM people WHERE id IN ( 1, 2, 3 ) @@ -74,11 +74,11 @@ $order = array( 'field1' => 'asc', 'field2' => 'desc', ); -dibi::test(" +dibi::test(' SELECT * FROM people - ORDER BY %by", $order, " -"); + ORDER BY %by', $order, ' +'); // -> SELECT * FROM people ORDER BY [field1] ASC, [field2] DESC diff --git a/examples/result-set-data-types.php b/examples/result-set-data-types.php index 60db319..db6ab3f 100644 --- a/examples/result-set-data-types.php +++ b/examples/result-set-data-types.php @@ -14,7 +14,7 @@ date_default_timezone_set('Europe/Prague'); dibi::connect(array( - 'driver' => 'sqlite3', + 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', )); @@ -27,7 +27,7 @@ $res->setType('customer_id', Dibi::INTEGER) ->setFormat(dibi::DATETIME, 'Y-m-d H:i:s'); -Tracy\Dumper::dump( $res->fetch() ); +Tracy\Dumper::dump($res->fetch()); // outputs: // DibiRow(3) { // customer_id => 1 @@ -38,7 +38,7 @@ Tracy\Dumper::dump( $res->fetch() ); // using auto-detection (works well with MySQL or other strictly typed databases) $res = dibi::query('SELECT * FROM [customers]'); -Tracy\Dumper::dump( $res->fetch() ); +Tracy\Dumper::dump($res->fetch()); // outputs: // DibiRow(3) { // customer_id => 1 diff --git a/examples/tracy-and-exceptions.php b/examples/tracy-and-exceptions.php index d5f4a4e..f5d8890 100644 --- a/examples/tracy-and-exceptions.php +++ b/examples/tracy-and-exceptions.php @@ -16,11 +16,11 @@ Tracy\Debugger::enable(); $connection = dibi::connect(array( - 'driver' => 'sqlite3', + 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', 'profiler' => array( 'run' => TRUE, - ) + ), )); diff --git a/examples/tracy.php b/examples/tracy.php index 5e5d820..53b3b4f 100644 --- a/examples/tracy.php +++ b/examples/tracy.php @@ -18,11 +18,11 @@ Tracy\Debugger::enable(); $connection = dibi::connect(array( - 'driver' => 'sqlite3', + 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', 'profiler' => array( 'run' => TRUE, - ) + ), )); @@ -35,4 +35,4 @@ $panel->register($connection); dibi::query('SELECT 123'); // result set will be dumped -Tracy\Debugger::barDump( dibi::fetchAll('SELECT * FROM customers WHERE customer_id < ?', 38), '[customers]' ); +Tracy\Debugger::barDump(dibi::fetchAll('SELECT * FROM customers WHERE customer_id < ?', 38), '[customers]'); diff --git a/examples/using-datetime.php b/examples/using-datetime.php index 626f510..d6df9e8 100644 --- a/examples/using-datetime.php +++ b/examples/using-datetime.php @@ -11,7 +11,7 @@ date_default_timezone_set('Europe/Prague'); // CHANGE TO REAL PARAMETERS! dibi::connect(array( - 'driver' => 'sqlite3', + 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', 'formatDate' => "'Y-m-d'", 'formatDateTime' => "'Y-m-d H-i-s'", @@ -19,10 +19,10 @@ dibi::connect(array( // generate and dump SQL -dibi::test(" - INSERT INTO [mytable]", array( - 'id' => 123, - 'date' => new DateTime('12.3.2007'), +dibi::test(' + INSERT INTO [mytable]', array( + 'id' => 123, + 'date' => new DateTime('12.3.2007'), 'stamp' => new DateTime('23.1.2007 10:23'), ) ); diff --git a/examples/using-extension-methods.php b/examples/using-extension-methods.php index 5337a68..394584e 100644 --- a/examples/using-extension-methods.php +++ b/examples/using-extension-methods.php @@ -12,14 +12,13 @@ Tracy\Debugger::enable(); dibi::connect(array( - 'driver' => 'sqlite3', + 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', )); // using the "prototype" to add custom method to class DibiResult -DibiResult::extensionMethod('fetchShuffle', function(DibiResult $obj) -{ +DibiResult::extensionMethod('fetchShuffle', function (DibiResult $obj) { $all = $obj->fetchAll(); shuffle($all); return $all; diff --git a/examples/using-fluent-syntax.php b/examples/using-fluent-syntax.php index 85e2cf8..37b7692 100644 --- a/examples/using-fluent-syntax.php +++ b/examples/using-fluent-syntax.php @@ -10,15 +10,15 @@ date_default_timezone_set('Europe/Prague'); dibi::connect(array( - 'driver' => 'sqlite3', + 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', )); $id = 10; $record = array( - 'title' => 'Super product', - 'price' => 318, + 'title' => 'Super product', + 'price' => 318, 'active' => TRUE, ); diff --git a/examples/using-limit-and-offset.php b/examples/using-limit-and-offset.php index dcc37c1..c27e8a3 100644 --- a/examples/using-limit-and-offset.php +++ b/examples/using-limit-and-offset.php @@ -8,7 +8,7 @@ require __DIR__ . '/../dibi/dibi.php'; dibi::connect(array( - 'driver' => 'sqlite3', + 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', )); diff --git a/examples/using-logger.php b/examples/using-logger.php index e207bff..5472baa 100644 --- a/examples/using-logger.php +++ b/examples/using-logger.php @@ -10,7 +10,7 @@ date_default_timezone_set('Europe/Prague'); dibi::connect(array( - 'driver' => 'sqlite3', + 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', // enable query logging to this file 'profiler' => array( @@ -26,13 +26,12 @@ try { $res = dibi::query('SELECT * FROM [customers] WHERE [customer_id] < ?', 5); $res = dibi::query('SELECT FROM [customers] WHERE [customer_id] < ?', 38); - } catch (DibiException $e) { echo '

    ', get_class($e), ': ', $e->getMessage(), '

    '; } // outputs a log file -echo "

    File data/log.sql:

    "; +echo '

    File data/log.sql:

    '; echo '
    ', file_get_contents('data/log.sql'), '
    '; diff --git a/examples/using-profiler.php b/examples/using-profiler.php index 12e1033..fa4a06d 100644 --- a/examples/using-profiler.php +++ b/examples/using-profiler.php @@ -10,16 +10,16 @@ require __DIR__ . '/../dibi/dibi.php'; dibi::connect(array( - 'driver' => 'sqlite3', + 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', 'profiler' => array( 'run' => TRUE, - ) + ), )); // execute some queries... -for ($i=0; $i<20; $i++) { +for ($i = 0; $i < 20; $i++) { $res = dibi::query('SELECT * FROM [customers] WHERE [customer_id] < ?', $i); } diff --git a/examples/using-substitutions.php b/examples/using-substitutions.php index cfd5ffe..6fed85a 100644 --- a/examples/using-substitutions.php +++ b/examples/using-substitutions.php @@ -8,7 +8,7 @@ require __DIR__ . '/../dibi/dibi.php'; dibi::connect(array( - 'driver' => 'sqlite3', + 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', )); @@ -16,7 +16,7 @@ dibi::connect(array( // create new substitution :blog: ==> wp_ dibi::getSubstitutes()->blog = 'wp_'; -dibi::test("SELECT * FROM [:blog:items]"); +dibi::test('SELECT * FROM [:blog:items]'); // -> SELECT * FROM [wp_items] diff --git a/examples/using-transactions.php b/examples/using-transactions.php index d7319fd..416bf9f 100644 --- a/examples/using-transactions.php +++ b/examples/using-transactions.php @@ -8,7 +8,7 @@ require __DIR__ . '/../dibi/dibi.php'; dibi::connect(array( - 'driver' => 'sqlite3', + 'driver' => 'sqlite3', 'database' => 'data/sample.s3db', )); diff --git a/tests/dibi/DataSource.phpt b/tests/dibi/DataSource.phpt index 1725afb..5385c9c 100644 --- a/tests/dibi/DataSource.phpt +++ b/tests/dibi/DataSource.phpt @@ -11,9 +11,9 @@ $conn->loadFile(__DIR__ . "/data/$config[system].sql"); $ds = $conn->dataSource('SELECT * FROM products'); Assert::match( - reformat(" + reformat(' SELECT * -FROM (SELECT * FROM products) t"), +FROM (SELECT * FROM products) t'), (string) $ds ); @@ -111,9 +111,9 @@ FROM (SELECT * FROM products) t $ds = $conn->select('title')->from('products')->toDataSource(); Assert::match( - reformat(" + reformat(' SELECT * -FROM (SELECT [title] FROM [products]) t"), +FROM (SELECT [title] FROM [products]) t'), (string) $ds ); @@ -148,9 +148,9 @@ Assert::equal(array( $ds = new DibiDataSource('products', $conn); Assert::match( - reformat(" + reformat(' SELECT * -FROM [products]"), +FROM [products]'), (string) $ds ); diff --git a/tests/dibi/DibiConnection.connect.phpt b/tests/dibi/DibiConnection.connect.phpt index f751745..e5b94c2 100644 --- a/tests/dibi/DibiConnection.connect.phpt +++ b/tests/dibi/DibiConnection.connect.phpt @@ -9,7 +9,7 @@ use Tester\Assert; require __DIR__ . '/bootstrap.php'; -test(function() use ($config) { +test(function () use ($config) { $conn = new DibiConnection($config); Assert::true($conn->isConnected()); @@ -18,7 +18,7 @@ test(function() use ($config) { }); -test(function() use ($config) { // lazy +test(function () use ($config) { // lazy $conn = new DibiConnection($config + array('lazy' => TRUE)); Assert::false($conn->isConnected()); @@ -27,7 +27,7 @@ test(function() use ($config) { // lazy }); -test(function() use ($config) { // query string +test(function () use ($config) { // query string $conn = new DibiConnection(http_build_query($config, NULL, '&')); Assert::true($conn->isConnected()); diff --git a/tests/dibi/DibiConnection.transactions.phpt b/tests/dibi/DibiConnection.transactions.phpt index a11f96d..088c7ae 100644 --- a/tests/dibi/DibiConnection.transactions.phpt +++ b/tests/dibi/DibiConnection.transactions.phpt @@ -13,16 +13,16 @@ $conn = new DibiConnection($config); $conn->loadFile(__DIR__ . "/data/$config[system].sql"); -/*Assert::exception(function() use ($conn) { +/*Assert::exception(function () use ($conn) { $conn->rollback(); }, 'DibiException'); -Assert::exception(function() use ($conn) { +Assert::exception(function () use ($conn) { $conn->commit(); }, 'DibiException'); $conn->begin(); -Assert::exception(function() use ($conn) { +Assert::exception(function () use ($conn) { $conn->begin(); }, 'DibiException'); */ diff --git a/tests/dibi/DibiFluent.cloning.phpt b/tests/dibi/DibiFluent.cloning.phpt index f2317de..5b6c550 100644 --- a/tests/dibi/DibiFluent.cloning.phpt +++ b/tests/dibi/DibiFluent.cloning.phpt @@ -13,23 +13,23 @@ $dolly = clone $fluent; $dolly->where('y=1'); $dolly->clause('FOO'); -Assert::same( reformat('SELECT * FROM [table] WHERE x=1'), (string) $fluent ); -Assert::same( reformat('SELECT * FROM [table] WHERE x=1 AND y=1 FOO'), (string) $dolly ); +Assert::same(reformat('SELECT * FROM [table] WHERE x=1'), (string) $fluent); +Assert::same(reformat('SELECT * FROM [table] WHERE x=1 AND y=1 FOO'), (string) $dolly); $fluent = new DibiFluent($conn); -$fluent->select('id')->from('table')->where('id = %i',1); +$fluent->select('id')->from('table')->where('id = %i', 1); $dolly = clone $fluent; -$dolly->where('cd = %i',5); +$dolly->where('cd = %i', 5); -Assert::same( reformat('SELECT [id] FROM [table] WHERE id = 1'), (string) $fluent ); -Assert::same( reformat('SELECT [id] FROM [table] WHERE id = 1 AND cd = 5'), (string) $dolly ); +Assert::same(reformat('SELECT [id] FROM [table] WHERE id = 1'), (string) $fluent); +Assert::same(reformat('SELECT [id] FROM [table] WHERE id = 1 AND cd = 5'), (string) $dolly); $fluent = new DibiFluent($conn); -$fluent->select("*")->from("table"); +$fluent->select('*')->from('table'); $dolly = clone $fluent; -$dolly->removeClause("select")->select("count(*)"); +$dolly->removeClause('select')->select('count(*)'); -Assert::same( reformat('SELECT * FROM [table]'), (string) $fluent ); -Assert::same( reformat('SELECT count(*) FROM [table]'), (string) $dolly ); +Assert::same(reformat('SELECT * FROM [table]'), (string) $fluent); +Assert::same(reformat('SELECT count(*) FROM [table]'), (string) $dolly); diff --git a/tests/dibi/DibiFluent.insert.phpt b/tests/dibi/DibiFluent.insert.phpt index 698324f..24b988f 100644 --- a/tests/dibi/DibiFluent.insert.phpt +++ b/tests/dibi/DibiFluent.insert.phpt @@ -9,9 +9,9 @@ $conn = new DibiConnection($config); $arr = array( - 'title' => 'Super Product', - 'price' => 12, - 'brand' => NULL, + 'title' => 'Super Product', + 'price' => 12, + 'brand' => NULL, ); $fluent = $conn->insert('table', $arr) diff --git a/tests/dibi/DibiFluent.select.phpt b/tests/dibi/DibiFluent.select.phpt index bdb67ee..617d02a 100644 --- a/tests/dibi/DibiFluent.select.phpt +++ b/tests/dibi/DibiFluent.select.phpt @@ -58,7 +58,7 @@ Assert::same( $fluent->where('col > %i', $max) ->or('col < %i', $min) ->where('active = 1') - ->where('col')->in(array(1,2,3)) + ->where('col')->in(array(1, 2, 3)) ->orderBy('val')->asc() ->orderBy('[val2] DESC') ->orderBy(array('val3' => -1)); diff --git a/tests/dibi/DibiFluent.update.phpt b/tests/dibi/DibiFluent.update.phpt index fde198f..587bdcf 100644 --- a/tests/dibi/DibiFluent.update.phpt +++ b/tests/dibi/DibiFluent.update.phpt @@ -9,9 +9,9 @@ $conn = new DibiConnection($config); $arr = array( - 'title' => 'Super Product', - 'price' => 12, - 'brand' => NULL, + 'title' => 'Super Product', + 'price' => 12, + 'brand' => NULL, ); $fluent = $conn->update('table', $arr) diff --git a/tests/dibi/DibiTranslator.conditions.phpt b/tests/dibi/DibiTranslator.conditions.phpt index 8024f70..4be4b68 100644 --- a/tests/dibi/DibiTranslator.conditions.phpt +++ b/tests/dibi/DibiTranslator.conditions.phpt @@ -13,10 +13,10 @@ $conn = new DibiConnection($config); // if & end Assert::same( - reformat(" + reformat(' SELECT * FROM [customers] -/* WHERE ... LIKE ... */"), +/* WHERE ... LIKE ... */'), $conn->translate(' SELECT * @@ -27,9 +27,9 @@ FROM [customers] // if & else & end (last end is optional) Assert::same( - reformat(" + reformat(' SELECT * -FROM [customers] /* ... */"), +FROM [customers] /* ... */'), $conn->translate(' SELECT * @@ -39,21 +39,21 @@ FROM %if', TRUE, '[customers] %else [products]' // if & else & (optional) end Assert::match( - reformat(" + reformat(' SELECT * FROM [people] WHERE [id] > 0 /* AND ...=... */ AND [bar]=1 -"), +'), - $conn->translate(" + $conn->translate(' 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, ' +')); // nested condition diff --git a/tests/dibi/DibiTranslator.phpt b/tests/dibi/DibiTranslator.phpt index 84776ae..f59eb06 100644 --- a/tests/dibi/DibiTranslator.phpt +++ b/tests/dibi/DibiTranslator.phpt @@ -15,32 +15,32 @@ $conn = new DibiConnection($config + array('formatDateTime' => "'Y-m-d H:i:s'", Assert::same( reformat("REPLACE INTO [products] ([title], [price]) VALUES ('Drticka', 318)"), $conn->translate('REPLACE INTO [products]', array( - 'title' => 'Drticka', - 'price' => 318, + 'title' => 'Drticka', + 'price' => 318, ))); // multiple INSERT command $array = array( - 'title' => 'Super Product', - 'price' => 12, - 'brand' => NULL, + 'title' => 'Super Product', + 'price' => 12, + 'brand' => NULL, ); Assert::same( reformat('INSERT INTO [products] ([title], [price], [brand]) VALUES (\'Super Product\', 12, NULL) , (\'Super Product\', 12, NULL) , (\'Super Product\', 12, NULL)'), - $conn->translate("INSERT INTO [products]", $array, $array, $array) + $conn->translate('INSERT INTO [products]', $array, $array, $array) ); // multiple INSERT command II $array = array( - array('pole' => 'hodnota1', 'bit' => 1), - array('pole' => 'hodnota2', 'bit' => 1), - array('pole' => 'hodnota3', 'bit' => 1) + array('pole' => 'hodnota1', 'bit' => 1), + array('pole' => 'hodnota2', 'bit' => 1), + array('pole' => 'hodnota3', 'bit' => 1), ); Assert::same( reformat('INSERT INTO [products] ([pole], [bit]) VALUES (\'hodnota1\', 1) , (\'hodnota2\', 1) , (\'hodnota3\', 1)'), - $conn->translate("INSERT INTO [products] %ex", $array) + $conn->translate('INSERT INTO [products] %ex', $array) ); @@ -50,32 +50,32 @@ Assert::same( $conn->translate('UPDATE [colors] SET', array( 'color' => 'blue', 'order' => 12, -), "WHERE [id]=%i", 123)); +), 'WHERE [id]=%i', 123)); // IN array $array = array(1, 2, 3); Assert::same( reformat('SELECT * FROM [people] WHERE [id] IN ( 1, 2, 3 )'), - $conn->translate("SELECT * FROM [people] WHERE [id] IN (", $array, ")") + $conn->translate('SELECT * FROM [people] WHERE [id] IN (', $array, ')') ); // long numbers Assert::same( reformat('SELECT -123456789123456789123456789'), - $conn->translate("SELECT %i", '-123456789123456789123456789') + $conn->translate('SELECT %i', '-123456789123456789123456789') ); // long float numbers Assert::same( reformat('SELECT -.12345678912345678912345678e10'), - $conn->translate("SELECT %f", '-.12345678912345678912345678e10') + $conn->translate('SELECT %f', '-.12345678912345678912345678e10') ); // invalid input -$e = Assert::exception(function() use ($conn) { - $conn->translate("SELECT %s", (object) array(123), ', %m', 123); +$e = Assert::exception(function () use ($conn) { + $conn->translate('SELECT %s', (object) array(123), ', %m', 123); }, 'DibiException', 'SQL translate error'); Assert::same('SELECT **Unexpected type object** , **Unknown or invalid modifier %m**', $e->getSql()); @@ -131,8 +131,8 @@ $order = array( 'field6' => FALSE, ); Assert::same( - reformat("SELECT * FROM [people] ORDER BY [field1] ASC, [field2] DESC, [field3] ASC, [field4] DESC, [field5] ASC, [field6] DESC"), - $conn->translate("SELECT * FROM [people] ORDER BY %by", $order) + reformat('SELECT * FROM [people] ORDER BY [field1] ASC, [field2] DESC, [field3] ASC, [field4] DESC, [field5] ASC, [field6] DESC'), + $conn->translate('SELECT * FROM [people] ORDER BY %by', $order) ); @@ -146,7 +146,7 @@ Assert::same( ); if ($config['system'] === 'odbc') { - Assert::exception(function() use ($conn) { + Assert::exception(function () use ($conn) { $conn->translate('SELECT * FROM [products] %lmt %ofs', 2, 1); }, 'DibiException'); } else { @@ -175,7 +175,7 @@ Assert::same( 'odbc' => 'INSERT INTO test ([a2], [a4], [b1], [b2], [b3], [b4], [b5], [b6], [b7], [b8], [b9]) VALUES (#09/26/1212 00:00:00#, #12/31/1969 22:13:20#, #09/26/1212#, #09/26/1212 00:00:00#, #12/31/1969#, #12/31/1969 22:13:20#, #09/26/1212 00:00:00#, #09/26/1212#, #09/26/1212 00:00:00#, NULL, NULL)', "INSERT INTO test ([a2], [a4], [b1], [b2], [b3], [b4], [b5], [b6], [b7], [b8], [b9]) VALUES ('1212-09-26 00:00:00', '1969-12-31 22:13:20', '1212-09-26', '1212-09-26 00:00:00', '1969-12-31', '1969-12-31 22:13:20', '1212-09-26 00:00:00', '1212-09-26', '1212-09-26 00:00:00', NULL, NULL)", )), - $conn->translate("INSERT INTO test", array( + $conn->translate('INSERT INTO test', array( 'a2' => new DibiDateTime('1212-09-26'), 'a4' => new DibiDateTime(-10000), 'b1%d' => '1212-09-26', @@ -193,10 +193,10 @@ Assert::same( // like $args = array( - "SELECT * FROM products WHERE (title LIKE %like~ AND title LIKE %~like) OR title LIKE %~like~", + 'SELECT * FROM products WHERE (title LIKE %like~ AND title LIKE %~like) OR title LIKE %~like~', 'C', 'r', - "a\n%_\\'\"" + "a\n%_\\'\"", ); if ($config['system'] === 'pgsql') { @@ -213,7 +213,6 @@ if ($config['system'] === 'pgsql') { "SELECT * FROM products WHERE (title LIKE 'C%' AND title LIKE '%r') OR title LIKE '%a\n\\%\\_\\\\''\"%'", $conn->translate($args[0], $args[1], $args[2], $args[3]) ); - } elseif ($config['driver'] !== 'sqlite') { // sqlite2 Assert::same( reformat(array( @@ -226,7 +225,7 @@ if ($config['system'] === 'pgsql') { } -$e = Assert::exception(function() use ($conn) { +$e = Assert::exception(function () use ($conn) { $conn->translate("SELECT '"); }, 'DibiException', 'SQL translate error'); Assert::same('SELECT **Alone quote**', $e->getSql()); @@ -248,12 +247,12 @@ HAVING MAX(salary) > %i 123 INTO OUTFILE '/tmp/result''.txt' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\\n' -" +", )), - $conn->translate('%sql', "SELECT DISTINCT HIGH_PRIORITY SQL_BUFFER_RESULT -CONCAT(last_name, \", \", first_name) AS full_name + $conn->translate('%sql', 'SELECT DISTINCT HIGH_PRIORITY SQL_BUFFER_RESULT +CONCAT(last_name, ", ", first_name) AS full_name GROUP BY [user] -HAVING MAX(salary) > %i", 123, " +HAVING MAX(salary) > %i', 123, " INTO OUTFILE '/tmp/result''.txt' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\\n' @@ -272,10 +271,10 @@ $array3 = array( 'col3' => 'three', ); $array4 = array( - 'a' => 12, - 'b' => NULL, - 'c' => new DibiDateTime('12.3.2007'), - 'd' => 'any string', + 'a' => 12, + 'b' => NULL, + 'c' => new DibiDateTime('12.3.2007'), + 'd' => 'any string', ); $array5 = array('RAND()', '[col1] > [col2]'); @@ -365,26 +364,26 @@ WHERE ([test].[a] LIKE '1995-03-01' LIMIT 10", )), - $conn->translate("SELECT * + $conn->translate('SELECT * FROM [db.table] -WHERE ([test.a] LIKE %d", '1995-03-01', " - OR [b1] IN (", $array1, ") - OR [b2] IN (%s", $array1, ") - OR [b3] IN (%s", array(), ") - OR [b4] IN (", $array2, ") - OR [b5] IN (%n", $array3, ") - OR [b6] IN %l", $array3, " - OR [b7] IN %in", array(), " - OR [b8] IN (%sql", $array5, ") - OR [b9] IN (", array(), ") +WHERE ([test.a] LIKE %d', '1995-03-01', ' + OR [b1] IN (', $array1, ') + OR [b2] IN (%s', $array1, ') + OR [b3] IN (%s', array(), ') + OR [b4] IN (', $array2, ') + OR [b5] IN (%n', $array3, ') + OR [b6] IN %l', $array3, ' + OR [b7] IN %in', array(), ' + OR [b8] IN (%sql', $array5, ') + OR [b9] IN (', array(), ") AND [c] = 'embedded '' string' - OR [d]=%i", 10.3, " - OR [e]=%i", NULL, " - OR [true]=", TRUE, " - OR [false]=", FALSE, " - OR [str_null]=%sn", '', " - OR [str_not_null]=%sn", 'hello', " -LIMIT 10") + OR [d]=%i", 10.3, ' + OR [e]=%i', NULL, ' + OR [true]=', TRUE, ' + OR [false]=', FALSE, ' + OR [str_null]=%sn', '', ' + OR [str_not_null]=%sn', 'hello', ' +LIMIT 10') ); @@ -466,7 +465,7 @@ Assert::same( ); -$e = Assert::exception(function() use ($conn) { +$e = Assert::exception(function () use ($conn) { $array6 = array( 'id' => array(1, 2, 3, 4), 'text' => array('ahoj', 'jak', 'se', array('SUM(%i)', '5')), @@ -488,14 +487,14 @@ Assert::same( ); -$by = array ( +$by = array( array('funkce(nazev_pole) ASC'), - 'jine_pole' => 'DESC' + 'jine_pole' => 'DESC', ); Assert::same( reformat('SELECT * FROM table ORDER BY funkce(nazev_pole) ASC, [jine_pole] DESC'), - $conn->translate("SELECT * FROM table ORDER BY %by", $by) + $conn->translate('SELECT * FROM table ORDER BY %by', $by) ); Assert::same( @@ -514,12 +513,12 @@ setLocale(LC_ALL, 'czech'); Assert::same( reformat("UPDATE [colors] SET [color]='blue', [price]=-12.4, [spec]=-9E-005, [spec2]=1000, [spec3]=10000, [spec4]=10000 WHERE [price]=123.5"), - $conn->translate("UPDATE [colors] SET", array( + $conn->translate('UPDATE [colors] SET', array( 'color' => 'blue', 'price' => -12.4, 'spec%f' => '-9E-005', 'spec2%f' => 1000.00, 'spec3%i' => 10000, 'spec4' => 10000, -), "WHERE [price]=%f", 123.5) +), 'WHERE [price]=%f', 123.5) ); diff --git a/tests/dibi/PdoMssql.limits.phpt b/tests/dibi/PdoMssql.limits.phpt index e12e66c..995381b 100644 --- a/tests/dibi/PdoMssql.limits.phpt +++ b/tests/dibi/PdoMssql.limits.phpt @@ -12,11 +12,11 @@ if ($config['system'] !== 'mssql' || $config['driver'] !== 'pdo') { Tester\Environment::skip("Not supported system '$config[system]'."); } -$tests = function($conn){ +$tests = function ($conn) { $version = $conn->getDriver()->getResource()->getAttribute(PDO::ATTR_SERVER_VERSION); // MsSQL2012+ - if(version_compare($version, '11.0') >= 0) { + if (version_compare($version, '11.0') >= 0) { // Limit and offset Assert::same( 'SELECT 1 OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY', diff --git a/tests/dibi/Postgre.like.phpt b/tests/dibi/Postgre.like.phpt index 72e8785..d1e7fbb 100644 --- a/tests/dibi/Postgre.like.phpt +++ b/tests/dibi/Postgre.like.phpt @@ -13,16 +13,16 @@ if ($config['system'] !== 'pgsql') { } -$tests = function($conn) { +$tests = function ($conn) { Assert::false($conn->query("SELECT 'AAxBB' LIKE %~like~", 'A_B')->fetchSingle()); - Assert::true( $conn->query("SELECT 'AA_BB' LIKE %~like~", 'A_B')->fetchSingle()); + Assert::true($conn->query("SELECT 'AA_BB' LIKE %~like~", 'A_B')->fetchSingle()); Assert::false($conn->query("SELECT 'AAxBB' LIKE %~like~", 'A%B')->fetchSingle()); - Assert::true( $conn->query("SELECT 'AA%BB' LIKE %~like~", 'A%B')->fetchSingle()); + Assert::true($conn->query("SELECT 'AA%BB' LIKE %~like~", 'A%B')->fetchSingle()); Assert::same('AA\\BB', $conn->query("SELECT 'AA\\BB'")->fetchSingle()); Assert::false($conn->query("SELECT 'AAxBB' LIKE %~like~", 'A\\B')->fetchSingle()); - Assert::true( $conn->query("SELECT 'AA\\BB' LIKE %~like~", 'A\\B')->fetchSingle()); + Assert::true($conn->query("SELECT 'AA\\BB' LIKE %~like~", 'A\\B')->fetchSingle()); }; $conn = new DibiConnection($config);