1
0
mirror of https://github.com/dg/dibi.git synced 2025-02-23 10:26:21 +01:00

strict type fixes [Closes #255][Closes #256]

This commit is contained in:
David Grudl 2017-07-21 22:15:45 +02:00
parent 662927d823
commit cb9fd29207
4 changed files with 10 additions and 9 deletions

View File

@ -57,7 +57,7 @@ class Event
{
$this->connection = $connection;
$this->type = $type;
$this->sql = trim($sql);
$this->sql = trim((string) $sql);
$this->time = -microtime(true);
if ($type === self::QUERY && preg_match('#\(?\s*(SELECT|UPDATE|INSERT|DELETE)#iA', $this->sql, $matches)) {

View File

@ -22,11 +22,11 @@ class Helpers
* Prints out a syntax highlighted version of the SQL command or Result.
* @param string|Result
*/
public static function dump($sql = null, bool $return = false): string
public static function dump($sql = null, bool $return = false): ?string
{
ob_start();
if ($sql instanceof Result && PHP_SAPI === 'cli') {
$hasColors = (substr(getenv('TERM'), 0, 5) === 'xterm');
$hasColors = (substr((string) getenv('TERM'), 0, 5) === 'xterm');
$maxLen = 0;
foreach ($sql as $i => $row) {
if ($i === 0) {
@ -88,7 +88,7 @@ class Helpers
// syntax highlight
$highlighter = "#(/\\*.+?\\*/)|(\\*\\*.+?\\*\\*)|(?<=[\\s,(])($keywords1)(?=[\\s,)])|(?<=[\\s,(=])($keywords2)(?=[\\s,)=])#is";
if (PHP_SAPI === 'cli') {
if (substr(getenv('TERM'), 0, 5) === 'xterm') {
if (substr((string) getenv('TERM'), 0, 5) === 'xterm') {
$sql = preg_replace_callback($highlighter, function ($m) {
if (!empty($m[1])) { // comment
return "\033[1;30m" . $m[1] . "\033[0m";
@ -130,6 +130,7 @@ class Helpers
return ob_get_clean();
} else {
ob_end_flush();
return null;
}
}

View File

@ -44,7 +44,7 @@ class Result implements IDataSource
/** @var bool Already fetched? Used for allowance for first seek(0) */
private $fetched = false;
/** @var string returned object class */
/** @var ?string returned object class */
private $rowClass = Row::class;
/** @var callable returned object factory*/
@ -133,7 +133,7 @@ class Result implements IDataSource
/**
* Set fetched object class. This class should extend the Row class.
*/
public function setRowClass(string $class): self
public function setRowClass(?string $class): self
{
$this->rowClass = $class;
return $this;
@ -143,7 +143,7 @@ class Result implements IDataSource
/**
* Returns fetched object class name.
*/
public function getRowClass(): string
public function getRowClass(): ?string
{
return $this->rowClass;
}

View File

@ -67,7 +67,7 @@ class dibi
* Creates a new Connection object and connects it to specified database.
* @throws Dibi\Exception
*/
public static function connect(array $config = [], string $name = '0'): Dibi\Connection
public static function connect($config = [], string $name = '0'): Dibi\Connection
{
return self::$connection = self::$registry[$name] = new Dibi\Connection($config, $name);
}
@ -358,7 +358,7 @@ class dibi
* @param string|Result
* @param bool return output instead of printing it?
*/
public static function dump($sql = null, bool $return = false): string
public static function dump($sql = null, bool $return = false): ?string
{
return Dibi\Helpers::dump($sql, $return);
}