phpstan/array typehint fixes

This commit is contained in:
Dennis Eichhorn 2020-02-05 21:09:31 +01:00
parent 8d48e3b317
commit 6c917b5486
15 changed files with 52 additions and 44 deletions

View File

@ -60,10 +60,10 @@ abstract class ConnectionAbstract implements ConnectionInterface
/**
* Database data.
*
* @var array{db:string, host:string, port:int, login:string, password:string, database:string, prefix:string}
* @var array{db:string, database:string, prefix:string}|array{db:string, host:string, port:int, login:string, password:string, database:string, prefix:string}
* @since 1.0.0
*/
protected array $dbdata = [];
protected array $dbdata;
/**
* Database type.
@ -146,7 +146,7 @@ abstract class ConnectionAbstract implements ConnectionInterface
*/
public function getPort() : int
{
return (int) $this->dbdata['port'] ?? 0;
return (int) ($this->dbdata['port'] ?? 0);
}
/**
@ -178,7 +178,9 @@ abstract class ConnectionAbstract implements ConnectionInterface
}
/**
* array{db:string, host:string, port:int, login:string, password:string, database:string, prefix:string} $dbdata the basic database information for establishing a connection
* Connect to database
*
* @param null|array{db:string, database:string, prefix:string}|array{db:string, host:string, port:int, login:string, password:string, database:string, prefix:string} $dbdata the basic database information for establishing a connection
*
* @return void
*

View File

@ -41,7 +41,7 @@ final class ConnectionFactory
*
* Overwrites current connection if existing
*
* @param array{db:string, host:string, port:int, login:string, password:string, database:string, prefix:string} $dbdata the basic database information for establishing a connection
* @param array{db:string, database:string, prefix:string}|array{db:string, host:string, port:int, login:string, password:string, database:string, prefix:string} $dbdata the basic database information for establishing a connection
*
* @return ConnectionAbstract
*

View File

@ -38,7 +38,7 @@ final class SQLiteConnection extends ConnectionAbstract
*
* Creates the database object and overwrites all default values.
*
* @param array{db:string, host:string, port:int, login:string, password:string, database:string, prefix:string} $dbdata the basic database information for establishing a connection
* @param array{db:string, database:string, prefix:string} $dbdata the basic database information for establishing a connection
*
* @since 1.0.0
*/
@ -58,7 +58,13 @@ final class SQLiteConnection extends ConnectionAbstract
}
/**
* {@inheritdoc}
* Connect to database
*
* @param null|array{db:string, database:string, prefix:string} $dbdata the basic database information for establishing a connection
*
* @return void
*
* @since 1.0.0
*/
public function connect(array $dbdata = null) : void
{

View File

@ -65,7 +65,6 @@ final class SqlServerConnection extends ConnectionAbstract
$this->close();
$this->dbdata = $dbdata ?? $this->dbdata;
$this->prefix = $dbdata['prefix'];
if (!isset($this->dbdata['db'], $this->dbdata['host'], $this->dbdata['port'], $this->dbdata['database'], $this->dbdata['login'], $this->dbdata['password'])
|| !DatabaseType::isValidValue($this->dbdata['db'])
@ -74,6 +73,9 @@ final class SqlServerConnection extends ConnectionAbstract
throw new InvalidConnectionConfigException((string) \json_encode($this->dbdata));
}
$this->close();
$this->prefix = $dbdata['prefix'] ?? '';
try {
$this->con = new \PDO('sqlsrv:Server=' . $this->dbdata['host'] . ',' . $this->dbdata['port'] . ';Database=' . $this->dbdata['database'] . ';ConnectionPooling=0', $this->dbdata['login'], $this->dbdata['password']);
$this->con->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);

View File

@ -104,8 +104,8 @@ final class DatabasePool implements DataStoragePoolInterface
/**
* Create database.
*
* @param string $key Database key
* @param array $config Database config data
* @param string $key Database key
* @param array{db:string, database:string, prefix:string}|array{db:string, host:string, port:int, login:string, password:string, database:string, prefix:string} $config Database config data
*
* @return bool
*

View File

@ -62,7 +62,7 @@ final class Currency
* @var string
* @since 1.0.0
*/
private string $number = 0;
private string $number = '';
/**
* Currency subunits.
@ -78,7 +78,7 @@ final class Currency
* @var string
* @since 1.0.0
*/
private string $decimals = 0;
private string $decimals = '';
/**
* Currency countries.

View File

@ -30,7 +30,7 @@ final class L11nManager
/**
* Language.
*
* @var array<string, string>
* @var array<string, array<int|string, array<string, string>>>
* @since 1.0.0
*/
private array $language = [];
@ -128,7 +128,7 @@ final class L11nManager
* @param string $language Language iso code
* @param string $module Module name
*
* @return array<string, string>|array<string, array<string, string>>
* @return array<int|string, array<string, string>>|array<string, string>
*
* @since 1.0.0
*/

View File

@ -189,7 +189,7 @@ final class FileLogger implements LoggerInterface
$temp = \explode(' ', \microtime());
$mtime = ((float) $temp[1]) + ((float) $temp[0]);
self::$timings[$id] = ['start' => $mtime];
self::$timings[$id] = ['start' => $mtime, 'end' => 0.0, 'time' => 0.0];
return true;
}

