1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-16 19:14:17 +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

@@ -4,8 +4,8 @@
* @dataProvider ../databases.ini
*/
use Tester\Assert;
use Dibi\Connection;
use Tester\Assert;
require __DIR__ . '/bootstrap.php';

View File

@@ -4,8 +4,8 @@
* @dataProvider ../databases.ini
*/
use Tester\Assert;
use Dibi\Row;
use Tester\Assert;
require __DIR__ . '/bootstrap.php';
@@ -61,9 +61,9 @@ Assert::equal([
// more complex association array
function query($conn) {
return $conn->query(in_array($conn->getConfig('system'), ['odbc', 'sqlsrv']) ? '
function query($conn)
{
return $conn->query(in_array($conn->getConfig('system'), ['odbc', 'sqlsrv'], true) ? '
SELECT products.title, customers.name, orders.amount
FROM ([products]
INNER JOIN [orders] ON [products.product_id] = [orders.product_id])
@@ -170,11 +170,11 @@ Assert::equal([
Assert::equal([
new Row(['title' => 'Chair', 'name' => 'Arnold Rimmer', 'amount' => num(7.0)]),
new Row([
'title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0)]),
'title' => 'Computer', 'name' => 'Arnold Rimmer', 'amount' => num(2.0), ]),
new Row([
'title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0)]),
'title' => 'Table', 'name' => 'Dave Lister', 'amount' => num(3.0), ]),
new Row([
'title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0)]),
'title' => 'Computer', 'name' => 'Kristine Kochanski', 'amount' => num(5.0), ]),
], query($conn)->fetchAssoc('@,='));

View File

@@ -1,7 +1,7 @@
<?php
use Tester\Assert;
use Dibi\Row;
use Tester\Assert;
require __DIR__ . '/bootstrap.php';

View File

@@ -1,7 +1,7 @@
<?php
use Tester\Assert;
use Dibi\Fluent;
use Tester\Assert;
require __DIR__ . '/bootstrap.php';

View File

@@ -7,23 +7,29 @@ require __DIR__ . '/bootstrap.php';
class MockDriver extends Dibi\Drivers\SqlsrvDriver
{
function __construct()
{}
public function __construct()
{
}
function connect(array &$config)
{}
function query($sql)
public function connect(array &$config)
{
}
public function query($sql)
{
return $this;
}
function getResultColumns()
public function getResultColumns()
{
return [];
}
function fetch($assoc)
public function fetch($assoc)
{
return false;
}

View File

@@ -4,8 +4,8 @@
* @dataProvider ../databases.ini
*/
use Tester\Assert;
use Dibi\Row;
use Tester\Assert;
require __DIR__ . '/bootstrap.php';
@@ -28,7 +28,7 @@ Assert::equal([
// more complex association array
if (!in_array($config['system'], ['odbc', 'sqlsrv'])) {
if (!in_array($config['system'], ['odbc', 'sqlsrv'], true)) {
$res = $conn->select(['products.title' => 'title', 'customers.name' => 'name'])->select('orders.amount')->as('amount')
->from('products')
->innerJoin('orders')->using('(product_id)')

View File

@@ -25,7 +25,7 @@ Assert::same(
);
if (!in_array($config['driver'], ['sqlite3', 'pdo', 'sqlsrv'])) {
if (!in_array($config['driver'], ['sqlite3', 'pdo', 'sqlsrv'], true)) {
Assert::same(
['products.product_id', 'orders.order_id', 'customers.name', 'xXx'],
$info->getColumnNames(true)
@@ -36,18 +36,18 @@ if (!in_array($config['driver'], ['sqlite3', 'pdo', 'sqlsrv'])) {
$columns = $info->getColumns();
Assert::same('product_id', $columns[0]->getName());
if (!in_array($config['driver'], ['sqlite3', 'pdo', 'sqlsrv'])) {
if (!in_array($config['driver'], ['sqlite3', 'pdo', 'sqlsrv'], true)) {
Assert::same('products', $columns[0]->getTableName());
}
Assert::null($columns[0]->getVendorInfo('xxx'));
if (!in_array($config['system'], ['sqlite', 'sqlsrv'])) {
if (!in_array($config['system'], ['sqlite', 'sqlsrv'], true)) {
Assert::same('i', $columns[0]->getType());
}
Assert::null($columns[0]->isNullable());
Assert::same('xXx', $columns[3]->getName());
Assert::null($columns[3]->getTableName());
if (!in_array($config['system'], ['sqlite', 'sqlsrv'])) {
if (!in_array($config['system'], ['sqlite', 'sqlsrv'], true)) {
Assert::same('i', $columns[0]->getType());
}
Assert::null($columns[3]->isNullable());

View File

@@ -1,17 +1,19 @@
<?php
use Tester\Assert;
use Dibi\Type;
use Tester\Assert;
require __DIR__ . '/bootstrap.php';
class MockResult extends Dibi\Result
{
function __construct()
{}
public function __construct()
{
}
function test($row)
public function test($row)
{
$normalize = new ReflectionMethod('Dibi\Result', 'normalize');
$normalize->setAccessible(true);

View File

@@ -9,7 +9,7 @@ use Tester\Assert;
require __DIR__ . '/bootstrap.php';
$conn = new Dibi\Connection($config);
$conn->loadFile(__DIR__ . "/data/sqlsrv.insert.sql");
$conn->loadFile(__DIR__ . '/data/sqlsrv.insert.sql');
for ($i = 1; $i <= 5; $i++) {
$conn->query('INSERT INTO %n DEFAULT VALUES', 'aaa');

View File

@@ -11,27 +11,37 @@ class TestClass
public $public;
protected $protected;
public static $publicStatic;
protected $protected;
public function publicMethod()
{}
{
}
public static function publicMethodStatic()
{}
{
}
protected function protectedMethod()
{}
{
}
protected static function protectedMethodS()
{}
{
}
public function getBar()
{
return 123;
}
public function isFoo()
{
return 456;

View File

@@ -4,8 +4,8 @@
* @dataProvider ../databases.ini
*/
use Tester\Assert;
use Dibi\DateTime;
use Tester\Assert;
require __DIR__ . '/bootstrap.php';
@@ -95,7 +95,7 @@ Assert::same(
$conn->translate('TEST %and', ['[cond] > 2', '[cond2] = "3"', 'cond3 < RAND()'])
);
//
$where = [];
$where[] = '[age] > 20';
$where[] = '[email] IS NOT NULL';
@@ -156,7 +156,7 @@ if ($config['system'] === 'odbc') {
Assert::same(
reformat([
'sqlsrv' => 'SELECT * FROM [products] OFFSET 1 ROWS FETCH NEXT 2 ROWS ONLY',
'SELECT * FROM [products] LIMIT 2 OFFSET 1'
'SELECT * FROM [products] LIMIT 2 OFFSET 1',
]),
$conn->translate('SELECT * FROM [products] %lmt %ofs', 2, 1)
);
@@ -549,7 +549,7 @@ Assert::same(
);
setLocale(LC_ALL, 'czech');
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"),

View File

@@ -63,7 +63,7 @@ function reformat($s)
return strtr($s, '[]', '``');
} elseif ($config['system'] === 'postgre') {
return strtr($s, '[]', '""');
} elseif (in_array($config['system'], ['odbc', 'sqlite', 'sqlsrv'])) {
} elseif (in_array($config['system'], ['odbc', 'sqlite', 'sqlsrv'], true)) {
return $s;
} else {
trigger_error("Unsupported driver $config[system]", E_USER_WARNING);

View File

@@ -15,7 +15,7 @@ $conn->loadFile(__DIR__ . "/data/$config[system].sql");
$e = Assert::exception(function () use ($conn) {
$conn->query('SELECT');
}, 'Dibi\DriverException', "%a% error in your SQL syntax;%a%", 1064);
}, 'Dibi\DriverException', '%a% error in your SQL syntax;%a%', 1064);
Assert::same('SELECT', $e->getSql());