1
0
mirror of https://github.com/dg/dibi.git synced 2025-09-03 19:12:33 +02:00

coding style: fixes in code

This commit is contained in:
David Grudl
2017-07-21 22:28:27 +02:00
parent ebf0be1fd0
commit 4f75637b63
35 changed files with 116 additions and 101 deletions

View File

@@ -143,7 +143,7 @@ class Panel implements Tracy\IBarPanel
#tracy-debug tracy-DibiProfiler tr table { margin: 8px 0; max-height: 150px; overflow:auto } </style>
<h1>Queries: ' . count($this->events)
. ($totalTime === null ? '' : ', time: ' . number_format($totalTime * 1000, 1, '.', '') . 'ms') . ', '
. htmlSpecialChars($connection->getConfig('driver') . ($connection->getConfig('name') ? '/' . $connection->getConfig('name') : '')
. htmlspecialchars($connection->getConfig('driver') . ($connection->getConfig('name') ? '/' . $connection->getConfig('name') : '')
. ($connection->getConfig('host') ? '@' . $connection->getConfig('host') : '')) . '</h1>
<div class="tracy-inner tracy-DibiProfiler">
<table>

View File

@@ -48,7 +48,6 @@ class Connection
* - run (bool) => enable profiler?
* - file => file to log
* - substitutes (array) => map of driver specific substitutes (under development)
* @param mixed connection parameters
* @param string connection name
* @throws Exception

View File

@@ -10,7 +10,6 @@ namespace Dibi;
/**
* Default implementation of IDataSource for dibi.
*
*/
class DataSource implements IDataSource
{

View File

@@ -33,7 +33,7 @@ class DateTime extends \DateTime
public function modifyClone($modify = '')
{
$dolly = clone($this);
$dolly = clone $this;
return $modify ? $dolly->modify($modify) : $dolly;
}

View File

@@ -277,7 +277,7 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
*/
public function escapeIdentifier($value)
{
return '"' . str_replace('"', '""', $value). '"';
return '"' . str_replace('"', '""', $value) . '"';
}
@@ -713,9 +713,9 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
*/
public function getTriggers($table = null)
{
$q = "SELECT TRIM(RDB\$TRIGGER_NAME)
FROM RDB\$TRIGGERS
WHERE RDB\$SYSTEM_FLAG = 0";
$q = 'SELECT TRIM(RDB$TRIGGER_NAME)
FROM RDB$TRIGGERS
WHERE RDB$SYSTEM_FLAG = 0';
$q .= $table === null ? ';' : " AND RDB\$RELATION_NAME = UPPER('$table')";
$res = $this->query($q);
@@ -786,9 +786,9 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
*/
public function getProcedures()
{
$res = $this->query("
SELECT TRIM(RDB\$PROCEDURE_NAME)
FROM RDB\$PROCEDURES;"
$res = $this->query('
SELECT TRIM(RDB$PROCEDURE_NAME)
FROM RDB$PROCEDURES;'
);
$procedures = [];
while ($row = $res->fetch(false)) {
@@ -804,10 +804,10 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
*/
public function getGenerators()
{
$res = $this->query("
SELECT TRIM(RDB\$GENERATOR_NAME)
FROM RDB\$GENERATORS
WHERE RDB\$SYSTEM_FLAG = 0;"
$res = $this->query('
SELECT TRIM(RDB$GENERATOR_NAME)
FROM RDB$GENERATORS
WHERE RDB$SYSTEM_FLAG = 0;'
);
$generators = [];
while ($row = $res->fetch(false)) {
@@ -823,10 +823,10 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
*/
public function getFunctions()
{
$res = $this->query("
SELECT TRIM(RDB\$FUNCTION_NAME)
FROM RDB\$FUNCTIONS
WHERE RDB\$SYSTEM_FLAG = 0;"
$res = $this->query('
SELECT TRIM(RDB$FUNCTION_NAME)
FROM RDB$FUNCTIONS
WHERE RDB$SYSTEM_FLAG = 0;'
);
$functions = [];
while ($row = $res->fetch(false)) {

View File

@@ -357,7 +357,7 @@ class MsSqlDriver implements Dibi\Driver, Dibi\ResultDriver
/**
* 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
*/
public function seek($row)
{

View File

@@ -69,12 +69,12 @@ class MsSqlReflector implements Dibi\Reflector
if (!is_array($row) || count($row) < 1) {
if ($fallback) {
$row = $this->driver->query("SELECT COUNT(*) FROM {$this->driver->escapeIdentifier($table)}")->fetch(false);
$count = intval($row[0]);
$count = (int) ($row[0]);
} else {
$count = false;
}
} else {
$count = intval($row[0]);
$count = (int) ($row[0]);
}
return $count;

View File

@@ -274,7 +274,7 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
$value = new Dibi\DateTime($value);
}
return $value->format("#m/d/Y#");
return $value->format('#m/d/Y#');
}
@@ -287,7 +287,7 @@ class OdbcDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
$value = new Dibi\DateTime($value);
}
return $value->format("#m/d/Y H:i:s.u#");
return $value->format('#m/d/Y H:i:s.u#');
}

View File

@@ -41,7 +41,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
private $autocommit = true;
/** @var string Date and datetime format */
private $fmtDate, $fmtDateTime;
private $fmtDate;
private $fmtDateTime;
/** @var int|false Number of affected rows */
private $affectedRows = false;
@@ -373,7 +374,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
// 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) : '')
. ') WHERE "__rnum" > '. (int) $offset;
. ') WHERE "__rnum" > ' . (int) $offset;
} elseif ($limit !== null) {
$sql = 'SELECT * FROM (' . $sql . ') WHERE ROWNUM <= ' . (int) $limit;

View File

@@ -348,7 +348,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
$value = new Dibi\DateTime($value);
}
return $value->format($this->driverName === 'odbc' ? "#m/d/Y H:i:s.u#" : "'Y-m-d H:i:s.u'");
return $value->format($this->driverName === 'odbc' ? '#m/d/Y H:i:s.u#' : "'Y-m-d H:i:s.u'");
}
@@ -455,7 +455,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
// 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) : '')
. ') WHERE "__rnum" > '. (int) $offset;
. ') WHERE "__rnum" > ' . (int) $offset;
} elseif ($limit !== null) {
$sql = 'SELECT * FROM (' . $sql . ') WHERE ROWNUM <= ' . (int) $limit;
@@ -474,8 +474,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
}
break;
}
// intentionally break omitted
// break omitted
case 'odbc':
if ($offset) {
throw new Dibi\NotSupportedException('Offset is not supported by this database.');
@@ -484,8 +483,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
$sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ') t';
break;
}
// intentionally break omitted
// break omitted
default:
throw new Dibi\NotSupportedException('PDO or driver does not support applying limit or offset.');
}

View File

@@ -78,7 +78,7 @@ class PostgreDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
}
}
set_error_handler(function($severity, $message) use (&$error) {
set_error_handler(function ($severity, $message) use (&$error) {
$error = $message;
});
if (empty($config['persistent'])) {

View File

@@ -37,10 +37,12 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
private $autoFree = true;
/** @var string Date and datetime format */
private $fmtDate, $fmtDateTime;
private $fmtDate;
private $fmtDateTime;
/** @var string character encoding */
private $dbcharset, $charset;
private $dbcharset;
private $charset;
/**

View File

@@ -105,7 +105,7 @@ class SqlsrvReflector implements Dibi\Reflector
*/
public function getIndexes($table)
{
$keyUsagesRes = $this->driver->query(sprintf("EXEC [sys].[sp_helpindex] @objname = N%s", $this->driver->escapeText($table)));
$keyUsagesRes = $this->driver->query(sprintf('EXEC [sys].[sp_helpindex] @objname = N%s', $this->driver->escapeText($table)));
$keyUsages = [];
while ($row = $keyUsagesRes->fetch(true)) {
$keyUsages[$row['index_name']] = explode(',', $row['index_keys']);

View File

@@ -38,7 +38,7 @@ class Fluent implements IDataSource
/** @var array */
public static $masks = [
'SELECT' => ['SELECT', 'DISTINCT', 'FROM', 'WHERE', 'GROUP BY',
'HAVING', 'ORDER BY', 'LIMIT', 'OFFSET'],
'HAVING', 'ORDER BY', 'LIMIT', 'OFFSET', ],
'UPDATE' => ['UPDATE', 'SET', 'WHERE', 'ORDER BY', 'LIMIT'],
'INSERT' => ['INSERT', 'INTO', 'VALUES', 'SELECT'],
'DELETE' => ['DELETE', 'FROM', 'USING', 'WHERE', 'ORDER BY', 'LIMIT'],

View File

@@ -39,7 +39,7 @@ class Helpers
echo $hasColors ? "\033[1;37m#row: $i\033[0m\n" : "#row: $i\n";
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";
}
@@ -51,14 +51,14 @@ class Helpers
if ($i === 0) {
echo "\n<table class=\"dump\">\n<thead>\n\t<tr>\n\t\t<th>#row</th>\n";
foreach ($row as $col => $foo) {
echo "\t\t<th>" . htmlSpecialChars((string) $col) . "</th>\n";
echo "\t\t<th>" . htmlspecialchars((string) $col) . "</th>\n";
}
echo "\t</tr>\n</thead>\n<tbody>\n";
}
echo "\t<tr>\n\t\t<th>", $i, "</th>\n";
foreach ($row as $col) {
echo "\t\t<td>", htmlSpecialChars((string) $col), "</td>\n";
echo "\t\t<td>", htmlspecialchars((string) $col), "</td>\n";
}
echo "\t</tr>\n";
}
@@ -107,7 +107,7 @@ class Helpers
echo trim($sql) . "\n\n";
} else {
$sql = htmlSpecialChars($sql);
$sql = htmlspecialchars($sql);
$sql = preg_replace_callback($highlighter, function ($m) {
if (!empty($m[1])) { // comment
return '<em style="color:gray">' . $m[1] . '</em>';

View File

@@ -76,7 +76,7 @@ class Column
public function getTable()
{
if (empty($this->info['table']) || !$this->reflector) {
throw new Dibi\Exception("Table is unknown or not available.");
throw new Dibi\Exception('Table is unknown or not available.');
}
return new Table($this->reflector, ['name' => $this->info['table']]);
}

View File

@@ -364,10 +364,10 @@ class Result 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
@@ -450,7 +450,7 @@ class Result implements IDataSource
}
do {
$data[ (string) $row[$key] ] = $row[$value];
$data[(string) $row[$key]] = $row[$value];
} while ($row = $this->fetch());
return $data;

View File

@@ -129,7 +129,7 @@ trait Strict
}
}
$list = & self::$extMethods[strtolower($name)];
$list = &self::$extMethods[strtolower($name)];
if ($callback === null) { // getter
$cache = &$list[''][$class];
if (isset($cache)) {

View File

@@ -340,14 +340,12 @@ final class Translator
case 'in': // deprecated
trigger_error('Modifier %in is deprecated, use %iN.', E_USER_DEPRECATED);
// intentionally break omitted
// break omitted
case 'iN': // signed int or null
if ($value == '') {
$value = null;
}
// intentionally break omitted
// break omitted
case 'i': // signed int
case 'u': // unsigned int, ignored
if ($value === null) {
@@ -360,7 +358,7 @@ final class Translator
} else {
return (string) (int) $value;
}
// break omitted
case 'f': // float
if ($value === null) {
return 'NULL';
@@ -369,7 +367,7 @@ final class Translator
} else {
return rtrim(rtrim(number_format($value + 0, 10, '.', ''), '0'), '.');
}
// break omitted
case 'd': // date
case 't': // datetime
case 'dt': // datetime
@@ -378,7 +376,7 @@ final class Translator
} else {
return $modifier === 'd' ? $this->driver->escapeDate($value) : $this->driver->escapeDateTime($value);
}
// break omitted
case 'by':
case 'n': // composed identifier name
return $this->identifiers->$value;

View File

@@ -49,12 +49,6 @@ class dibi
FIELD_DATETIME = Type::DATETIME,
FIELD_TIME = Type::TIME;
/** @var Dibi\Connection[] Connection registry storage for DibiConnection objects */
private static $registry = [];
/** @var Dibi\Connection Current connection */
private static $connection;
/** @var string Last SQL command @see dibi::query() */
public static $sql;
@@ -70,6 +64,12 @@ class dibi
/** @var string Default dibi driver */
public static $defaultDriver = 'mysqli';
/** @var Dibi\Connection[] Connection registry storage for DibiConnection objects */
private static $registry = [];
/** @var Dibi\Connection Current connection */
private static $connection;
/**
* Static class - cannot be instantiated.

View File

@@ -166,7 +166,7 @@ interface ResultDriver
/**
* 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 Exception
*/
function seek($row);