View File

@ -45,7 +45,7 @@ final class Polygon implements D2ShapeInterface
/**
* Constructor.
*
* @param array[] $coord 2 Dimensional coordinate array where the indices are x and y
* @param array<int, array{x:int|float, y:int|float}> $coord 2 Dimensional coordinate array where the indices are x and y
*
* @example Polygon([['x' => 1, 'y' => 2], ['x' => ...], ...])
*
@ -59,7 +59,7 @@ final class Polygon implements D2ShapeInterface
/**
* Point polygon relative position
*
* @param array<string, float|int> $point Point location
* @param array{x:int|float, y:int|float} $point Point location
*
* @return int
*
@ -76,8 +76,8 @@ final class Polygon implements D2ShapeInterface
/**
* Point polygon relative position
*
* @param array<string, float|int> $point Point location
* @param array<int, array<string, float|int>> $polygon Polygon definition
* @param array{x:int|float, y:int|float} $point Point location
* @param array<int, array{x:int|float, y:int|float}> $polygon Polygon definition
*
* @return int -1 inside polygon 0 on vertice 1 outside
*
@ -141,8 +141,8 @@ final class Polygon implements D2ShapeInterface
/**
* Is point on vertex?
*
* @param array<string, float|int> $point Point location
* @param array<int, array<string, float|int>> $polygon Polygon definition
* @param array{x:int|float, y:int|float} $point Point location
* @param array<int, array{x:int|float, y:int|float}> $polygon Polygon definition
*
* @return bool
*
@ -239,7 +239,7 @@ final class Polygon implements D2ShapeInterface
/**
* Get barycenter
*
* @return array<string, float|int>
* @return array{x:int|float, y:int|float}
*
* @since 1.0.0
*/

View File

@ -49,7 +49,7 @@ final class Head implements RenderableInterface
/**
* Assets bound to this page instance.
*
* @var array<string, array<type:int, attributes:array>>
* @var array|array<string, array{type:int, attributes:array}>
* @since 1.0.0
*/
private array $assets = [];

View File

