phpstan fixes

This commit is contained in:
Dennis Eichhorn 2020-11-27 22:56:16 +01:00
parent f9e71e5a9e
commit aaf34cd373
17 changed files with 121 additions and 60 deletions

View File

@ -18,6 +18,9 @@ namespace phpOMS\Algorithm\Clustering;
/**
* Point interface.
*
* @property int $group Group
* @property string $name Name
*
* @package phpOMS\Algorithm\Clustering;
* @license OMS License 1.0
* @link https://orange-management.org

View File

@ -813,8 +813,6 @@ class DataMapperAbstract implements DataMapperInterface
}
// Setting relation value (id) for relation (since the relation is not stored in an extra relation table)
/** @var string $table */
/** @var array $columns */
if (!isset(static::$hasMany[$propertyName]['external'])) {
$relProperty = $relReflectionClass->getProperty($mapper::$columns[static::$hasMany[$propertyName]['self']]['internal']);
@ -893,8 +891,6 @@ class DataMapperAbstract implements DataMapperInterface
}
// Setting relation value (id) for relation (since the relation is not stored in an extra relation table)
/** @var string $table */
/** @var array $columns */
if (static::$hasMany[$propertyName]['table'] === static::$hasMany[$propertyName]['mapper']::$table
&& isset($mapper::$columns[static::$hasMany[$propertyName]['self']])
) {
@ -1153,8 +1149,6 @@ class DataMapperAbstract implements DataMapperInterface
}
// create if not existing
/** @var string $table */
/** @var array $columns */
if (static::$hasMany[$propertyName]['table'] === static::$hasMany[$propertyName]['mapper']::$table
&& isset($mapper::$columns[static::$hasMany[$propertyName]['self']])
) {
@ -1235,8 +1229,6 @@ class DataMapperAbstract implements DataMapperInterface
}
// create if not existing
/** @var string $table */
/** @var array $columns */
if (static::$hasMany[$propertyName]['table'] === static::$hasMany[$propertyName]['mapper']::$table
&& isset($mapper::$columns[static::$hasMany[$propertyName]['self']])
) {
@ -1293,7 +1285,6 @@ class DataMapperAbstract implements DataMapperInterface
*/
private static function deleteRelationTable(string $propertyName, array $objsIds, $objId) : void
{
/** @var string $table */
if (empty($objsIds)
|| static::$hasMany[$propertyName]['table'] === static::$table
|| static::$hasMany[$propertyName]['table'] === static::$hasMany[$propertyName]['mapper']::$table
@ -2879,7 +2870,7 @@ class DataMapperAbstract implements DataMapperInterface
$query->random(static::$primaryField)
->limit($amount);
return self::getAllByQuery($query, $relations, $depth, null, $query);
return self::getAllByQuery($query, $relations, $depth);
}
/**
@ -3103,7 +3094,6 @@ class DataMapperAbstract implements DataMapperInterface
$query = new Builder(self::$db);
if (self::$relations === RelationType::ALL) {
/** @var string $primaryField */
$src = $value['external'] ?? $value['mapper']::$primaryField;
$query->select($value['table'] . '.' . $src)

View File

@ -143,7 +143,7 @@ class Builder extends BuilderAbstract
/**
* Group.
*
* @var string[]
* @var string[]|self[]
* @since 1.0.0
*/
public array $groups = [];
@ -274,6 +274,8 @@ class Builder extends BuilderAbstract
{
$this->type = QueryType::SELECT;
/** @var mixed[] $columns */
/** @var mixed $column */
foreach ($columns as $column) {
if (\is_string($column) || $column instanceof self) {
$this->selects[] = $column;
@ -489,7 +491,7 @@ class Builder extends BuilderAbstract
/**
* From.
*
* @param array ...$tables Tables
* @param mixed ...$tables Tables
*
* @return Builder
*
@ -497,6 +499,8 @@ class Builder extends BuilderAbstract
*/
public function from(...$tables) : self
{
/** @var mixed[] $tables */
/** @var mixed $table */
foreach ($tables as $key => $table) {
if (\is_string($table) || $table instanceof self) {
$this->from[] = $table;
@ -654,7 +658,7 @@ class Builder extends BuilderAbstract
/**
* Group by.
*
* @param array|string ...$columns Grouping result
* @param mixed ...$columns Grouping result
*
* @return Builder
*
@ -662,6 +666,8 @@ class Builder extends BuilderAbstract
*/
public function groupBy(...$columns) : self
{
/** @var mixed[] $columns */
/** @var mixed $column */
foreach ($columns as $column) {
if (\is_string($column) || $column instanceof self) {
$this->groups[] = $column;
@ -998,7 +1004,7 @@ class Builder extends BuilderAbstract
/**
* Values to insert.
*
* @param array ...$sets Values
* @param mixed ...$sets Values
*
* @return Builder
*
@ -1030,7 +1036,7 @@ class Builder extends BuilderAbstract
/**
* Update columns.
*
* @param array ...$tables Column names to update
* @param mixed ...$tables Column names to update
*
* @return Builder
*
@ -1046,6 +1052,8 @@ class Builder extends BuilderAbstract
$this->type = QueryType::UPDATE;
/** @var mixed[] $tables */
/** @var mixed $table */
foreach ($tables as $table) {
if (\is_string($table) || $table instanceof self) {
$this->updates[] = $table;
@ -1100,7 +1108,7 @@ class Builder extends BuilderAbstract
/**
* Join.
*
* @param mixed $table Join query
* @param string|self $table Join query
* @param string $type Join type
* @param null|string $alias Alias name (empty = none)
*
@ -1110,7 +1118,9 @@ class Builder extends BuilderAbstract
*/
public function join($table, string $type = JoinType::JOIN, string $alias = null) : self
{
if (!\is_string($table) && !($table instanceof self)) {
if ((!\is_string($table) && !($table instanceof self))
|| ($alias === null && !\is_string($table))
) {
throw new \InvalidArgumentException();
}

View File

@ -704,7 +704,7 @@ class Matrix implements \ArrayAccess, \Iterator
/**
* {@inheritdoc}
*/
public function current()
public function current() : int
{
return $this->offsetGet($this->position);
}

View File

@ -146,4 +146,16 @@ abstract class HeaderAbstract
* @since 1.0.0
*/
abstract public function has(string $key) : bool;
/**
* Push all headers.
*
* @return void
*
* @since 1.0.0
* @codeCoverageIgnore
*/
public function push() : void
{
}
}

View File

@ -25,6 +25,8 @@ use phpOMS\Views\View;
/**
* Response class.
*
* @property \phpOMS\Message\Http\HttpHeader $header Http header
*
* @package phpOMS\Message\Http
* @license OMS License 1.0
* @link https://orange-management.org

View File

@ -198,6 +198,7 @@ abstract class InstallerAbstract
{
$directories = new Directory(\dirname($info->getPath()) . '/Admin/Routes');
/** @var Directory|File $child */
foreach ($directories as $child) {
if ($child instanceof Directory) {
foreach ($child as $file) {
@ -277,6 +278,7 @@ abstract class InstallerAbstract
{
$directories = new Directory(\dirname($info->getPath()) . '/Admin/Hooks');
/** @var Directory|File $child */
foreach ($directories as $child) {
if ($child instanceof Directory) {
foreach ($child as $file) {

View File

@ -97,7 +97,7 @@ final class ModuleManager
/**
* All modules in the module directory.
*
* @var array<string, array>
* @var array<string, ModuleInfo>
* @since 1.0.0
*/
private array $all = [];
@ -252,7 +252,7 @@ final class ModuleManager
/**
* Get all modules in the module directory.
*
* @return array<string, array>
* @return array<string, ModuleInfo>
*
* @since 1.0.0
*/
@ -268,10 +268,10 @@ final class ModuleManager
$c = $files === false ? 0 : \count($files);
for ($i = 0; $i < $c; ++$i) {
$module = $this->loadInfo($files[$i]);
$info = $this->loadInfo($files[$i]);
if ($module !== null) {
$this->all[$files[$i]] = $module;
if ($info !== null) {
$this->all[$files[$i]] = $info;
}
}
}
@ -311,7 +311,11 @@ final class ModuleManager
$installed = $sth->fetchAll(\PDO::FETCH_COLUMN);
foreach ($installed as $module) {
$this->installed[$module] = $this->loadInfo($module);
$info = $this->loadInfo($module);
if ($info !== null) {
$this->installed[$module] = $info;
}
}
}
@ -361,6 +365,10 @@ final class ModuleManager
try {
$info = $this->loadInfo($module);
if ($info === null) {
return false;
}
$this->deactivateModule($info);
return true;
@ -412,6 +420,10 @@ final class ModuleManager
try {
$info = $this->loadInfo($module);
if ($info === null) {
return false;
}
$this->activateModule($info);
return true;
@ -457,7 +469,11 @@ final class ModuleManager
*/
public function reInit(string $module, ApplicationInfo $appInfo = null) : void
{
$info = $this->loadInfo($module);
$info = $this->loadInfo($module);
if ($info === null) {
return;
}
$class = '\\Modules\\' . $info->getDirectory() . '\\Admin\\Installer';
if (!Autoloader::exists($class)) {
@ -491,6 +507,9 @@ final class ModuleManager
try {
$info = $this->loadInfo($module);
if ($info === null) {
return false;
}
$this->installed[$module] = $info;
$this->installDependencies($info->getDependencies());
@ -541,6 +560,9 @@ final class ModuleManager
try {
$info = $this->loadInfo($module);
if ($info === null) {
return false;
}
$this->installed[$module] = $info;
// uninstall dependencies if not used by others

View File

@ -32,16 +32,8 @@ use phpOMS\Utils\StringUtils;
* @link https://orange-management.org
* @since 1.0.0
*/
class Directory extends FileAbstract implements DirectoryInterface, FtpContainerInterface
class Directory extends FileAbstract implements DirectoryInterface
{
/**
* Directory nodes (files and directories).
*
* @var FileAbstract[]
* @since 1.0.0
*/
private array $nodes = [];
/**
* Filter for directory listing
*
@ -50,6 +42,14 @@ class Directory extends FileAbstract implements DirectoryInterface, FtpContainer
*/
private string $filter = '*';
/**
* Directory nodes (files and directories).
*
* @var array<string, ContainerInterface>
* @since 1.0.0
*/
private array $nodes = [];
/**
* Create ftp connection.
*
@ -385,6 +385,7 @@ class Directory extends FileAbstract implements DirectoryInterface, FtpContainer
$data[$names[$key]] = $e;
}
/** @var array<string, array{permission:int, number:string, user:string, group:string, size:string, month:string, day:string, time:string, type:string}> */
return $data;
}
@ -499,7 +500,11 @@ class Directory extends FileAbstract implements DirectoryInterface, FtpContainer
if (\is_dir($item)) {
self::put($con, $item, $to . '/' . self::name($item));
} else {
File::put($con, $to . '/' . self::name($item), \file_get_contents($item));
$content = \file_get_contents($item);
if ($content !== false) {
File::put($con, $to . '/' . self::name($item), $content);
}
}
}
@ -682,7 +687,7 @@ class Directory extends FileAbstract implements DirectoryInterface, FtpContainer
/**
* {@inheritdoc}
*/
public function key()
public function key() : ?string
{
return \key($this->nodes);
}
@ -690,7 +695,7 @@ class Directory extends FileAbstract implements DirectoryInterface, FtpContainer
/**
* {@inheritdoc}
*/
public function next()
public function next() : FileAbstract
{
$next = \next($this->nodes);
@ -704,7 +709,7 @@ class Directory extends FileAbstract implements DirectoryInterface, FtpContainer
/**
* {@inheritdoc}
*/
public function valid()
public function valid() : bool
{
$key = \key($this->nodes);

View File

@ -14,7 +14,6 @@ declare(strict_types=1);
namespace phpOMS\System\File\Ftp;
use phpOMS\System\File\ContainerInterface;
use phpOMS\Uri\HttpUri;
/**
@ -27,7 +26,7 @@ use phpOMS\Uri\HttpUri;
* @link https://orange-management.org
* @since 1.0.0
*/
abstract class FileAbstract implements ContainerInterface
abstract class FileAbstract implements FtpContainerInterface
{
/**
* Ftp connection

View File

@ -14,6 +14,8 @@ declare(strict_types=1);
namespace phpOMS\System\File\Ftp;
use phpOMS\System\File\ContainerInterface;
/**
* Filesystem class.
*
@ -24,7 +26,7 @@ namespace phpOMS\System\File\Ftp;
* @link https://orange-management.org
* @since 1.0.0
*/
interface FtpContainerInterface
interface FtpContainerInterface extends ContainerInterface
{
/**
* Get the datetime when the resource got created.

View File

@ -29,7 +29,7 @@ use phpOMS\Utils\StringUtils;
* @link https://orange-management.org
* @since 1.0.0
*/
final class Directory extends FileAbstract implements DirectoryInterface, LocalContainerInterface
final class Directory extends FileAbstract implements DirectoryInterface
{
/**
* Directory list filter.
@ -42,7 +42,7 @@ final class Directory extends FileAbstract implements DirectoryInterface, LocalC
/**
* Directory nodes (files and directories).
*
* @var ContainerInterface[]
* @var array<string, ContainerInterface>
* @since 1.0.0
*/
private array $nodes = [];
@ -163,7 +163,12 @@ final class Directory extends FileAbstract implements DirectoryInterface, LocalC
parent::index();
foreach (\glob($this->path . \DIRECTORY_SEPARATOR . $this->filter) as $filename) {
$files = \glob($this->path . \DIRECTORY_SEPARATOR . $this->filter);
if ($files === false) {
return;
}
foreach ($files as $filename) {
if (!StringUtils::endsWith(\trim($filename), '.')) {
$file = \is_dir($filename) ? new self($filename, '*', false) : new File($filename);
@ -493,7 +498,7 @@ final class Directory extends FileAbstract implements DirectoryInterface, LocalC
/**
* {@inheritdoc}
*/
public function current()
public function current() : self
{
$current = \current($this->nodes);
@ -507,7 +512,7 @@ final class Directory extends FileAbstract implements DirectoryInterface, LocalC
/**
* {@inheritdoc}
*/
public function key()
public function key() : ?string
{
return \key($this->nodes);
}
@ -515,7 +520,7 @@ final class Directory extends FileAbstract implements DirectoryInterface, LocalC
/**
* {@inheritdoc}
*/
public function next()
public function next() : FileAbstract
{
$next = \next($this->nodes);

View File

@ -29,7 +29,7 @@ use phpOMS\System\File\PathException;
* @link https://orange-management.org
* @since 1.0.0
*/
final class File extends FileAbstract implements FileInterface, LocalContainerInterface
final class File extends FileAbstract implements FileInterface
{
/**
* Constructor.

View File

@ -14,7 +14,7 @@ declare(strict_types=1);
namespace phpOMS\System\File\Local;
use phpOMS\System\File\ContainerInterface;
use phpOMS\System\File\PathException;
/**
* Filesystem class.
@ -26,7 +26,7 @@ use phpOMS\System\File\ContainerInterface;
* @link https://orange-management.org
* @since 1.0.0
*/
abstract class FileAbstract implements ContainerInterface
abstract class FileAbstract implements LocalContainerInterface
{
/**
* Path.

View File

@ -14,6 +14,8 @@ declare(strict_types=1);
namespace phpOMS\System\File\Local;
use phpOMS\System\File\ContainerInterface;
/**
* Filesystem class.
*
@ -24,7 +26,7 @@ namespace phpOMS\System\File\Local;
* @link https://orange-management.org
* @since 1.0.0
*/
interface LocalContainerInterface
interface LocalContainerInterface extends ContainerInterface
{
/**
* Get the datetime when the resource got created.

View File

@ -17,6 +17,13 @@ namespace phpOMS\Uri;
/**
* Uri interface.
*
* @property string $scheme Scheme
* @property string $host Host
* @property int $port Port
* @property string $fragment Fragment
* @property string $user User
* @property string $pass Password
*
* @package phpOMS\Uri
* @license OMS License 1.0
* @link https://orange-management.org

View File

@ -429,7 +429,7 @@ class Repository
*/
public function createBranch(Branch $branch, bool $force = false) : string
{
return \implode("\n", $this->run('branch ' . ($force ? '-D' : '-d') . ' ' . $branch->getName()));
return \implode("\n", $this->run('branch ' . ($force ? '-D' : '-d') . ' ' . $branch->name));
}
/**
@ -497,7 +497,7 @@ class Repository
*/
public function checkout(Branch $branch) : string
{
$result = \implode("\n", $this->run('checkout ' . $branch->getName()));
$result = \implode("\n", $this->run('checkout ' . $branch->name));
$this->branch = $branch;
return $result;
@ -514,7 +514,7 @@ class Repository
*/
public function merge(Branch $branch) : string
{
return \implode("\n", $this->run('merge ' . $branch->getName() . ' --no-ff'));
return \implode("\n", $this->run('merge ' . $branch->name . ' --no-ff'));
}
/**
@ -579,7 +579,7 @@ class Repository
{
$remote = \escapeshellarg($remote);
return \implode("\n", $this->run('push --tags ' . $remote . ' ' . $branch->getName()));
return \implode("\n", $this->run('push --tags ' . $remote . ' ' . $branch->name));
}
/**
@ -596,7 +596,7 @@ class Repository
{
$remote = \escapeshellarg($remote);
return \implode("\n", $this->run('pull ' . $remote . ' ' . $branch->getName()));
return \implode("\n", $this->run('pull ' . $remote . ' ' . $branch->name));
}
/**
@ -711,7 +711,7 @@ class Repository
$author = \substr($line, \strlen($matches[0]) + 1);
$contributor = new Author($author === false ? '' : $author);
$contributor->setCommitCount($this->getCommitsCount($start, $end)[$contributor->getName()]);
$contributor->setCommitCount($this->getCommitsCount($start, $end)[$contributor->name]);
$addremove = $this->getAdditionsRemovalsByContributor($contributor, $start, $end);
$contributor->setAdditionCount($addremove['added']);
@ -781,7 +781,7 @@ class Repository
$addremove = ['added' => 0, 'removed' => 0];
$lines = $this->run(
'log --author=' . \escapeshellarg($author->getName())
'log --author=' . \escapeshellarg($author->name)
. ' --since="' . $start->format('Y-m-d')
. '" --before="' . $end->format('Y-m-d')
. '" --pretty=tformat: --numstat'
@ -833,7 +833,7 @@ class Repository
if ($author === null) {
$author = '';
} else {
$author = ' --author=' . \escapeshellarg($author->getName()) . '';
$author = ' --author=' . \escapeshellarg($author->name) . '';
}
$lines = $this->run(