diff --git a/examples/using-profiler.php b/examples/using-profiler.php
index 11f1095..2aa6b58 100644
--- a/examples/using-profiler.php
+++ b/examples/using-profiler.php
@@ -25,13 +25,13 @@ for ($i = 0; $i < 20; $i++) {
// display output
?>
-
' . number_format($event->time * 1000, 3, '.', ' ');
diff --git a/src/Dibi/Connection.php b/src/Dibi/Connection.php
index 5d50641..c56cb94 100644
--- a/src/Dibi/Connection.php
+++ b/src/Dibi/Connection.php
@@ -82,7 +82,7 @@ class Connection
if ($config['driver'] instanceof Driver) {
$this->driver = $config['driver'];
$config['driver'] = get_class($this->driver);
- } elseif (is_subclass_of($config['driver'], 'Dibi\Driver')) {
+ } elseif (is_subclass_of($config['driver'], Driver::class)) {
$this->driver = new $config['driver'];
} else {
$class = preg_replace(['#\W#', '#sql#'], ['_', 'Sql'], ucfirst(strtolower($config['driver'])));
@@ -102,7 +102,7 @@ class Connection
$profilerCfg = ['run' => (bool) $profilerCfg];
}
if (!empty($profilerCfg['run'])) {
- $filter = isset($profilerCfg['filter']) ? $profilerCfg['filter'] : Event::QUERY;
+ $filter = $profilerCfg['filter'] ?? Event::QUERY;
if (isset($profilerCfg['file'])) {
$this->onEvent[] = [new Loggers\FileLogger($profilerCfg['file'], $filter), 'logEvent'];
@@ -186,15 +186,9 @@ class Connection
*/
final public function getConfig($key = NULL, $default = NULL)
{
- if ($key === NULL) {
- return $this->config;
-
- } elseif (isset($this->config[$key])) {
- return $this->config[$key];
-
- } else {
- return $default;
- }
+ return $key === NULL
+ ? $this->config
+ : ($this->config[$key] ?? $default);
}
@@ -622,7 +616,7 @@ class Connection
public function getDatabaseInfo()
{
$this->connected || $this->connect();
- return new Reflection\Database($this->driver->getReflector(), isset($this->config['database']) ? $this->config['database'] : NULL);
+ return new Reflection\Database($this->driver->getReflector(), $this->config['database'] ?? NULL);
}
@@ -647,7 +641,7 @@ class Connection
protected function onEvent($arg)
{
foreach ($this->onEvent ?: [] as $handler) {
- call_user_func($handler, $arg);
+ $handler($arg);
}
}
diff --git a/src/Dibi/Drivers/MySqliDriver.php b/src/Dibi/Drivers/MySqliDriver.php
index 5b96c2a..66f4b16 100644
--- a/src/Dibi/Drivers/MySqliDriver.php
+++ b/src/Dibi/Drivers/MySqliDriver.php
@@ -476,7 +476,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
if ($types === NULL) {
$consts = get_defined_constants(TRUE);
$types = [];
- foreach (isset($consts['mysqli']) ? $consts['mysqli'] : [] as $key => $value) {
+ foreach ($consts['mysqli'] ?? [] as $key => $value) {
if (strncmp($key, 'MYSQLI_TYPE_', 12) === 0) {
$types[$value] = substr($key, 12);
}
@@ -492,7 +492,7 @@ class MySqliDriver implements Dibi\Driver, Dibi\ResultDriver
'name' => $row['name'],
'table' => $row['orgtable'],
'fullname' => $row['table'] ? $row['table'] . '.' . $row['name'] : $row['name'],
- 'nativetype' => isset($types[$row['type']]) ? $types[$row['type']] : $row['type'],
+ 'nativetype' => $types[$row['type']] ?? $row['type'],
'type' => $row['type'] === MYSQLI_TYPE_TIME ? Dibi\Type::TIME_INTERVAL : NULL,
'vendor' => $row,
];
diff --git a/src/Dibi/Drivers/OracleDriver.php b/src/Dibi/Drivers/OracleDriver.php
index ba10728..0f6187f 100644
--- a/src/Dibi/Drivers/OracleDriver.php
+++ b/src/Dibi/Drivers/OracleDriver.php
@@ -68,8 +68,8 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
$foo = &$config['charset'];
if (empty($config['nativeDate'])) {
- $this->fmtDate = isset($config['formatDate']) ? $config['formatDate'] : 'U';
- $this->fmtDateTime = isset($config['formatDateTime']) ? $config['formatDateTime'] : 'U';
+ $this->fmtDate = $config['formatDate'] ?? 'U';
+ $this->fmtDateTime = $config['formatDateTime'] ?? 'U';
}
if (isset($config['resource'])) {
@@ -495,7 +495,7 @@ class OracleDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
'table' => $row['TABLE_NAME'],
'name' => $row['COLUMN_NAME'],
'nativetype' => $row['DATA_TYPE'],
- 'size' => isset($row['DATA_LENGTH']) ? $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 7ddf29b..ae277f6 100644
--- a/src/Dibi/Drivers/PdoDriver.php
+++ b/src/Dibi/Drivers/PdoDriver.php
@@ -80,9 +80,8 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
}
$this->driverName = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME);
- $this->serverVersion = isset($config['version'])
- ? $config['version']
- : @$this->connection->getAttribute(PDO::ATTR_SERVER_VERSION); // @ - may be not supported
+ $this->serverVersion = $config['version']
+ ?? @$this->connection->getAttribute(PDO::ATTR_SERVER_VERSION); // @ - may be not supported
}
@@ -121,7 +120,7 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
}
}
- list($sqlState, $code, $message) = $this->connection->errorInfo();
+ [$sqlState, $code, $message] = $this->connection->errorInfo();
$message = "SQLSTATE[$sqlState]: $message";
switch ($this->driverName) {
case 'mysql':
diff --git a/src/Dibi/Drivers/Sqlite3Driver.php b/src/Dibi/Drivers/Sqlite3Driver.php
index 6fae30e..6956116 100644
--- a/src/Dibi/Drivers/Sqlite3Driver.php
+++ b/src/Dibi/Drivers/Sqlite3Driver.php
@@ -62,8 +62,8 @@ class Sqlite3Driver implements Dibi\Driver, Dibi\ResultDriver
public function connect(array &$config)
{
Dibi\Helpers::alias($config, 'database', 'file');
- $this->fmtDate = isset($config['formatDate']) ? $config['formatDate'] : 'U';
- $this->fmtDateTime = isset($config['formatDateTime']) ? $config['formatDateTime'] : 'U';
+ $this->fmtDate = $config['formatDate'] ?? 'U';
+ $this->fmtDateTime = $config['formatDateTime'] ?? 'U';
if (isset($config['resource']) && $config['resource'] instanceof SQLite3) {
$this->connection = $config['resource'];
diff --git a/src/Dibi/Drivers/SqlsrvDriver.php b/src/Dibi/Drivers/SqlsrvDriver.php
index b6e39a9..fd0ec49 100644
--- a/src/Dibi/Drivers/SqlsrvDriver.php
+++ b/src/Dibi/Drivers/SqlsrvDriver.php
@@ -75,9 +75,7 @@ class SqlsrvDriver implements Dibi\Driver, Dibi\ResultDriver
$options = $config['options'];
// Default values
- if (!isset($options['CharacterSet'])) {
- $options['CharacterSet'] = 'UTF-8';
- }
+ $options['CharacterSet'] = $options['CharacterSet'] ?? 'UTF-8';
$options['PWD'] = (string) $options['PWD'];
$options['UID'] = (string) $options['UID'];
$options['Database'] = (string) $options['Database'];
diff --git a/src/Dibi/Drivers/SqlsrvReflector.php b/src/Dibi/Drivers/SqlsrvReflector.php
index 37bb6ba..6eba7f2 100644
--- a/src/Dibi/Drivers/SqlsrvReflector.php
+++ b/src/Dibi/Drivers/SqlsrvReflector.php
@@ -117,7 +117,7 @@ class SqlsrvReflector implements Dibi\Reflector
$indexes[$row['name']]['name'] = $row['name'];
$indexes[$row['name']]['unique'] = $row['is_unique'] === 1;
$indexes[$row['name']]['primary'] = $row['is_primary_key'] === 1;
- $indexes[$row['name']]['columns'] = isset($keyUsages[$row['name']]) ? $keyUsages[$row['name']] : [];
+ $indexes[$row['name']]['columns'] = $keyUsages[$row['name']] ?? [];
}
return array_values($indexes);
}
diff --git a/src/Dibi/Fluent.php b/src/Dibi/Fluent.php
index 8e064a1..a3f9665 100644
--- a/src/Dibi/Fluent.php
+++ b/src/Dibi/Fluent.php
@@ -421,7 +421,8 @@ class Fluent implements IDataSource
{
$res = $this->connection->query($args);
foreach ($this->setups as $setup) {
- call_user_func_array([$res, array_shift($setup)], $setup);
+ $method = array_shift($setup);
+ $res->$method(...$setup);
}
return $res;
}
diff --git a/src/Dibi/HashMap.php b/src/Dibi/HashMap.php
index e33bc5c..c803e52 100644
--- a/src/Dibi/HashMap.php
+++ b/src/Dibi/HashMap.php
@@ -58,9 +58,9 @@ final class HashMap extends HashMapBase
{
if ($nm == '') {
$nm = "\xFF";
- return isset($this->$nm) ? $this->$nm : $this->$nm = call_user_func($this->getCallback(), '');
+ return $this->$nm = $this->$nm ?? $this->getCallback()('');
} else {
- return $this->$nm = call_user_func($this->getCallback(), $nm);
+ return $this->$nm = $this->getCallback()($nm);
}
}
diff --git a/src/Dibi/Helpers.php b/src/Dibi/Helpers.php
index 267e6c8..caa1027 100644
--- a/src/Dibi/Helpers.php
+++ b/src/Dibi/Helpers.php
@@ -263,7 +263,7 @@ class Helpers
$sql = '';
$count++;
if ($onProgress) {
- call_user_func($onProgress, $count, isset($stat['size']) ? $size * 100 / $stat['size'] : NULL);
+ $onProgress($count, isset($stat['size']) ? $size * 100 / $stat['size'] : NULL);
}
} else {
@@ -275,7 +275,7 @@ class Helpers
$driver->query($sql);
$count++;
if ($onProgress) {
- call_user_func($onProgress, $count, isset($stat['size']) ? 100 : NULL);
+ $onProgress($count, isset($stat['size']) ? 100 : NULL);
}
}
fclose($handle);
diff --git a/src/Dibi/Reflection/Column.php b/src/Dibi/Reflection/Column.php
index 7f6593d..bd31e20 100644
--- a/src/Dibi/Reflection/Column.php
+++ b/src/Dibi/Reflection/Column.php
@@ -57,7 +57,7 @@ class Column
*/
public function getFullName()
{
- return isset($this->info['fullname']) ? $this->info['fullname'] : NULL;
+ return $this->info['fullname'] ?? NULL;
}
@@ -150,7 +150,7 @@ class Column
*/
public function getDefault()
{
- return isset($this->info['default']) ? $this->info['default'] : NULL;
+ return $this->info['default'] ?? NULL;
}
@@ -160,7 +160,7 @@ class Column
*/
public function getVendorInfo($key)
{
- return isset($this->info['vendor'][$key]) ? $this->info['vendor'][$key] : NULL;
+ return $this->info['vendor'][$key] ?? NULL;
}
}
diff --git a/src/Dibi/Result.php b/src/Dibi/Result.php
index a37cc71..4860693 100644
--- a/src/Dibi/Result.php
+++ b/src/Dibi/Result.php
@@ -43,7 +43,7 @@ class Result implements IDataSource
private $fetched = FALSE;
/** @var string returned object class */
- private $rowClass = 'Dibi\Row';
+ private $rowClass = Row::class;
/** @var callable returned object factory*/
private $rowFactory;
@@ -185,7 +185,7 @@ class Result implements IDataSource
$this->fetched = TRUE;
$this->normalize($row);
if ($this->rowFactory) {
- return call_user_func($this->rowFactory, $row);
+ return ($this->rowFactory)($row);
} elseif ($this->rowClass) {
$row = new $this->rowClass($row);
}
@@ -461,7 +461,7 @@ class Result implements IDataSource
$cache = Helpers::getTypeCache();
try {
foreach ($this->getResultDriver()->getResultColumns() as $col) {
- $this->types[$col['name']] = isset($col['type']) ? $col['type'] : $cache->{$col['nativetype']};
+ $this->types[$col['name']] = $col['type'] ?? $cache->{$col['nativetype']};
}
} catch (NotSupportedException $e) {
}
@@ -543,7 +543,7 @@ class Result implements IDataSource
*/
final public function getType($col)
{
- return isset($this->types[$col]) ? $this->types[$col] : NULL;
+ return $this->types[$col] ?? NULL;
}
@@ -566,7 +566,7 @@ class Result implements IDataSource
*/
final public function getFormat($type)
{
- return isset($this->formats[$type]) ? $this->formats[$type] : NULL;
+ return $this->formats[$type] ?? NULL;
}
diff --git a/src/Dibi/Strict.php b/src/Dibi/Strict.php
index 8e4b7bd..0493ef2 100644
--- a/src/Dibi/Strict.php
+++ b/src/Dibi/Strict.php
@@ -29,7 +29,7 @@ trait Strict
{
if ($cb = self::extensionMethod(get_class($this) . '::' . $name)) { // back compatiblity
array_unshift($args, $this);
- return call_user_func_array($cb, $args);
+ return $cb(...$args);
}
$class = method_exists($this, $name) ? 'parent' : get_class($this);
$items = (new ReflectionClass($this))->getMethods(ReflectionMethod::IS_PUBLIC);
@@ -113,7 +113,7 @@ trait Strict
if (strpos($name, '::') === FALSE) {
$class = get_called_class();
} else {
- list($class, $name) = explode('::', $name);
+ [$class, $name] = explode('::', $name);
$class = (new ReflectionClass($class))->getName();
}
diff --git a/src/Dibi/Translator.php b/src/Dibi/Translator.php
index 9e0ab10..e9b810a 100644
--- a/src/Dibi/Translator.php
+++ b/src/Dibi/Translator.php
@@ -238,7 +238,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, isset($pair[1]) ? $pair[1] : (is_array($v) ? 'ex' : FALSE));
+ . $this->formatValue($v, $pair[1] ?? (is_array($v) ? 'ex' : FALSE));
}
return implode(', ', $vx);
@@ -247,7 +247,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, isset($pair[1]) ? $pair[1] : (is_array($v) ? 'ex' : FALSE));
+ $vx[] = $this->formatValue($v, $pair[1] ?? (is_array($v) ? 'ex' : FALSE));
}
return '(' . (($vx || $modifier === 'l') ? implode(', ', $vx) : 'NULL') . ')';
@@ -256,7 +256,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, isset($pair[1]) ? $pair[1] : (is_array($v) ? 'ex' : FALSE));
+ $vx[] = $this->formatValue($v, $pair[1] ?? (is_array($v) ? 'ex' : FALSE));
}
return '(' . implode(', ', $kx) . ') VALUES (' . implode(', ', $vx) . ')';
@@ -277,7 +277,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, isset($pair[1]) ? $pair[1] : (is_array($v2) ? 'ex' : FALSE));
+ $vx[$k2][] = $this->formatValue($v2, $pair[1] ?? (is_array($v2) ? 'ex' : FALSE));
}
}
foreach ($vx as $k => $v) {
@@ -300,7 +300,7 @@ final class Translator
case 'ex':
case 'sql':
- return call_user_func_array([$this->connection, 'translate'], $value);
+ return $this->connection->translate(...$value);
default: // value, value, value - all with the same modifier
foreach ($value as $v) {
diff --git a/src/Dibi/exceptions.php b/src/Dibi/exceptions.php
index 4a8f7fb..d91ed30 100644
--- a/src/Dibi/exceptions.php
+++ b/src/Dibi/exceptions.php
@@ -75,7 +75,7 @@ class PcreException extends Exception
5 => 'Offset didn\'t correspond to the begin of a valid UTF-8 code point', // PREG_BAD_UTF8_OFFSET_ERROR
];
$code = preg_last_error();
- parent::__construct(str_replace('%msg', isset($messages[$code]) ? $messages[$code] : 'Unknown error', $message), $code);
+ parent::__construct(str_replace('%msg', $messages[$code] ?? 'Unknown error', $message), $code);
}
}
diff --git a/tests/dibi/Connection.connect.phpt b/tests/dibi/Connection.connect.phpt
index cf872ca..ed31db9 100644
--- a/tests/dibi/Connection.connect.phpt
+++ b/tests/dibi/Connection.connect.phpt
@@ -34,7 +34,7 @@ test(function () use ($config) { // query string
Assert::null($conn->getConfig('lazy'));
Assert::same($config['driver'], $conn->getConfig('driver'));
- Assert::type('Dibi\Driver', $conn->getDriver());
+ Assert::type(Dibi\Driver::class, $conn->getDriver());
});
diff --git a/tests/dibi/Connection.transactions.phpt b/tests/dibi/Connection.transactions.phpt
index b7d13bc..6eae5c3 100644
--- a/tests/dibi/Connection.transactions.phpt
+++ b/tests/dibi/Connection.transactions.phpt
@@ -15,16 +15,16 @@ $conn->loadFile(__DIR__ . "/data/$config[system].sql");
/*Assert::exception(function () use ($conn) {
$conn->rollback();
-}, 'Dibi\Exception');
+}, Dibi\Exception::class);
Assert::exception(function () use ($conn) {
$conn->commit();
-}, 'Dibi\Exception');
+}, Dibi\Exception::class);
$conn->begin();
Assert::exception(function () use ($conn) {
$conn->begin();
-}, 'Dibi\Exception');
+}, Dibi\Exception::class);
*/
diff --git a/tests/dibi/Result.normalize.phpt b/tests/dibi/Result.normalize.phpt
index cdcc51b..73e1775 100644
--- a/tests/dibi/Result.normalize.phpt
+++ b/tests/dibi/Result.normalize.phpt
@@ -13,7 +13,7 @@ class MockResult extends Dibi\Result
function test($row)
{
- $normalize = new ReflectionMethod('Dibi\Result', 'normalize');
+ $normalize = new ReflectionMethod(Dibi\Result::class, 'normalize');
$normalize->setAccessible(TRUE);
$normalize->invokeArgs($this, [&$row]);
return $row;
@@ -164,7 +164,7 @@ test(function () {
Assert::same(['col' => NULL], $result->test(['col' => NULL]));
Assert::exception(function () use ($result) {
$result->test(['col' => TRUE]);
- }, 'Exception');
+ }, Exception::class);
Assert::same(['col' => NULL], $result->test(['col' => FALSE]));
Assert::same(['col' => NULL], $result->test(['col' => '']));
@@ -183,7 +183,7 @@ test(function () {
Assert::same(['col' => NULL], $result->test(['col' => NULL]));
Assert::exception(function () use ($result) {
$result->test(['col' => TRUE]);
- }, 'Exception');
+ }, Exception::class);
Assert::same(['col' => NULL], $result->test(['col' => FALSE]));
Assert::same(['col' => NULL], $result->test(['col' => '']));
@@ -201,7 +201,7 @@ test(function () {
Assert::same(['col' => NULL], $result->test(['col' => NULL]));
Assert::exception(function () use ($result) {
$result->test(['col' => TRUE]);
- }, 'Exception');
+ }, Exception::class);
Assert::same(['col' => NULL], $result->test(['col' => FALSE]));
Assert::same(['col' => NULL], $result->test(['col' => '']));
@@ -217,7 +217,7 @@ test(function () {
Assert::same(['col' => NULL], $result->test(['col' => NULL]));
Assert::exception(function () use ($result) {
$result->test(['col' => TRUE]);
- }, 'Exception');
+ }, Exception::class);
Assert::same(['col' => NULL], $result->test(['col' => FALSE]));
Assert::same(['col' => NULL], $result->test(['col' => '']));
diff --git a/tests/dibi/Sqlsrv.limits.phpt b/tests/dibi/Sqlsrv.limits.phpt
index cda91dd..38d9cdc 100644
--- a/tests/dibi/Sqlsrv.limits.phpt
+++ b/tests/dibi/Sqlsrv.limits.phpt
@@ -39,7 +39,7 @@ $tests = function ($conn) {
function () use ($conn) {
$conn->translate('SELECT 1 %ofs', -10);
},
- 'Dibi\NotSupportedException',
+ Dibi\NotSupportedException::class,
'Negative offset or limit.'
);
@@ -48,7 +48,7 @@ $tests = function ($conn) {
function () use ($conn) {
$conn->translate('SELECT 1 %lmt', -10);
},
- 'Dibi\NotSupportedException',
+ Dibi\NotSupportedException::class,
'Negative offset or limit.'
);
@@ -57,7 +57,7 @@ $tests = function ($conn) {
function () use ($conn) {
$conn->translate('SELECT 1 %ofs %lmt', 10, -10);
},
- 'Dibi\NotSupportedException',
+ Dibi\NotSupportedException::class,
'Negative offset or limit.'
);
@@ -66,7 +66,7 @@ $tests = function ($conn) {
function () use ($conn) {
$conn->translate('SELECT 1 %ofs %lmt', -10, 10);
},
- 'Dibi\NotSupportedException',
+ Dibi\NotSupportedException::class,
'Negative offset or limit.'
);
} else {
@@ -82,7 +82,7 @@ $tests = function ($conn) {
Assert::exception(
$conn->translate('SELECT 1 %ofs %lmt', 10, 10),
- 'DibiNotSupportedException'
+ Dibi\NotSupportedException::class
);
}
};
diff --git a/tests/dibi/Strict.phpt b/tests/dibi/Strict.phpt
index 4f17ab5..6908444 100644
--- a/tests/dibi/Strict.phpt
+++ b/tests/dibi/Strict.phpt
@@ -51,53 +51,53 @@ class TestChild extends TestClass
Assert::exception(function () {
$obj = new TestClass;
$obj->undeclared();
-}, 'LogicException', 'Call to undefined method TestClass::undeclared().');
+}, LogicException::class, 'Call to undefined method TestClass::undeclared().');
Assert::exception(function () {
TestClass::undeclared();
-}, 'LogicException', 'Call to undefined static method TestClass::undeclared().');
+}, LogicException::class, 'Call to undefined static method TestClass::undeclared().');
Assert::exception(function () {
$obj = new TestChild;
$obj->callParent();
-}, 'LogicException', 'Call to undefined method parent::callParent().');
+}, LogicException::class, 'Call to undefined method parent::callParent().');
Assert::exception(function () {
$obj = new TestClass;
$obj->publicMethodX();
-}, 'LogicException', 'Call to undefined method TestClass::publicMethodX(), did you mean publicMethod()?');
+}, LogicException::class, 'Call to undefined method TestClass::publicMethodX(), did you mean publicMethod()?');
Assert::exception(function () { // suggest static method
$obj = new TestClass;
$obj->publicMethodStaticX();
-}, 'LogicException', 'Call to undefined method TestClass::publicMethodStaticX(), did you mean publicMethodStatic()?');
+}, LogicException::class, 'Call to undefined method TestClass::publicMethodStaticX(), did you mean publicMethodStatic()?');
Assert::exception(function () { // suggest only public method
$obj = new TestClass;
$obj->protectedMethodX();
-}, 'LogicException', 'Call to undefined method TestClass::protectedMethodX().');
+}, LogicException::class, 'Call to undefined method TestClass::protectedMethodX().');
// writing
Assert::exception(function () {
$obj = new TestClass;
$obj->undeclared = 'value';
-}, 'LogicException', 'Attempt to write to undeclared property TestClass::$undeclared.');
+}, LogicException::class, 'Attempt to write to undeclared property TestClass::$undeclared.');
Assert::exception(function () {
$obj = new TestClass;
$obj->publicX = 'value';
-}, 'LogicException', 'Attempt to write to undeclared property TestClass::$publicX, did you mean $public?');
+}, LogicException::class, 'Attempt to write to undeclared property TestClass::$publicX, did you mean $public?');
Assert::exception(function () { // suggest only non-static property
$obj = new TestClass;
$obj->publicStaticX = 'value';
-}, 'LogicException', 'Attempt to write to undeclared property TestClass::$publicStaticX.');
+}, LogicException::class, 'Attempt to write to undeclared property TestClass::$publicStaticX.');
Assert::exception(function () { // suggest only public property
$obj = new TestClass;
$obj->protectedX = 'value';
-}, 'LogicException', 'Attempt to write to undeclared property TestClass::$protectedX.');
+}, LogicException::class, 'Attempt to write to undeclared property TestClass::$protectedX.');
// property getter
@@ -112,29 +112,29 @@ Assert::same(456, $obj->foo);
Assert::exception(function () {
$obj = new TestClass;
$val = $obj->undeclared;
-}, 'LogicException', 'Attempt to read undeclared property TestClass::$undeclared.');
+}, LogicException::class, 'Attempt to read undeclared property TestClass::$undeclared.');
Assert::exception(function () {
$obj = new TestClass;
$val = $obj->publicX;
-}, 'LogicException', 'Attempt to read undeclared property TestClass::$publicX, did you mean $public?');
+}, LogicException::class, 'Attempt to read undeclared property TestClass::$publicX, did you mean $public?');
Assert::exception(function () { // suggest only non-static property
$obj = new TestClass;
$val = $obj->publicStaticX;
-}, 'LogicException', 'Attempt to read undeclared property TestClass::$publicStaticX.');
+}, LogicException::class, 'Attempt to read undeclared property TestClass::$publicStaticX.');
Assert::exception(function () { // suggest only public property
$obj = new TestClass;
$val = $obj->protectedX;
-}, 'LogicException', 'Attempt to read undeclared property TestClass::$protectedX.');
+}, LogicException::class, 'Attempt to read undeclared property TestClass::$protectedX.');
// unset/isset
Assert::exception(function () {
$obj = new TestClass;
unset($obj->undeclared);
-}, 'LogicException', 'Attempt to unset undeclared property TestClass::$undeclared.');
+}, LogicException::class, 'Attempt to unset undeclared property TestClass::$undeclared.');
Assert::false(isset($obj->undeclared));
diff --git a/tests/dibi/Translator.phpt b/tests/dibi/Translator.phpt
index 9c970cb..d9e5918 100644
--- a/tests/dibi/Translator.phpt
+++ b/tests/dibi/Translator.phpt
@@ -77,7 +77,7 @@ Assert::same(
// invalid input
$e = Assert::exception(function () use ($conn) {
$conn->translate('SELECT %s', (object) [123], ', %m', 123);
-}, 'Dibi\Exception', 'SQL translate error: Invalid combination of type stdClass and modifier %s');
+}, Dibi\Exception::class, 'SQL translate error: Invalid combination of type stdClass and modifier %s');
Assert::same('SELECT **Invalid combination of type stdClass and modifier %s** , **Unknown or unexpected modifier %m**', $e->getSql());
Assert::same(
@@ -150,7 +150,7 @@ Assert::same(
if ($config['system'] === 'odbc') {
Assert::exception(function () use ($conn) {
$conn->translate('SELECT * FROM [products] %lmt %ofs', 2, 1);
- }, 'Dibi\Exception');
+ }, Dibi\Exception::class);
} else {
// with limit = 2, offset = 1
Assert::same(
@@ -198,7 +198,7 @@ Assert::same(
Assert::exception(function () use ($conn) {
$conn->translate('SELECT %s', new DateTime('1212-09-26'));
-}, 'Dibi\Exception', 'SQL translate error: Invalid combination of type Dibi\DateTime and modifier %s');
+}, Dibi\Exception::class, 'SQL translate error: Invalid combination of type Dibi\DateTime and modifier %s');
@@ -240,7 +240,7 @@ if ($config['system'] === 'postgre') {
$e = Assert::exception(function () use ($conn) {
$conn->translate("SELECT '");
-}, 'Dibi\Exception', 'SQL translate error: Alone quote');
+}, Dibi\Exception::class, 'SQL translate error: Alone quote');
Assert::same('SELECT **Alone quote**', $e->getSql());
Assert::match(
@@ -491,7 +491,7 @@ $e = Assert::exception(function () use ($conn) {
'num%i' => ['1', ''],
];
$conn->translate('INSERT INTO test %m', $array6);
-}, 'Dibi\Exception', 'SQL translate error: Multi-insert array "num%i" is different');
+}, Dibi\Exception::class, 'SQL translate error: Multi-insert array "num%i" is different');
Assert::same('INSERT INTO test **Multi-insert array "num%i" is different**', $e->getSql());
$array6 = [
diff --git a/tests/dibi/exceptions.mysql.phpt b/tests/dibi/exceptions.mysql.phpt
index 4f20c51..97d8147 100644
--- a/tests/dibi/exceptions.mysql.phpt
+++ b/tests/dibi/exceptions.mysql.phpt
@@ -15,27 +15,27 @@ $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::class, "%a% error in your SQL syntax;%a%", 1064);
Assert::same('SELECT', $e->getSql());
$e = Assert::exception(function () use ($conn) {
$conn->query('INSERT INTO products (product_id, title) VALUES (1, "New")');
-}, 'Dibi\UniqueConstraintViolationException', "%a?%Duplicate entry '1' for key 'PRIMARY'", 1062);
+}, Dibi\UniqueConstraintViolationException::class, "%a?%Duplicate entry '1' for key 'PRIMARY'", 1062);
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', "%a?%Column 'title' cannot be null", 1048);
+}, Dibi\NotNullConstraintViolationException::class, "%a?%Column 'title' cannot be null", 1048);
Assert::same('INSERT INTO products (title) VALUES (NULL)', $e->getSql());
$e = Assert::exception(function () use ($conn) {
$conn->query('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)');
-}, 'Dibi\ForeignKeyConstraintViolationException', '%a% a foreign key constraint fails %a%', 1452);
+}, Dibi\ForeignKeyConstraintViolationException::class, '%a% a foreign key constraint fails %a%', 1452);
Assert::same('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)', $e->getSql());
diff --git a/tests/dibi/exceptions.postgre.phpt b/tests/dibi/exceptions.postgre.phpt
index de38df9..dc1f4b1 100644
--- a/tests/dibi/exceptions.postgre.phpt
+++ b/tests/dibi/exceptions.postgre.phpt
@@ -15,27 +15,27 @@ $conn->loadFile(__DIR__ . "/data/$config[system].sql");
$e = Assert::exception(function () use ($conn) {
$conn->query('SELECT INTO');
-}, 'Dibi\DriverException', '%a?%syntax error %A%');
+}, Dibi\DriverException::class, '%a?%syntax error %A%');
Assert::same('SELECT INTO', $e->getSql());
$e = Assert::exception(function () use ($conn) {
$conn->query('INSERT INTO products (product_id, title) VALUES (1, "New")');
-}, 'Dibi\UniqueConstraintViolationException', '%a% violates unique constraint %A%', '23505');
+}, Dibi\UniqueConstraintViolationException::class, '%a% violates unique constraint %A%', '23505');
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', '%a?%null value in column "title" violates not-null constraint%A?%', '23502');
+}, Dibi\NotNullConstraintViolationException::class, '%a?%null value in column "title" violates not-null constraint%A?%', '23502');
Assert::same('INSERT INTO products (title) VALUES (NULL)', $e->getSql());
$e = Assert::exception(function () use ($conn) {
$conn->query('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)');
-}, 'Dibi\ForeignKeyConstraintViolationException', '%a% violates foreign key constraint %A%', '23503');
+}, Dibi\ForeignKeyConstraintViolationException::class, '%a% violates foreign key constraint %A%', '23503');
Assert::same('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)', $e->getSql());
diff --git a/tests/dibi/exceptions.sqlite.phpt b/tests/dibi/exceptions.sqlite.phpt
index e0fc3d5..3e19231 100644
--- a/tests/dibi/exceptions.sqlite.phpt
+++ b/tests/dibi/exceptions.sqlite.phpt
@@ -15,21 +15,21 @@ $conn->loadFile(__DIR__ . "/data/$config[system].sql");
$e = Assert::exception(function () use ($conn) {
$conn->query('SELECT');
-}, 'Dibi\DriverException', '%a% syntax error', 1);
+}, Dibi\DriverException::class, '%a% syntax error', 1);
Assert::same('SELECT', $e->getSql());
$e = Assert::exception(function () use ($conn) {
$conn->query('INSERT INTO products (product_id, title) VALUES (1, "New")');
-}, 'Dibi\UniqueConstraintViolationException', 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', NULL, 19);
+}, Dibi\NotNullConstraintViolationException::class, NULL, 19);
Assert::same('INSERT INTO products (title) VALUES (NULL)', $e->getSql());
@@ -37,6 +37,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', NULL, 19);
+}, Dibi\ForeignKeyConstraintViolationException::class, NULL, 19);
Assert::same('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)', $e->getSql());
|