@ -66,7 +66,7 @@ final class ModuleManager
/**
* Installed modules.
*
* @var array<string, array>
* @var array<string, InfoManager>
* @since 1.0.0
*/
private array $installed = [];
@ -264,7 +264,7 @@ final class ModuleManager
$content = \file_get_contents($path);
$json = \json_decode($content === false ? '[]' : $content, true);
$this->all[$json['name']['internal']] = $json === false ? [] : $json;
$this->all[(string) ($json['name']['internal'] ?? '?')] = $json === false ? [] : $json;
}
}
@ -288,7 +288,7 @@ final class ModuleManager
*
* @param bool $useCache Use Cache
*
* @return array<string, array>
* @return array<string, InfoManager>
*
* @since 1.0.0
*/
@ -311,10 +311,7 @@ final class ModuleManager
// throw new PathException($path);
}
$content = \file_get_contents($path);
$json = \json_decode($content === false ? '[]' : $content, true);
$this->installed[$json['name']['internal']] = $json === false ? [] : $json;
$this->installed[$module] = $this->loadInfo($module);
}
}

View File

@ -231,13 +231,13 @@ class PriorityQueue implements \Countable, \Serializable
/**
* Delete element.
*
* @param mixed $id Element to delete
* @param int $id Element to delete
*
* @return bool
*
* @since 1.0.0
*/
public function delete($id) : bool
public function delete(int $id) : bool
{
if (isset($this->queue[$id])) {
unset($this->queue[$id]);
@ -251,14 +251,14 @@ class PriorityQueue implements \Countable, \Serializable
/**
* Set element priority.
*
* @param mixed $id Element ID
* @param int $id Element ID
* @param float $priority Element priority
*
* @return void
*
* @since 1.0.0
*/
public function setPriority($id, float $priority) : void
public function setPriority(int $id, float $priority) : void
{
if ($this->type === PriorityMode::FIFO || $this->type === PriorityMode::LIFO) {
$this->queue[$id]['priority'] = $priority;
@ -279,13 +279,13 @@ class PriorityQueue implements \Countable, \Serializable
/**
* Get element
*
* @param mixed $id Element ID
* @param int $id Element ID
*
* @return array
*
* @since 1.0.0
*/
public function get($id) : array
public function get(int $id) : array
{
return $this->queue[$id] ?? [];
}
@ -293,7 +293,7 @@ class PriorityQueue implements \Countable, \Serializable
/**
* Get element
*
* @return array<array>
* @return array<int, array{data:mixed, priority:float}>
*
* @since 1.0.0
*/

View File

@ -29,7 +29,7 @@ final class Storage
/**
* Registered storage.
*
* @var array<string, StorageAbstract|string>
* @var array<string, StorageAbstract|string|ContainerInterface>
* @since 1.0.0
*/
private static array $registered = [];
@ -87,8 +87,8 @@ final class Storage
/**
* Register storage environment.
*
* @param string $name Name of the environment
* @param StorageAbstract|string $class Class to register. This can be either a namespace path, a anonymous class or storage implementation.
* @param string $name Name of the environment
* @param ContainerInterface|StorageAbstract|string $class Class to register. This can be either a namespace path, a anonymous class or storage implementation.
*
* @return bool
*

View File

@ -77,6 +77,7 @@ final class Dictionary
$this->min = -1;
$this->max = -1;
/** @var array<int, array<int, string|array>> $count */
$count = [];
while (isset($source[0])) {
$count[] = [\substr_count($source, $source[0]), $source[0]];
@ -98,8 +99,8 @@ final class Dictionary
/**
* Fill dictionary.
*
* @param array<int, array<int, string>> $entry Source data to generate dictionary from
* @param string $value Dictionary value
* @param array<int, array<int, string|array>> $entry Source data to generate dictionary from
* @param string $value Dictionary value
*
* @return void
*

View File

@ -83,7 +83,7 @@ class Commit
/**
* Files.
*
* @var array<string, array{old:string, new:string}>
* @var array<string, array<int, array{old:string, new:string}>>
* @since 1.0.0
*/
private array $files = [];
@ -165,7 +165,7 @@ class Commit
/**
* Get files of this commit.
*
* @return string[]
* @return array<string, array<int, array{old:string, new:string}>>
*
* @since 1.0.0
*/