Fixes for phan and phpstan

Note that the (string) for pg_escape_string and pg_escape_literal are
forced for phpstan because it thinks this might return false even
thought both function only return string ever
This commit is contained in:
Clemens Schwaighofer
2022-03-03 06:49:15 +09:00
parent 42b961f35e
commit a0a7389d3b
3 changed files with 21 additions and 13 deletions

View File

@@ -694,10 +694,10 @@ class IO
* @param object|resource|bool $cursor current cursor for pg_result_error, * @param object|resource|bool $cursor current cursor for pg_result_error,
* pg_last_error too, but pg_result_error * pg_last_error too, but pg_result_error
* is more accurate (PgSql\Result) * is more accurate (PgSql\Result)
* @return array Pos 0: if we could get the method where it was called * @return array<mixed> Pos 0: if we could get the method where it was called
* if not found [Uknown Method] * if not found [Uknown Method]
* Pos 1: if we have the pg_error_string from last error * Pos 1: if we have the pg_error_string from last error
* if nothing then empty string * if nothing then empty string
*/ */
private function __dbErrorPreprocessor($cursor = false): array private function __dbErrorPreprocessor($cursor = false): array
{ {
@@ -898,7 +898,7 @@ class IO
* Read data from previous written data cache * Read data from previous written data cache
* @param string $query_hash The hash for the current query * @param string $query_hash The hash for the current query
* @param boolean $assoc_only Only return assoc value (key named) * @param boolean $assoc_only Only return assoc value (key named)
* @return array Current position query data from cache * @return array<mixed> Current position query data from cache
*/ */
private function __dbReturnCacheRead(string $query_hash, bool $assoc_only): array private function __dbReturnCacheRead(string $query_hash, bool $assoc_only): array
{ {
@@ -1479,9 +1479,12 @@ class IO
break; break;
// bytea data // bytea data
case 'by': case 'by':
$value = empty($value) ? 'NULL' : $this->dbEscapeBytea($value); $value = empty($value) ? 'NULL' : $this->dbEscapeBytea((string)$value);
break; break;
case 'b': case 'b':
if (is_float($value)) {
$value = (int)$value;
}
$value = $value === '' || $value === null ? $value = $value === '' || $value === null ?
'NULL' : 'NULL' :
"'" . $this->dbBoolean($value, true) . "'"; "'" . $this->dbBoolean($value, true) . "'";
@@ -2840,7 +2843,7 @@ class IO
/** /**
* Return field names from query * Return field names from query
* @return array Field names as array * @return array<mixed> Field names as array
*/ */
public function dbGetFieldNames(): array public function dbGetFieldNames(): array
{ {
@@ -2896,7 +2899,8 @@ class IO
/** /**
* Return the combined warning and error history * Return the combined warning and error history
* @return array * TODO: add options to return only needed (Eg error, time based)
* @return array<mixed> Complete long error history string
*/ */
public function dbGetCombinedErrorHistory(): array public function dbGetCombinedErrorHistory(): array
{ {
@@ -2996,7 +3000,7 @@ class IO
/** /**
* DEPRECATED: getCursorExt * DEPRECATED: getCursorExt
* @param string|null $q [DEPRECATED] * @param string|null $q [DEPRECATED]
* @return array<mixed>|null [DEPRECATED] * @return array<mixed>|string|int|resource|object|null [DEPRECATED]
* @deprecated use dbGetCursorExt($q = null) instead * @deprecated use dbGetCursorExt($q = null) instead
*/ */
public function getCursorExt($q = null) public function getCursorExt($q = null)

View File

@@ -528,9 +528,10 @@ class PgSQL
public function __dbEscapeLiteral($string): string public function __dbEscapeLiteral($string): string
{ {
if ($this->dbh === false || is_bool($this->dbh)) { if ($this->dbh === false || is_bool($this->dbh)) {
return ''; return (string)'';
} }
return pg_escape_literal($this->dbh, (string)$string); // for phpstan, thinks this is string|false?
return (string)pg_escape_literal($this->dbh, (string)$string);
} }
/** /**
@@ -544,7 +545,8 @@ class PgSQL
if ($this->dbh === false || is_bool($this->dbh)) { if ($this->dbh === false || is_bool($this->dbh)) {
return ''; return '';
} }
return pg_escape_identifier($this->dbh, (string)$string); // for phpstan, thinks this is string|false?
return (string)pg_escape_identifier($this->dbh, (string)$string);
} }
/** /**
@@ -583,7 +585,9 @@ class PgSQL
return false; return false;
} }
$busy = pg_connection_busy($this->dbh); $busy = pg_connection_busy($this->dbh);
/** @var array<resource>|null */
$socket = [pg_socket($this->dbh)]; $socket = [pg_socket($this->dbh)];
$null = null;
while ($busy) { while ($busy) {
// Will wait on that socket until that happens or the timeout is reached // Will wait on that socket until that happens or the timeout is reached
stream_select($socket, $null, $null, $timeout_seconds); stream_select($socket, $null, $null, $timeout_seconds);

View File

@@ -97,7 +97,7 @@ class Support
* Defaults to skip level 0 wich is this methid * Defaults to skip level 0 wich is this methid
* @param integer $start_level From what level on, as defaul starts with 1 * @param integer $start_level From what level on, as defaul starts with 1
* to exclude self * to exclude self
* @return array All method names in list where max is last called * @return array<mixed> All method names in list where max is last called
*/ */
public static function getCallerMethodList(int $start_level = 1): array public static function getCallerMethodList(int $start_level = 1): array
{ {