1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-06 14:16:39 +02:00

removed Dibi\Strict

This commit is contained in:
David Grudl
2023-08-09 16:11:51 +02:00
parent 8915b0343c
commit b01d97ac86
47 changed files with 0 additions and 355 deletions

View File

@@ -20,8 +20,6 @@ use Tracy;
*/
class Panel implements Tracy\IBarPanel
{
use Dibi\Strict;
/** @var int maximum SQL length */
public static $maxLength = 1000;

View File

@@ -20,8 +20,6 @@ use Traversable;
*/
class Connection implements IConnection
{
use Strict;
/** @var array of function (Event $event); Occurs after query is executed */
public $onEvent = [];

View File

@@ -15,8 +15,6 @@ namespace Dibi;
*/
class DataSource implements IDataSource
{
use Strict;
/** @var Connection */
private $connection;

View File

@@ -15,8 +15,6 @@ namespace Dibi;
*/
class DateTime extends \DateTimeImmutable
{
use Strict;
/**
* @param string|int $time
*/

View File

@@ -17,8 +17,6 @@ use Dibi;
*/
class DummyDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
{
use Dibi\Strict;
public function disconnect(): void
{
}

View File

@@ -26,8 +26,6 @@ use Dibi\Helpers;
*/
class FirebirdDriver implements Dibi\Driver
{
use Dibi\Strict;
public const ERROR_EXCEPTION_THROWN = -836;
/** @var resource */

View File

@@ -17,8 +17,6 @@ use Dibi;
*/
class FirebirdReflector implements Dibi\Reflector
{
use Dibi\Strict;
/** @var Dibi\Driver */
private $driver;

View File

@@ -18,8 +18,6 @@ use Dibi\Helpers;
*/
class FirebirdResult implements Dibi\ResultDriver
{
use Dibi\Strict;
/** @var resource */
private $resultSet;

View File

@@ -18,8 +18,6 @@ use Dibi;
*/
class MySqlReflector implements Dibi\Reflector
{
use Dibi\Strict;
/** @var Dibi\Driver */
private $driver;

View File

@@ -32,8 +32,6 @@ use Dibi;
*/
class MySqliDriver implements Dibi\Driver
{
use Dibi\Strict;
public const ERROR_ACCESS_DENIED = 1045;
public const ERROR_DUPLICATE_ENTRY = 1062;

View File

@@ -17,8 +17,6 @@ use Dibi;
*/
class MySqliResult implements Dibi\ResultDriver
{
use Dibi\Strict;
/** @var \mysqli_result */
private $resultSet;

View File

@@ -17,8 +17,6 @@ use Dibi;
*/
class NoDataResult implements Dibi\ResultDriver
{
use Dibi\Strict;
/** @var int */
private $rows;

View File

@@ -25,8 +25,6 @@ use Dibi;
*/
class OdbcDriver implements Dibi\Driver
{
use Dibi\Strict;
/** @var resource */
private $connection;

View File

@@ -17,8 +17,6 @@ use Dibi;
*/
class OdbcReflector implements Dibi\Reflector
{
use Dibi\Strict;
/** @var Dibi\Driver */
private $driver;

View File

@@ -17,8 +17,6 @@ use Dibi;
*/
class OdbcResult implements Dibi\ResultDriver
{
use Dibi\Strict;
/** @var resource */
private $resultSet;

View File

@@ -27,8 +27,6 @@ use Dibi;
*/
class OracleDriver implements Dibi\Driver
{
use Dibi\Strict;
/** @var resource */
private $connection;

View File

@@ -17,8 +17,6 @@ use Dibi;
*/
class OracleReflector implements Dibi\Reflector
{
use Dibi\Strict;
/** @var Dibi\Driver */
private $driver;

View File

@@ -17,8 +17,6 @@ use Dibi;
*/
class OracleResult implements Dibi\ResultDriver
{
use Dibi\Strict;
/** @var resource */
private $resultSet;

View File

@@ -27,8 +27,6 @@ use PDO;
*/
class PdoDriver implements Dibi\Driver
{
use Dibi\Strict;
/** @var PDO|null Connection resource */
private $connection;

View File

@@ -19,8 +19,6 @@ use PDO;
*/
class PdoResult implements Dibi\ResultDriver
{
use Dibi\Strict;
/** @var \PDOStatement|null */
private $resultSet;

View File

@@ -28,8 +28,6 @@ use PgSql;
*/
class PostgreDriver implements Dibi\Driver
{
use Dibi\Strict;
/** @var resource|PgSql\Connection */
private $connection;

View File

@@ -17,8 +17,6 @@ use Dibi;
*/
class PostgreReflector implements Dibi\Reflector
{
use Dibi\Strict;
/** @var Dibi\Driver */
private $driver;

View File

@@ -19,8 +19,6 @@ use PgSql;
*/
class PostgreResult implements Dibi\ResultDriver
{
use Dibi\Strict;
/** @var resource|PgSql\Result */
private $resultSet;

View File

@@ -25,8 +25,6 @@ use SQLite3;
*/
class SqliteDriver implements Dibi\Driver
{
use Dibi\Strict;
/** @var SQLite3 */
private $connection;

View File

@@ -17,8 +17,6 @@ use Dibi;
*/
class SqliteReflector implements Dibi\Reflector
{
use Dibi\Strict;
/** @var Dibi\Driver */
private $driver;

View File

@@ -18,8 +18,6 @@ use Dibi\Helpers;
*/
class SqliteResult implements Dibi\ResultDriver
{
use Dibi\Strict;
/** @var \SQLite3Result */
private $resultSet;

View File

@@ -27,8 +27,6 @@ use Dibi\Helpers;
*/
class SqlsrvDriver implements Dibi\Driver
{
use Dibi\Strict;
/** @var resource */
private $connection;

View File

@@ -17,8 +17,6 @@ use Dibi;
*/
class SqlsrvReflector implements Dibi\Reflector
{
use Dibi\Strict;
/** @var Dibi\Driver */
private $driver;

View File

@@ -17,8 +17,6 @@ use Dibi;
*/
class SqlsrvResult implements Dibi\ResultDriver
{
use Dibi\Strict;
/** @var resource */
private $resultSet;

View File

@@ -15,8 +15,6 @@ namespace Dibi;
*/
class Event
{
use Strict;
/** event type */
public const
CONNECT = 1,

View File

@@ -15,8 +15,6 @@ namespace Dibi;
*/
class Expression
{
use Strict;
/** @var array */
private $values;

View File

@@ -45,8 +45,6 @@ namespace Dibi;
*/
class Fluent implements IDataSource
{
use Strict;
public const REMOVE = false;
/** @var array */

View File

@@ -12,8 +12,6 @@ namespace Dibi;
class Helpers
{
use Strict;
/** @var HashMap */
private static $types;

View File

@@ -15,8 +15,6 @@ namespace Dibi;
*/
class Literal
{
use Strict;
/** @var string */
private $value;

View File

@@ -17,8 +17,6 @@ use Dibi;
*/
class FileLogger
{
use Dibi\Strict;
/** @var string Name of the file where SQL errors should be logged */
public $file;

View File

@@ -27,8 +27,6 @@ use Dibi;
*/
class Column
{
use Dibi\Strict;
/** @var Dibi\Reflector|null when created by Result */
private $reflector;

View File

@@ -21,8 +21,6 @@ use Dibi;
*/
class Database
{
use Dibi\Strict;
/** @var Dibi\Reflector */
private $reflector;

View File

@@ -9,7 +9,6 @@ declare(strict_types=1);
namespace Dibi\Reflection;
use Dibi;
/**
@@ -20,8 +19,6 @@ use Dibi;
*/
class ForeignKey
{
use Dibi\Strict;
/** @var string */
private $name;

View File

@@ -9,7 +9,6 @@ declare(strict_types=1);
namespace Dibi\Reflection;
use Dibi;
/**
@@ -22,8 +21,6 @@ use Dibi;
*/
class Index
{
use Dibi\Strict;
/** @var array (name, columns, [unique], [primary]) */
private $info;

View File

@@ -20,8 +20,6 @@ use Dibi;
*/
class Result
{
use Dibi\Strict;
/** @var Dibi\ResultDriver */
private $driver;

View File

@@ -25,8 +25,6 @@ use Dibi;
*/
class Table
{
use Dibi\Strict;
/** @var Dibi\Reflector */
private $reflector;

View File

@@ -17,8 +17,6 @@ namespace Dibi;
*/
class Result implements IDataSource
{
use Strict;
/** @var ResultDriver|null */
private $driver;

View File

@@ -15,8 +15,6 @@ namespace Dibi;
*/
class ResultIterator implements \Iterator, \Countable
{
use Strict;
/** @var Result */
private $result;

View File

@@ -1,112 +0,0 @@
<?php
/**
* This file is part of the Dibi, smart database abstraction layer (https://dibiphp.com)
* Copyright (c) 2005 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Dibi;
use ReflectionClass;
use ReflectionMethod;
use ReflectionProperty;
/**
* Better OOP experience.
*/
trait Strict
{
/** @var array [method => [type => callback]] */
private static $extMethods;
/**
* Call to undefined method.
* @throws \LogicException
*/
public function __call(string $name, array $args)
{
$class = method_exists($this, $name) ? 'parent' : static::class;
$items = (new ReflectionClass($this))->getMethods(ReflectionMethod::IS_PUBLIC);
$items = array_map(fn($item) => $item->getName(), $items);
$hint = ($t = Helpers::getSuggestion($items, $name))
? ", did you mean $t()?"
: '.';
throw new \LogicException("Call to undefined method $class::$name()$hint");
}
/**
* Call to undefined static method.
* @throws \LogicException
*/
public static function __callStatic(string $name, array $args)
{
$rc = new ReflectionClass(static::class);
$items = array_filter($rc->getMethods(\ReflectionMethod::IS_STATIC), fn($m) => $m->isPublic());
$items = array_map(fn($item) => $item->getName(), $items);
$hint = ($t = Helpers::getSuggestion($items, $name))
? ", did you mean $t()?"
: '.';
throw new \LogicException("Call to undefined static method {$rc->getName()}::$name()$hint");
}
/**
* Access to undeclared property.
* @throws \LogicException
*/
public function &__get(string $name)
{
if ((method_exists($this, $m = 'get' . $name) || method_exists($this, $m = 'is' . $name))
&& (new ReflectionMethod($this, $m))->isPublic()
) { // back compatiblity
$ret = $this->$m();
return $ret;
}
$rc = new ReflectionClass($this);
$items = array_filter($rc->getProperties(ReflectionProperty::IS_PUBLIC), fn($p) => !$p->isStatic());
$items = array_map(fn($item) => $item->getName(), $items);
$hint = ($t = Helpers::getSuggestion($items, $name))
? ", did you mean $$t?"
: '.';
throw new \LogicException("Attempt to read undeclared property {$rc->getName()}::$$name$hint");
}
/**
* Access to undeclared property.
* @throws \LogicException
*/
public function __set(string $name, $value)
{
$rc = new ReflectionClass($this);
$items = array_filter($rc->getProperties(ReflectionProperty::IS_PUBLIC), fn($p) => !$p->isStatic());
$items = array_map(fn($item) => $item->getName(), $items);
$hint = ($t = Helpers::getSuggestion($items, $name))
? ", did you mean $$t?"
: '.';
throw new \LogicException("Attempt to write to undeclared property {$rc->getName()}::$$name$hint");
}
public function __isset(string $name): bool
{
return false;
}
/**
* Access to undeclared property.
* @throws \LogicException
*/
public function __unset(string $name)
{
$class = static::class;
throw new \LogicException("Attempt to unset undeclared property $class::$$name.");
}
}

View File

@@ -15,8 +15,6 @@ namespace Dibi;
*/
final class Translator
{
use Strict;
/** @var Connection */
private $connection;

View File

@@ -37,8 +37,6 @@ declare(strict_types=1);
*/
class dibi
{
use Dibi\Strict;
public const
AFFECTED_ROWS = 'a',
IDENTIFIER = 'n';

View File

@@ -1,151 +0,0 @@
<?php
declare(strict_types=1);
use Tester\Assert;
require __DIR__ . '/bootstrap.php';
class TestClass
{
use Dibi\Strict;
public $public;
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;
}
}
class TestChild extends TestClass
{
public function callParent()
{
parent::callParent();
}
}
// calling
Assert::exception(function () {
$obj = new TestClass;
$obj->undeclared();
}, LogicException::class, 'Call to undefined method TestClass::undeclared().');
Assert::exception(function () {
TestClass::undeclared();
}, LogicException::class, 'Call to undefined static method TestClass::undeclared().');
Assert::exception(function () {
$obj = new TestChild;
$obj->callParent();
}, LogicException::class, 'Call to undefined method parent::callParent().');
Assert::exception(function () {
$obj = new TestClass;
$obj->publicMethodX();
}, LogicException::class, 'Call to undefined method TestClass::publicMethodX(), did you mean publicMethod()?');
Assert::exception(function () { // suggest static method
$obj = new TestClass;
$obj->publicMethodStaticX();
}, 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::class, 'Call to undefined method TestClass::protectedMethodX().');
// writing
Assert::exception(function () {
$obj = new TestClass;
$obj->undeclared = 'value';
}, LogicException::class, 'Attempt to write to undeclared property TestClass::$undeclared.');
Assert::exception(function () {
$obj = new TestClass;
$obj->publicX = 'value';
}, 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::class, 'Attempt to write to undeclared property TestClass::$publicStaticX.');
Assert::exception(function () { // suggest only public property
$obj = new TestClass;
$obj->protectedX = 'value';
}, LogicException::class, 'Attempt to write to undeclared property TestClass::$protectedX.');
// property getter
$obj = new TestClass;
Assert::false(isset($obj->bar));
Assert::same(123, $obj->bar);
Assert::false(isset($obj->foo));
Assert::same(456, $obj->foo);
// reading
Assert::exception(function () {
$obj = new TestClass;
$val = $obj->undeclared;
}, LogicException::class, 'Attempt to read undeclared property TestClass::$undeclared.');
Assert::exception(function () {
$obj = new TestClass;
$val = $obj->publicX;
}, 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::class, 'Attempt to read undeclared property TestClass::$publicStaticX.');
Assert::exception(function () { // suggest only public property
$obj = new TestClass;
$val = $obj->protectedX;
}, LogicException::class, 'Attempt to read undeclared property TestClass::$protectedX.');
// unset/isset
Assert::exception(function () {
$obj = new TestClass;
unset($obj->undeclared);
}, LogicException::class, 'Attempt to unset undeclared property TestClass::$undeclared.');
Assert::false(isset($obj->undeclared));