From e87a75cd6d0964bfd92765e7d17f834fd3d5a235 Mon Sep 17 00:00:00 2001 From: Visman Date: Sun, 24 May 2020 18:30:48 +0700 Subject: [PATCH] Add declaration of argument types and return values --- app/Controllers/Install.php | 3 +- app/Controllers/Primary.php | 5 ++- app/Controllers/Routing.php | 4 +- app/Core/Cache.php | 10 ++--- app/Core/Cache/FileCache.php | 14 +++--- app/Core/Cache/ProviderCacheInterface.php | 10 ++--- app/Core/Container.php | 14 +++--- app/Core/Csrf.php | 8 ++-- app/Core/DB.php | 24 +++++------ app/Core/DB/mysql.php | 43 ++++++++++--------- app/Core/DBStatement.php | 6 +-- app/Core/ErrorHandler.php | 16 ++++--- app/Core/File.php | 32 +++++++------- app/Core/Files.php | 18 ++++---- app/Core/Func.php | 12 +++--- app/Core/Image.php | 12 +++--- app/Core/Lang.php | 8 ++-- app/Core/Mail.php | 49 +++++++++++---------- app/Core/Parser.php | 10 ++--- app/Core/Router.php | 24 +++++------ app/Core/Secury.php | 10 ++--- app/Core/Validator.php | 34 +++++++-------- app/Core/Validators.php | 2 +- app/Core/View.php | 2 +- app/Models/Action.php | 6 +-- app/Models/AdminList/Model.php | 4 +- app/Models/BanList/Check.php | 2 +- app/Models/BanList/Delete.php | 3 +- app/Models/BanList/Filter.php | 2 +- app/Models/BanList/GetList.php | 2 +- app/Models/BanList/Insert.php | 3 +- app/Models/BanList/IsBanned.php | 2 +- app/Models/BanList/Load.php | 3 +- app/Models/BanList/Model.php | 6 +-- app/Models/BanList/Update.php | 3 +- app/Models/Categories/Manager.php | 14 +++--- app/Models/Censorship/Load.php | 2 +- app/Models/Censorship/Model.php | 4 +- app/Models/Censorship/Refresh.php | 3 +- app/Models/Censorship/Save.php | 3 +- app/Models/Config/Install.php | 3 +- app/Models/Config/Load.php | 3 +- app/Models/Config/Model.php | 2 +- app/Models/Config/Save.php | 3 +- app/Models/Cookie/Model.php | 16 +++---- app/Models/DBMap/Model.php | 4 +- app/Models/DataModel.php | 14 +++--- app/Models/Forum/CalcStat.php | 3 +- app/Models/Forum/Delete.php | 2 +- app/Models/Forum/LoadTree.php | 7 +-- app/Models/Forum/Manager.php | 12 +++--- app/Models/Forum/Markread.php | 2 +- app/Models/Forum/Model.php | 39 ++++++++--------- app/Models/Forum/Refresh.php | 6 +-- app/Models/Forum/Save.php | 4 +- app/Models/Group/Delete.php | 2 +- app/Models/Group/Manager.php | 12 +++--- app/Models/Group/Model.php | 12 +++--- app/Models/Group/Perm.php | 10 ++--- app/Models/Group/Save.php | 4 +- app/Models/ManagerModel.php | 6 +-- app/Models/Method.php | 6 +-- app/Models/Model.php | 18 ++++---- app/Models/Online/Info.php | 3 +- app/Models/Online/Model.php | 6 +-- app/Models/Page.php | 24 +++++------ app/Models/Pages/Admin.php | 6 +-- app/Models/Pages/Admin/Bans.php | 25 +++++------ app/Models/Pages/Admin/Categories.php | 9 ++-- app/Models/Pages/Admin/Censoring.php | 5 ++- app/Models/Pages/Admin/Forums.php | 17 ++++---- app/Models/Pages/Admin/Groups.php | 19 +++++---- app/Models/Pages/Admin/Host.php | 3 +- app/Models/Pages/Admin/Index.php | 3 +- app/Models/Pages/Admin/Maintenance.php | 9 ++-- app/Models/Pages/Admin/Options.php | 5 ++- app/Models/Pages/Admin/Permissions.php | 5 ++- app/Models/Pages/Admin/Statistics.php | 5 ++- app/Models/Pages/Admin/Users.php | 7 ++- app/Models/Pages/Admin/Users/Action.php | 15 ++++--- app/Models/Pages/Admin/Users/Promote.php | 3 +- app/Models/Pages/Admin/Users/Result.php | 9 ++-- app/Models/Pages/Admin/Users/Stat.php | 5 ++- app/Models/Pages/Admin/Users/View.php | 9 ++-- app/Models/Pages/Auth.php | 14 +++--- app/Models/Pages/Ban.php | 4 +- app/Models/Pages/Debug.php | 6 +-- app/Models/Pages/Delete.php | 4 +- app/Models/Pages/Edit.php | 6 +-- app/Models/Pages/Forum.php | 2 +- app/Models/Pages/Index.php | 2 +- app/Models/Pages/Install.php | 6 +-- app/Models/Pages/Maintenance.php | 2 +- app/Models/Pages/Message.php | 3 +- app/Models/Pages/Misc.php | 2 +- app/Models/Pages/Post.php | 9 ++-- app/Models/Pages/PostFormTrait.php | 2 +- app/Models/Pages/PostValidatorTrait.php | 2 +- app/Models/Pages/Profile.php | 8 ++-- app/Models/Pages/Profile/Config.php | 5 ++- app/Models/Pages/Profile/Edit.php | 5 ++- app/Models/Pages/Profile/Email.php | 7 +-- app/Models/Pages/Profile/Mod.php | 7 +-- app/Models/Pages/Profile/Pass.php | 5 ++- app/Models/Pages/Profile/View.php | 5 ++- app/Models/Pages/Redirect.php | 12 +++--- app/Models/Pages/Register.php | 8 ++-- app/Models/Pages/Report.php | 6 +-- app/Models/Pages/Rules.php | 6 +-- app/Models/Pages/Search.php | 16 +++---- app/Models/Pages/Topic.php | 14 +++--- app/Models/Pages/Userlist.php | 8 ++-- app/Models/Post/Delete.php | 2 +- app/Models/Post/Load.php | 9 ++-- app/Models/Post/Manager.php | 22 +++++----- app/Models/Post/Model.php | 25 +++++------ app/Models/Post/PreviousPost.php | 6 +-- app/Models/Post/RebuildIndex.php | 2 +- app/Models/Post/Save.php | 4 +- app/Models/Post/UserInfoFromIP.php | 2 +- app/Models/Post/UserStat.php | 2 +- app/Models/Post/View.php | 6 +-- app/Models/Report/Manager.php | 10 ++--- app/Models/Report/Model.php | 8 ++-- app/Models/Report/Save.php | 4 +- app/Models/Rules.php | 2 +- app/Models/Rules/Profile.php | 34 +++++++-------- app/Models/Rules/Users.php | 16 +++---- app/Models/Search/ActionP.php | 2 +- app/Models/Search/ActionT.php | 2 +- app/Models/Search/Delete.php | 2 +- app/Models/Search/Execute.php | 6 +-- app/Models/Search/Index.php | 4 +- app/Models/Search/Model.php | 12 +++--- app/Models/Search/Prepare.php | 6 +-- app/Models/Search/TruncateIndex.php | 2 +- app/Models/SmileyList/Load.php | 3 +- app/Models/SmileyList/Model.php | 2 +- app/Models/Stats/Model.php | 4 +- app/Models/Stopwords/Model.php | 6 +-- app/Models/Topic/CalcStat.php | 3 +- app/Models/Topic/Delete.php | 2 +- app/Models/Topic/Load.php | 2 +- app/Models/Topic/Manager.php | 8 ++-- app/Models/Topic/Model.php | 37 ++++++++-------- app/Models/Topic/Save.php | 4 +- app/Models/Topic/View.php | 2 +- app/Models/User/AdminsIds.php | 2 +- app/Models/User/ChangeGroup.php | 2 +- app/Models/User/Current.php | 13 +++--- app/Models/User/Delete.php | 2 +- app/Models/User/Filter.php | 2 +- app/Models/User/IsUniqueName.php | 2 +- app/Models/User/Manager.php | 6 +-- app/Models/User/Model.php | 52 +++++++++++------------ app/Models/User/Promote.php | 2 +- app/Models/User/Save.php | 4 +- app/Models/User/Stats.php | 2 +- app/Models/User/UpdateCountPosts.php | 2 +- app/Models/User/UpdateCountTopics.php | 2 +- app/Models/User/UpdateLastVisit.php | 4 +- app/Models/User/UsersNumber.php | 2 +- app/Models/Validators/Email.php | 2 +- app/Models/Validators/Username.php | 2 +- app/functions.php | 48 +++++++++++---------- 165 files changed, 729 insertions(+), 675 deletions(-) diff --git a/app/Controllers/Install.php b/app/Controllers/Install.php index f07d1b6c..7def6e9d 100644 --- a/app/Controllers/Install.php +++ b/app/Controllers/Install.php @@ -3,6 +3,7 @@ namespace ForkBB\Controllers; use ForkBB\Core\Container; +use ForkBB\Models\Page; class Install { @@ -27,7 +28,7 @@ class Install * * @return Page */ - public function routing() + public function routing(): Page { $uri = $_SERVER['REQUEST_URI']; if (($pos = \strpos($uri, '?')) !== false) { diff --git a/app/Controllers/Primary.php b/app/Controllers/Primary.php index 05840bc4..d797b7a2 100644 --- a/app/Controllers/Primary.php +++ b/app/Controllers/Primary.php @@ -3,6 +3,7 @@ namespace ForkBB\Controllers; use ForkBB\Core\Container; +use ForkBB\Models\Page; class Primary { @@ -29,7 +30,7 @@ class Primary * * @return Page|null */ - public function check() + public function check(): ?Page { if ($this->c->config->o_maintenance && ! $this->c->MAINTENANCE_OFF) { if (! isset($this->c->admins->list[$this->c->Cookie->uId]) @@ -50,5 +51,7 @@ class Primary if (! $this->c->user->isAdmin && $this->c->bans->check($this->c->user)) { return $this->c->Ban->ban($this->c->user); } + + return null; } } diff --git a/app/Controllers/Routing.php b/app/Controllers/Routing.php index 96110998..8f82e5c0 100644 --- a/app/Controllers/Routing.php +++ b/app/Controllers/Routing.php @@ -3,12 +3,14 @@ namespace ForkBB\Controllers; use ForkBB\Core\Container; +use ForkBB\Models\Page; class Routing { const DUO = ['GET', 'POST']; const GET = 'GET'; const PST = 'POST'; + /** * Контейнер * @var Container @@ -30,7 +32,7 @@ class Routing * * @return Page */ - public function routing() + public function routing(): Page { $user = $this->c->user; $config = $this->c->config; diff --git a/app/Core/Cache.php b/app/Core/Cache.php index f3f0e1c3..032ded67 100644 --- a/app/Core/Cache.php +++ b/app/Core/Cache.php @@ -30,7 +30,7 @@ class Cache * * @return mixed */ - public function get($key, $default = null) + public function get(string $key, $default = null) { return $this->provider->get($key, $default); } @@ -44,7 +44,7 @@ class Cache * * @return bool */ - public function set($key, $value, $ttl = null) + public function set(string $key, $value, int $ttl = null): bool { return $this->provider->set($key, $value, $ttl); } @@ -56,7 +56,7 @@ class Cache * * @return bool */ - public function delete($key) + public function delete(striing $key): bool { return $this->provider->delete($key); } @@ -66,7 +66,7 @@ class Cache * * @return bool */ - public function clear() + public function clear(): bool { return $this->provider->clear(); } @@ -78,7 +78,7 @@ class Cache * * @return bool */ - public function has($key) + public function has(string $key): bool { return $this->provider->has($key); } diff --git a/app/Core/Cache/FileCache.php b/app/Core/Cache/FileCache.php index 90560877..266864a3 100644 --- a/app/Core/Cache/FileCache.php +++ b/app/Core/Cache/FileCache.php @@ -44,7 +44,7 @@ class FileCache implements ProviderCacheInterface * * @return mixed */ - public function get($key, $default = null) + public function get(string $key, $default = null) { $file = $this->file($key); if (\is_file($file)) { @@ -68,7 +68,7 @@ class FileCache implements ProviderCacheInterface * * @return bool */ - public function set($key, $value, $ttl = null) + public function set(string $key, $value, int $ttl = null): bool { $file = $this->file($key); $expire = null === $ttl || $ttl < 1 ? 0 : \time() + $ttl; @@ -90,7 +90,7 @@ class FileCache implements ProviderCacheInterface * * @return bool */ - public function delete($key) + public function delete(string $key): bool { $file = $this->file($key); if (\is_file($file)) { @@ -110,7 +110,7 @@ class FileCache implements ProviderCacheInterface * * @return bool */ - public function clear() + public function clear(): bool { $dir = new RecursiveDirectoryIterator($this->cacheDir, RecursiveDirectoryIterator::SKIP_DOTS); $iterator = new RecursiveIteratorIterator($dir); @@ -130,7 +130,7 @@ class FileCache implements ProviderCacheInterface * * @return bool */ - public function has($key) + public function has(string $key): bool { return null !== $this->get($key); } @@ -144,7 +144,7 @@ class FileCache implements ProviderCacheInterface * * @return string */ - protected function file($key) + protected function file(string $key): string { if (\is_string($key) && \preg_match('%^[a-z0-9_-]+$%Di', $key)) { return $this->cacheDir . '/cache_' . $key . '.php'; @@ -157,7 +157,7 @@ class FileCache implements ProviderCacheInterface * * @param string $file */ - protected function invalidate($file) + protected function invalidate(string $file): void { if (\function_exists('\\opcache_invalidate')) { \opcache_invalidate($file, true); diff --git a/app/Core/Cache/ProviderCacheInterface.php b/app/Core/Cache/ProviderCacheInterface.php index ecd3ab99..abf27fe0 100644 --- a/app/Core/Cache/ProviderCacheInterface.php +++ b/app/Core/Cache/ProviderCacheInterface.php @@ -12,7 +12,7 @@ interface ProviderCacheInterface * * @return mixed */ - public function get($key, $default = null); + public function get(string $key, $default = null); /** * Установка данных в кэш по ключу @@ -23,7 +23,7 @@ interface ProviderCacheInterface * * @return bool */ - public function set($key, $value, $ttl = null); + public function set(string $key, $value, int $ttl = null): bool; /** * Удаление данных по ключу @@ -32,14 +32,14 @@ interface ProviderCacheInterface * * @return bool */ - public function delete($key); + public function delete(string $key): bool; /** * Очистка кэша * * @return bool */ - public function clear(); + public function clear(): bool; /** * Проверка наличия ключа @@ -48,5 +48,5 @@ interface ProviderCacheInterface * * @return bool */ - public function has($key); + public function has(string $key): bool; } diff --git a/app/Core/Container.php b/app/Core/Container.php index 0b4caefa..581d0270 100644 --- a/app/Core/Container.php +++ b/app/Core/Container.php @@ -41,7 +41,7 @@ class Container * * @param array config */ - public function config(array $config) + public function config(array $config): void { if (isset($config['shared'])) { $this->shared = \array_replace_recursive($this->shared, $config['shared']); @@ -62,7 +62,7 @@ class Container * * @return mixed */ - public function __get($id) + public function __get(string $id) { if (isset($this->instances[$id]) || \array_key_exists($id, $this->instances)) { //???? return $this->instances[$id]; @@ -116,7 +116,7 @@ class Container * @param string $id * @param mixed $service */ - public function __set($id, $service) + public function __set(string $id, $service): void { if (\strpos($id, '.') !== false) { //???? @@ -135,10 +135,10 @@ class Container */ public function fromArray(array $array, array $tree) { - $ptr = & $array; + $ptr = &$array; foreach ($tree as $s) { if (isset($ptr[$s])) { - $ptr = & $ptr[$s]; + $ptr = &$ptr[$s]; } else { return null; } @@ -157,7 +157,7 @@ class Container * * @return ContainerInterface Self reference */ - public function setParameter($name, $value) + public function setParameter(string $name, $value): self { $segments = \explode('.', $name); $n = \count($segments); @@ -212,7 +212,7 @@ class Container * * @return bool */ - public function isInit($name) + public function isInit(string $name): bool { return \array_key_exists($name, $this->instances); } diff --git a/app/Core/Csrf.php b/app/Core/Csrf.php index 440b80c2..e488eef2 100644 --- a/app/Core/Csrf.php +++ b/app/Core/Csrf.php @@ -20,9 +20,9 @@ class Csrf * Конструктор * * @param Secury $secury - * @param User $user + * @param string $key */ - public function __construct(Secury $secury, $key) + public function __construct(Secury $secury, string $key) { $this->secury = $secury; $this->key = \sha1($key); @@ -37,7 +37,7 @@ class Csrf * * @return string */ - public function create($marker, array $args = [], $time = null) + public function create(string $marker, array $args = [], $time = null): string { unset($args['token'], $args['#']); \ksort($args); @@ -58,7 +58,7 @@ class Csrf * * @return bool */ - public function verify($token, $marker, array $args = []) + public function verify($token, string $marker, array $args = []): bool { return \is_string($token) && \preg_match('%f(\d+)$%D', $token, $matches) diff --git a/app/Core/DB.php b/app/Core/DB.php index 0b3fc493..31ca5408 100644 --- a/app/Core/DB.php +++ b/app/Core/DB.php @@ -56,7 +56,7 @@ class DB extends PDO * * @throws PDOException */ - public function __construct($dsn, $username = null, $password = null, array $options = [], $prefix = '') + public function __construct(string $dsn, string $username = null, string $password = null, array $options = [], string $prefix = '') { $type = \strstr($dsn, ':', true); if ( @@ -89,7 +89,7 @@ class DB extends PDO * * @return mixed */ - public function __call($name, array $args) + public function __call(string $name, array $args) { if (empty($this->dbDrv)) { $drv = 'ForkBB\\Core\\DB\\' . \ucfirst($this->dbType); @@ -105,7 +105,7 @@ class DB extends PDO * * @return bool */ - protected function isOptions(array $arr) + protected function isOptions(array $arr): bool { $verify = [self::ATTR_CURSOR => [self::CURSOR_FWDONLY, self::CURSOR_SCROLL]]; @@ -127,7 +127,7 @@ class DB extends PDO * * @return array */ - protected function parse(&$query, array $params) + protected function parse(string &$query, array $params): array { $idxIn = 0; $idxOut = 1; @@ -214,7 +214,7 @@ class DB extends PDO * * @return int */ - public function getCount() + public function getCount(): int { return $this->qCount; } @@ -224,7 +224,7 @@ class DB extends PDO * * @return array */ - public function getQueries() + public function getQueries(): array { return $this->queries; } @@ -236,7 +236,7 @@ class DB extends PDO * @param float $time * @param bool $add */ - public function saveQuery($query, $time, $add = true) + public function saveQuery(string $query, float $time, bool $add = true): void { if ($add) { ++$this->qCount; @@ -286,7 +286,7 @@ class DB extends PDO * * @return PDOStatement */ - public function prepare($query, $arg1 = null, $arg2 = null) + public function prepare($query, $arg1 = null, $arg2 = null): PDOStatement { if (empty($arg1) === empty($arg2) || ! empty($arg2)) { $params = $arg1; @@ -320,7 +320,7 @@ class DB extends PDO * * @return PDOStatement|false */ - public function query($query, ...$args) + public function query(string $query, ...$args) { if (isset($args[0]) && \is_array($args[0])) { $params = \array_shift($args); @@ -357,7 +357,7 @@ class DB extends PDO /** * @return bool */ - public function beginTransaction() + public function beginTransaction(): bool { $start = \microtime(true); $result = parent::beginTransaction(); @@ -368,7 +368,7 @@ class DB extends PDO /** * @return bool */ - public function commit() + public function commit(): bool { $start = \microtime(true); $result = parent::commit(); @@ -379,7 +379,7 @@ class DB extends PDO /** * @return bool */ - public function rollback() + public function rollback(): bool { $start = \microtime(true); $result = parent::rollback(); diff --git a/app/Core/DB/mysql.php b/app/Core/DB/mysql.php index 4d83cdf0..ccfee04b 100644 --- a/app/Core/DB/mysql.php +++ b/app/Core/DB/mysql.php @@ -67,7 +67,7 @@ class Mysql * * @throws PDOException */ - public function __call($name, array $args) + public function __call(string $name, array $args) { throw new PDOException("Method '{$name}' not found in DB driver."); } @@ -79,7 +79,7 @@ class Mysql * * @throws PDOException */ - protected function testStr($str) + protected function testStr(string $str): void { if (! \is_string($str) || \preg_match('%[^a-zA-Z0-9_]%', $str)) { throw new PDOException("Name '{$str}' have bad characters."); @@ -93,7 +93,7 @@ class Mysql * * @return string */ - protected function replIdxs(array $arr) + protected function replIdxs(array $arr): string { foreach ($arr as &$value) { if (\preg_match('%^(.*)\s*(\(\d+\))$%', $value, $matches)) { @@ -115,7 +115,7 @@ class Mysql * * @return string */ - protected function replType($type) + protected function replType(string $type): string { return \preg_replace(\array_keys($this->dbTypeRepl), \array_values($this->dbTypeRepl), $type); } @@ -129,7 +129,8 @@ class Mysql * * @return string */ - protected function convToStr($data) { + protected function convToStr($data): string + { if (\is_string($data)) { return $this->db->quote($data); } elseif (\is_numeric($data)) { @@ -149,7 +150,7 @@ class Mysql * * @return bool */ - public function tableExists($table, $noPrefix = false) + public function tableExists(string $table, bool $noPrefix = false): bool { $table = ($noPrefix ? '' : $this->dbPrefix) . $table; try { @@ -171,7 +172,7 @@ class Mysql * * @return bool */ - public function fieldExists($table, $field, $noPrefix = false) + public function fieldExists(string $table, string $field, bool $noPrefix = false): bool { $table = ($noPrefix ? '' : $this->dbPrefix) . $table; try { @@ -193,7 +194,7 @@ class Mysql * * @return bool */ - public function indexExists($table, $index, $noPrefix = false) + public function indexExists(string $table, string $index, bool $noPrefix = false): bool { $table = ($noPrefix ? '' : $this->dbPrefix) . $table; $index = $index == 'PRIMARY' ? $index : $table . '_' . $index; @@ -216,7 +217,7 @@ class Mysql * * @return bool */ - public function createTable($table, array $schema, $noPrefix = false) + public function createTable(string $table, array $schema, bool $noPrefix = false): bool { $table = ($noPrefix ? '' : $this->dbPrefix) . $table; $this->testStr($table); @@ -297,7 +298,7 @@ class Mysql * * @return bool */ - public function dropTable($table, $noPrefix = false) + public function dropTable(string $table, bool $noPrefix = false): bool { $table = ($noPrefix ? '' : $this->dbPrefix) . $table; $this->testStr($table); @@ -313,7 +314,7 @@ class Mysql * * @return bool */ - public function renameTable($old, $new, $noPrefix = false) + public function renameTable(string $old, string $new, bool $noPrefix = false): bool { if ($this->tableExists($new, $noPrefix) && ! $this->tableExists($old, $noPrefix)) { return true; @@ -330,6 +331,7 @@ class Mysql * * @param string $table * @param string $field + * @param string $type * @param bool $allowNull * @param mixed $default * @param string $after @@ -337,7 +339,7 @@ class Mysql * * @return bool */ - public function addField($table, $field, $type, $allowNull, $default = null, $after = null, $noPrefix = false) + public function addField(string $table, string $field, string $type, bool $allowNull, $default = null, string $after = null, bool $noPrefix = false): bool { if ($this->fieldExists($table, $field, $noPrefix)) { return true; @@ -364,6 +366,7 @@ class Mysql * * @param string $table * @param string $field + * @param string $type * @param bool $allowNull * @param mixed $default * @param string $after @@ -371,7 +374,7 @@ class Mysql * * @return bool */ - public function alterField($table, $field, $type, $allowNull, $default = null, $after = null, $noPrefix = false) + public function alterField(string $table, string $field, string $type, bool $allowNull, $default = null, string $after = null, bool $noPrefix = false): bool { $table = ($noPrefix ? '' : $this->dbPrefix) . $table; $this->testStr($table); @@ -399,7 +402,7 @@ class Mysql * * @return bool */ - public function dropField($table, $field, $noPrefix = false) + public function dropField(string $table, string $field, bool $noPrefix = false): bool { if (! $this->fieldExists($table, $field, $noPrefix)) { return true; @@ -421,7 +424,7 @@ class Mysql * * @return bool */ - public function addIndex($table, $index, array $fields, $unique = false, $noPrefix = false) + public function addIndex(string $table, string $index, array $fields, bool $unique = false, bool $noPrefix = false): bool { if ($this->indexExists($table, $index, $noPrefix)) { return true; @@ -453,7 +456,7 @@ class Mysql * * @return bool */ - public function dropIndex($table, $index, $noPrefix = false) + public function dropIndex(string $table, string $index, bool $noPrefix = false): bool { if (! $this->indexExists($table, $index, $noPrefix)) { return true; @@ -479,7 +482,7 @@ class Mysql * * @return bool */ - public function truncateTable($table, $noPrefix = false) + public function truncateTable(string $table, bool $noPrefix = false): bool { $table = ($noPrefix ? '' : $this->dbPrefix) . $table; $this->testStr($table); @@ -489,9 +492,9 @@ class Mysql /** * Статистика * - * @return array|string + * @return array */ - public function statistics() + public function statistics(): array { $this->testStr($this->dbPrefix); $prefix = str_replace('_', '\\_', $this->dbPrefix); @@ -532,7 +535,7 @@ class Mysql * * @return array */ - public function getMap() + public function getMap(): array { $stmt = $this->db->query('SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME LIKE ?s', ["{$this->dbPrefix}%"]); $result = []; diff --git a/app/Core/DBStatement.php b/app/Core/DBStatement.php index ba257dd7..053ca7b1 100644 --- a/app/Core/DBStatement.php +++ b/app/Core/DBStatement.php @@ -49,7 +49,7 @@ class DBStatement extends PDOStatement * * @param array $map */ - public function setMap(array $map) + public function setMap(array $map): void { $this->map = $map; } @@ -61,7 +61,7 @@ class DBStatement extends PDOStatement * * @throws PDOException */ - public function bindValueList(array $params) + public function bindValueList(array $params): void { foreach ($this->map as $key => $data) { $type = \array_shift($data); @@ -90,7 +90,7 @@ class DBStatement extends PDOStatement * * @return bool */ - public function execute($params = null) + public function execute($params = null): bool { if (\is_array($params) && ! empty($params)) { $this->bindValueList($params); diff --git a/app/Core/ErrorHandler.php b/app/Core/ErrorHandler.php index edffa52e..c334fb08 100644 --- a/app/Core/ErrorHandler.php +++ b/app/Core/ErrorHandler.php @@ -2,6 +2,8 @@ namespace ForkBB\Core; +use Throwable; + class ErrorHandler { /** @@ -87,7 +89,7 @@ class ErrorHandler * * @return bool */ - public function errorHandler($type, $message, $file, $line) + public function errorHandler(int $type, string $message, string $file, string $line): bool { $error = [ 'type' => $type, @@ -112,7 +114,7 @@ class ErrorHandler * * @param Exception|Throwable $e */ - public function exceptionHandler($e) + public function exceptionHandler(Throwable $e): void { $this->error = [ 'type' => 0, //???? @@ -126,7 +128,7 @@ class ErrorHandler /** * Окончательно обрабатывает ошибки (в том числе фатальные) и исключения */ - public function shutdownHandler() + public function shutdownHandler(): void { if (isset($this->error['type'])) { $show = true; @@ -171,7 +173,7 @@ class ErrorHandler * * @param array $error */ - protected function log(array $error) + protected function log(array $error): void { $this->logged = true; $message = \preg_replace('%[\x00-\x1F]%', ' ', $this->message($error)); @@ -184,7 +186,7 @@ class ErrorHandler * * @param array $error */ - protected function show(array $error) + protected function show(array $error): void { \header('HTTP/1.1 500 Internal Server Error'); @@ -274,7 +276,7 @@ EOT; * * @return string */ - protected function message(array $error) + protected function message(array $error): string { $type = isset($this->type[$error['type']]) ? $this->type[$error['type']] : $this->type[0]; $file = \str_replace($this->hidePath, '...', $error['file']); @@ -288,7 +290,7 @@ EOT; * * @return string */ - protected function e($arg) + protected function e(string $arg): string { return \htmlspecialchars($arg, \ENT_HTML5 | \ENT_QUOTES | \ENT_SUBSTITUTE, 'UTF-8'); } diff --git a/app/Core/File.php b/app/Core/File.php index 33943baa..5a2fcdc8 100644 --- a/app/Core/File.php +++ b/app/Core/File.php @@ -105,7 +105,7 @@ class File * * @return null|string */ - public function error() + public function error(): ?string { return $this->error; } @@ -117,7 +117,7 @@ class File * * @return string */ - protected function filterName($name) + protected function filterName(string $name): string { if (\function_exists('\\transliterator_transliterate')) { $name = \transliterator_transliterate("Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove; Lower();", $name); @@ -137,13 +137,13 @@ class File * * @param string $path * - * @return false|array + * @return null|array */ - protected function pathinfo($path) + protected function pathinfo(string $path): ?array { if (! \preg_match($this->pattern, $path, $matches)) { $this->error = 'The path/name format is broken'; - return false; + return null; } if ('*' === $matches[2]) { @@ -152,7 +152,7 @@ class File if ('*' === $matches[3]) { $matches[3] = $this->ext; - } elseif ('(' === $matches[3]{0} && ')' === $matches[3]{\strlen($matches[3]) - 1}) { + } elseif ('(' === $matches[3][0] && ')' === $matches[3][\strlen($matches[3]) - 1]) { $matches[3] = \explode('|', \substr($matches[3], 1, -1)); if (1 === \count($matches[3])) { @@ -174,7 +174,7 @@ class File * * @return File */ - public function rename($rename) + public function rename(bool $rename): self { $this->rename = $rename; @@ -188,7 +188,7 @@ class File * * @return File */ - public function rewrite($rewrite) + public function rewrite(bool $rewrite): self { $this->rewrite = $rewrite; @@ -202,7 +202,7 @@ class File * * @return bool */ - protected function dirProc($dirname) + protected function dirProc(string $dirname): bool { if (! \is_dir($dirname)) { if (! @\mkdir($dirname, 0755)) { @@ -225,7 +225,7 @@ class File * * @return bool */ - protected function fileProc($path) + protected function fileProc(string $path): bool { if (\is_string($this->data)) { if (! \file_put_contents($this->path, $path)) { @@ -250,11 +250,11 @@ class File * * @return bool */ - public function toFile($path) + public function toFile(string $path): bool { $info = $this->pathinfo($path); - if (false === $info || ! $this->dirProc($info['dirname'])) { + if (null === $info || ! $this->dirProc($info['dirname'])) { return false; } @@ -283,22 +283,22 @@ class File } } - public function name() + public function name(): string { return $this->name; } - public function ext() + public function ext(): string { return $this->ext; } - public function size() + public function size(): int { return $this->size; } - public function path() + public function path(): string { return $this->path; } diff --git a/app/Core/Files.php b/app/Core/Files.php index dcbd2ccd..5c5c5e73 100644 --- a/app/Core/Files.php +++ b/app/Core/Files.php @@ -88,7 +88,7 @@ class Files * * @return int */ - public function maxImgSize($unit = null) + public function maxImgSize(string $unit = null): int { return $this->size($this->maxImgSize, $unit); } @@ -100,7 +100,7 @@ class Files * * @return int */ - public function maxFileSize($unit = null) + public function maxFileSize(string $unit = null): int { return $this->size($this->maxFileSize, $unit); } @@ -116,7 +116,7 @@ class Files * * @return int|float */ - public function size($value, $to = null) + public function size($value, string $to = null) { if (\is_string($value)) { if (! \preg_match('%^([^a-z]+)([a-z]+)?$%i', \trim($value), $matches)) { @@ -160,7 +160,7 @@ class Files * * @return null|string */ - public function error() + public function error(): ?string { return $this->error; } @@ -170,9 +170,9 @@ class Files * * @param mixed $file * - * @return false|string + * @return string|null */ - public function isImage($file) + public function isImage($file): ?string { if (\is_string($file)) { if (\function_exists('\\exif_imagetype')) { @@ -187,10 +187,10 @@ class Files } else { $type = 0; } - return isset($this->imageType[$type]) ? $this->imageType[$type] : false; + return isset($this->imageType[$type]) ? $this->imageType[$type] : null; } - return $file instanceof Image ? $file->ext() : false; + return $file instanceof Image ? $file->ext() : null; } /** @@ -291,7 +291,7 @@ class Files $isImage = $this->isImage($file['tmp_name']); - if (false !== $isImage) { + if (null !== $isImage) { $ext = $isImage; $isImage = 'swf' !== $isImage; // флеш не будет картинкой } diff --git a/app/Core/Func.php b/app/Core/Func.php index 2a88b5a2..4da94c28 100644 --- a/app/Core/Func.php +++ b/app/Core/Func.php @@ -45,7 +45,7 @@ class Func * * @return array */ - public function getStyles() + public function getStyles(): array { if (! \is_array($this->styles)) { $this->styles = $this->getFoldersWithFile($this->c->DIR_PUBLIC . '/style', 'style.css'); @@ -58,7 +58,7 @@ class Func * * @return array */ - public function getLangs() + public function getLangs(): array { if (! \is_array($this->langs)) { $this->langs = $this->getFoldersWithFile($this->c->DIR_LANG, 'common.po'); @@ -71,7 +71,7 @@ class Func * * @return array */ - public function getNameLangs() + public function getNameLangs(): array { if (! \is_array($this->nameLangs)) { $langs = $this->getLangs(); @@ -93,7 +93,7 @@ class Func * * @return array */ - public function getFoldersWithFile($dir, $file) + public function getFoldersWithFile(string $dir, string $file): array { $result = []; if (\is_dir($dir) && ($dh = \opendir($dir)) !== false) { @@ -123,7 +123,7 @@ class Func * * @return array */ - public function paginate($all, $cur, $marker, array $args = [], $info = 'Page %1$s of %2$s') + public function paginate(int $all, int $cur, string $marker, array $args = [], string $info = 'Page %1$s of %2$s'): array { $pages = []; if ($all < 2) { @@ -173,7 +173,7 @@ class Func * * @return array */ - public function langParse($str) + public function langParse(string $str): array { $result = []; diff --git a/app/Core/Image.php b/app/Core/Image.php index 0d520d31..94ffdbfa 100644 --- a/app/Core/Image.php +++ b/app/Core/Image.php @@ -64,7 +64,7 @@ class Image extends File * * @return Image */ - public function resize($maxW, $maxH) + public function resize(int $maxW, int $maxH): self { $oldW = \imagesx($this->image); $oldH = \imagesy($this->image); @@ -105,14 +105,14 @@ class Image extends File * * @param string $path * - * @return false|array + * @return null|array */ - protected function pathinfo($path) + protected function pathinfo(string $path): ?array { $info = parent::pathinfo($path); - if (false === $info) { - return false; + if (null === $info) { + return null; } if (\is_array($info['extension'])) { @@ -133,7 +133,7 @@ class Image extends File * * @return bool */ - protected function fileProc($path) + protected function fileProc(string $path): bool { switch (\pathinfo($path, \PATHINFO_EXTENSION)) { case 'jpg': diff --git a/app/Core/Lang.php b/app/Core/Lang.php index 82b7b3e4..4efac941 100644 --- a/app/Core/Lang.php +++ b/app/Core/Lang.php @@ -43,7 +43,7 @@ class Lang * * @return string|array */ - public function get($message, $lang = null) + public function get(string $message, string $lang = null) { if ($lang && isset($this->tr[$lang][$message])) { return $this->tr[$lang][$message]; @@ -65,7 +65,7 @@ class Lang * @param string $lang * @param string $path */ - public function load($name, $lang = null, $path = null) + public function load(string $name, string $lang = null, string $path = null): void { if ($lang) { if (isset($this->loaded[$name][$lang])) { @@ -105,7 +105,7 @@ class Lang * * @return array */ - protected function arrayFromStr($str) + protected function arrayFromStr(string $str): array { $lines = \explode("\n", $str); $count = \count($lines); @@ -253,7 +253,7 @@ class Lang * * @return string */ - protected function originalLine($line) + protected function originalLine(string $line): string { if (isset($line[1]) && $line[0] == '"' && $line[\strlen($line) - 1] == '"') { $line = \substr($line, 1, -1); diff --git a/app/Core/Mail.php b/app/Core/Mail.php index 87c5acfe..b2425601 100644 --- a/app/Core/Mail.php +++ b/app/Core/Mail.php @@ -89,7 +89,7 @@ class Mail * * @return false|string */ - public function valid($email, $strict = false, $idna = false) + public function valid($email, bool $strict = false, bool $idna = false) { if (! \is_string($email) || \mb_strlen($email, 'UTF-8') > 80 //???? for DB @@ -148,7 +148,7 @@ class Mail * * @return Mail */ - public function reset() + public function reset(): self { $this->to = []; $this->headers = []; @@ -163,7 +163,7 @@ class Mail * * @return Mail */ - public function setSubject($subject) + public function setSubject(string $subject): self { $this->headers['Subject'] = $this->encodeText(\preg_replace('%[\x00-\x1F]%', '', \trim($subject))); return $this; @@ -177,10 +177,9 @@ class Mail * * @return Mail */ - public function addTo($email, $name = null) + public function addTo($email, string $name = null): self { - if (\is_array($email)) { - } else { + if (! \is_array($email)) { $email = \preg_split('%[,\n\r]%', (string) $email, -1, PREG_SPLIT_NO_EMPTY); } foreach($email as $cur) { @@ -200,7 +199,7 @@ class Mail * * @return Mail */ - public function setTo($email, $name = null) + public function setTo($email, string $name = null): self { $this->to = []; return $this->addTo($email, $name); @@ -214,7 +213,7 @@ class Mail * * @return Mail */ - public function setFrom($email, $name = null) + public function setFrom(string $email, string $name = null): self { $email = $this->valid($email, false, true); if (false !== $email) { @@ -231,7 +230,7 @@ class Mail * * @return Mail */ - public function setReplyTo($email, $name = null) + public function setReplyTo(string $email, string $name = null): self { $email = $this->valid($email, false, true); if (false !== $email) { @@ -248,7 +247,7 @@ class Mail * * @return string */ - protected function formatAddress($email, $name = null) + protected function formatAddress($email, string $name = null): string { if (! \is_string($name) || \strlen(\trim($name)) == 0) { return $email; @@ -265,7 +264,7 @@ class Mail * * @return string */ - protected function encodeText($str) + protected function encodeText(string $str): string { if (\preg_match('%[^\x20-\x7F]%', $str)) { return '=?UTF-8?B?' . \base64_encode($str) . '?='; @@ -281,7 +280,7 @@ class Mail * * @return string */ - protected function filterName($name) + protected function filterName(string $name): string { return \addcslashes(\preg_replace('%[\x00-\x1F]%', '', \trim($name)), '\\"'); } @@ -293,7 +292,7 @@ class Mail * * @return Mail */ - public function setFolder($folder) + public function setFolder(string $folder): self { $this->folder = $folder; return $this; @@ -306,7 +305,7 @@ class Mail * * @return Mail */ - public function setLanguage($language) + public function setLanguage(string $language): self { $this->language = $language; return $this; @@ -322,7 +321,7 @@ class Mail * * @return Mail */ - public function setTpl($tpl, array $data) + public function setTpl(string $tpl, array $data): self { $file = \rtrim($this->folder, '\\/') . '/' . $this->language . '/mail/' . $tpl; if (! \is_file($file)) { @@ -347,7 +346,7 @@ class Mail * * @return Mail */ - public function setMessage($message) + public function setMessage(string $message): self { $this->message = \str_replace("\0", $this->EOL, \str_replace(["\r\n", "\n", "\r"], "\0", @@ -363,7 +362,7 @@ class Mail * * @return bool */ - public function send() + public function send(): bool { if (empty($this->to)) { throw new MailException('No recipient for the email.'); @@ -398,7 +397,7 @@ class Mail * * @return bool */ - protected function mail() + protected function mail(): bool { $to = \implode(', ', $this->to); $subject = $this->headers['Subject']; @@ -415,7 +414,7 @@ class Mail * * @return string */ - protected function strHeaders(array $headers) + protected function strHeaders(array $headers): string { foreach ($headers as $key => &$value) { $value = $key . ': ' . $value; @@ -431,7 +430,7 @@ class Mail * * @return bool */ - protected function smtp() + protected function smtp(): bool { // подлючение if (! \is_resource($this->connect)) { @@ -461,7 +460,7 @@ class Mail /** * Hello SMTP server */ - protected function smtpHello() + protected function smtpHello(): void { switch ($this->auth) { case 1: @@ -496,9 +495,9 @@ class Mail * * @return string */ - protected function smtpData($data, $code) + protected function smtpData(string $data, $code): string { - if (\is_resource($this->connect) && \is_string($data)) { + if (\is_resource($this->connect)) { if (@\fwrite($this->connect, $data . $this->EOL) === false) { throw new SmtpException('Couldn\'t send data to mail server.'); } @@ -527,7 +526,7 @@ class Mail * * @return string */ - protected function getEmailFrom($str) + protected function getEmailFrom(string $str): string { $match = \explode('" <', $str); if (\count($match) == 2 && \substr($match[1], -1) == '>') { @@ -542,7 +541,7 @@ class Mail * * @return string */ - protected function hostname() + protected function hostname(): string { return empty($_SERVER['SERVER_NAME']) ? (isset($_SERVER['SERVER_ADDR']) ? '[' . $_SERVER['SERVER_ADDR'] . ']' : '[127.0.0.1]') diff --git a/app/Core/Parser.php b/app/Core/Parser.php index a8ef6d8f..d313c62e 100644 --- a/app/Core/Parser.php +++ b/app/Core/Parser.php @@ -29,7 +29,7 @@ class Parser extends Parserus /** * Инициализация данных */ - protected function init() + protected function init(): void { if ($this->c->config->p_message_bbcode == '1' || $this->c->config->p_sig_bbcode == '1') { $bbcodes = include $this->c->DIR_CONFIG . '/defaultBBCode.php'; @@ -63,7 +63,7 @@ class Parser extends Parserus * * @return Parser */ - public function addBBCode(array $bb) + public function addBBCode(array $bb): self { if ($bb['tag'] == 'quote') { $bb['self nesting'] = (int) $this->c->config->o_quote_depth; @@ -81,7 +81,7 @@ class Parser extends Parserus * * @return string */ - public function prepare($text, $isSignature = false) + public function prepare(string $text, bool $isSignature = false): string { if ($isSignature) { $whiteList = $this->c->config->p_sig_bbcode == '1' ? $this->c->BBCODE_INFO['forSign'] : []; @@ -112,7 +112,7 @@ class Parser extends Parserus * * @return string */ - public function parseMessage($text = null, $hideSmilies = false) + public function parseMessage(string $text = null, bool $hideSmilies = false): string { // при null предполагается брать данные после prepare() if (null !== $text) { @@ -139,7 +139,7 @@ class Parser extends Parserus * * @return string */ - public function parseSignature($text = null) + public function parseSignature(string $text = null): string { // при null предполагается брать данные после prepare() if (null !== $text) { diff --git a/app/Core/Router.php b/app/Core/Router.php index 734c6d39..77b851bd 100644 --- a/app/Core/Router.php +++ b/app/Core/Router.php @@ -91,7 +91,7 @@ class Router * * @return string */ - public function validate($url, $defMarker, array $defArgs = []) + public function validate($url, string $defMarker, array $defArgs = []): string { if (\is_string($url) && \parse_url($url, PHP_URL_HOST) === $this->host @@ -116,7 +116,7 @@ class Router * * @return string */ - public function link($marker = null, array $args = []) + public function link(string $marker = null, array $args = []): string { $result = $this->baseUrl; $anchor = isset($args['#']) ? '#' . \rawurlencode($args['#']) : ''; @@ -167,7 +167,7 @@ class Router * * @return array */ - public function route($method, $uri) + public function route(string $method, string $uri): array { $head = $method == 'HEAD'; @@ -239,7 +239,7 @@ class Router * @param string $handler * @param string $marker */ - public function add($method, $route, $handler, $marker = null) + public function add($method, string $route, string $handler, string $marker = null): void { if (\is_array($method)) { foreach ($method as $m) { @@ -293,9 +293,9 @@ class Router * * @param string $route * - * @return array|false + * @return array|null */ - protected function parse($route) + protected function parse(string $route): ?array { $parts = \preg_split('%([\[\]{}/])%', $route, -1, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE); @@ -323,14 +323,14 @@ class Router if ($var) { switch ($part) { case '{': - return false; + return null; case '}': $data = \explode(':', $buffer, 2); if (! isset($data[1])) { $data[1] = '[^/\x00-\x1f]+'; } if ($data[0] === '' || $data[1] === '' || \is_numeric($data[0][0])) { - return false; + return null; } $pattern .= '(?P<' . $data[0] . '>' . $data[1] . ')'; $args[] = $data[0]; @@ -350,7 +350,7 @@ class Router $temp .= $part; break; default: - return false; + return null; } } else { switch ($part) { @@ -364,7 +364,7 @@ class Router case ']': --$s; if ($s < 0) { - return false; + return null; } $pattern .= ')?'; $req = true; @@ -374,7 +374,7 @@ class Router $var = true; break; case '}': - return false; + return null; default: $pattern .= \preg_quote($part, '%'); $temp .= $part; @@ -382,7 +382,7 @@ class Router } } if ($var || $s) { - return false; + return null; } $pattern .= '$%D'; return [$base, $pattern, $args, $temp, $argsReq]; diff --git a/app/Core/Secury.php b/app/Core/Secury.php index ed5fdc4f..2a8177f6 100644 --- a/app/Core/Secury.php +++ b/app/Core/Secury.php @@ -40,7 +40,7 @@ class Secury * * @return string */ - public function hash($data) + public function hash(string $data): string { return $this->hmac($data, \md5(__DIR__)); } @@ -55,7 +55,7 @@ class Secury * * @return string */ - public function hmac($data, $key) + public function hmac(string $data, string $key): string { if (empty($key)) { throw new InvalidArgumentException('Key can not be empty'); @@ -72,7 +72,7 @@ class Secury * * @return string */ - public function randomKey($len) + public function randomKey(int $len): string { $key = ''; if (\function_exists('\\random_bytes')) { @@ -100,7 +100,7 @@ class Secury * * @return string */ - public function randomHash($len) + public function randomHash(int $len): string { return \substr(\bin2hex($this->randomKey($len)), 0, $len); } @@ -113,7 +113,7 @@ class Secury * * @return string */ - public function randomPass($len) + public function randomPass(int $len): string { $key = $this->randomKey($len); $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; diff --git a/app/Core/Validator.php b/app/Core/Validator.php index 9da27d0f..669908c8 100644 --- a/app/Core/Validator.php +++ b/app/Core/Validator.php @@ -103,7 +103,7 @@ class Validator * * @return Validator */ - public function reset() + public function reset(): self { $this->validators = [ 'absent' => [$this, 'vAbsent'], @@ -145,7 +145,7 @@ class Validator * * @return Validator */ - public function addValidators(array $validators) + public function addValidators(array $validators): self { $this->validators = \array_replace($this->validators, $validators); return $this; @@ -160,7 +160,7 @@ class Validator * * @return Validator */ - public function addRules(array $list) + public function addRules(array $list): self { foreach ($list as $field => $raw) { $suffix = null; @@ -206,7 +206,7 @@ class Validator * * @return Validator */ - public function addArguments(array $arguments) + public function addArguments(array $arguments): self { $this->arguments = \array_replace($this->arguments, $arguments); return $this; @@ -219,7 +219,7 @@ class Validator * * @return Validator */ - public function addMessages(array $messages) + public function addMessages(array $messages): self { $this->messages = \array_replace($this->messages, $messages); return $this; @@ -232,7 +232,7 @@ class Validator * * @return Validator */ - public function addAliases(array $aliases) + public function addAliases(array $aliases): self { $this->aliases = \array_replace($this->aliases, $aliases); return $this; @@ -247,7 +247,7 @@ class Validator * * @return bool */ - public function validation(array $raw) + public function validation(array $raw): bool { if (empty($this->rules)) { throw new RuntimeException('Rules not found'); @@ -270,7 +270,7 @@ class Validator * * @return bool */ - public function __isset($field) + public function __isset(string $field): bool { return isset($this->result[$field]); } @@ -285,7 +285,7 @@ class Validator * * @return mixed */ - public function __get($field) + public function __get(string $field) { if (isset($this->status[$field])) { return $this->result[$field]; @@ -326,7 +326,7 @@ class Validator * * @return mixed */ - protected function checkValue($value, array $rules, $field) + protected function checkValue($value, array $rules, string $field) { foreach ($rules as $validator => $attr) { // данные для обработчика ошибок @@ -356,7 +356,7 @@ class Validator * * @throws RuntimeException */ - public function addError($error, $type = 'v') + public function addError($error, string $type = 'v'): void { if (empty($vars = \end($this->curData))) { throw new RuntimeException('The array of variables is empty'); @@ -395,7 +395,7 @@ class Validator * * @return mixed */ - protected function getArguments($field, $rule) + protected function getArguments(string $field, string $rule) { if (isset($this->arguments[$field . '.' . $rule])) { return $this->arguments[$field . '.' . $rule]; @@ -413,7 +413,7 @@ class Validator * * @return bool */ - public function getStatus($field) + public function getStatus(string $field): bool { if (! isset($this->status[$field])) { $this->__get($field); @@ -431,7 +431,7 @@ class Validator * * @return array */ - public function getData($all = false) + public function getData(bool $all = false): array { if (empty($this->status)) { throw new RuntimeException('Data not found'); @@ -451,7 +451,7 @@ class Validator * * @return array */ - public function getErrors() + public function getErrors(): array { return $this->errors; } @@ -786,12 +786,12 @@ class Validator if (\is_array($value)) { foreach ($value as $file) { - if (false === $this->c->Files->isImage($file)) { + if (null === $this->c->Files->isImage($file)) { $this->addError('The :alias not contains image'); return null; } } - } elseif (null !== $value && false === $this->c->Files->isImage($value)) { + } elseif (null !== $value && null === $this->c->Files->isImage($value)) { $this->addError('The :alias not contains image'); return null; } diff --git a/app/Core/Validators.php b/app/Core/Validators.php index 80148c5d..fcb6950e 100644 --- a/app/Core/Validators.php +++ b/app/Core/Validators.php @@ -31,7 +31,7 @@ abstract class Validators * * @throws RuntimeException */ - public function __call($name, array $args) + public function __call(string $name, array $args) { throw new RuntimeException($name . ' validator not found'); } diff --git a/app/Core/View.php b/app/Core/View.php index cc26f308..cdb42bd2 100644 --- a/app/Core/View.php +++ b/app/Core/View.php @@ -85,7 +85,7 @@ EOD; * * @return null|string */ - public function rendering(Page $p) + public function rendering(Page $p): ?string { foreach ($p->httpHeaders as $header) { \header($header[0], $header[1]); diff --git a/app/Models/Action.php b/app/Models/Action.php index 08fd0e3e..9c65c16d 100644 --- a/app/Models/Action.php +++ b/app/Models/Action.php @@ -31,12 +31,12 @@ class Action /** * Объявление менеджера - * + * * @param ManagerModel $manager - * + * * @return Action */ - public function setManager(ManagerModel $manager) + public function setManager(ManagerModel $manager): self { $this->manager = $manager; return $this; diff --git a/app/Models/AdminList/Model.php b/app/Models/AdminList/Model.php index de219bd2..d27b4fd1 100644 --- a/app/Models/AdminList/Model.php +++ b/app/Models/AdminList/Model.php @@ -11,7 +11,7 @@ class Model extends ParentModel * * @return AdminList\Model */ - public function init() + public function init(): self { if ($this->c->Cache->has('admins')) { $this->list = $this->c->Cache->get('admins'); @@ -27,7 +27,7 @@ class Model extends ParentModel * * @return AdminList\Model */ - public function reset() + public function reset(): self { $this->c->Cache->delete('admins'); return $this; diff --git a/app/Models/BanList/Check.php b/app/Models/BanList/Check.php index 92ea8c46..5b363a67 100644 --- a/app/Models/BanList/Check.php +++ b/app/Models/BanList/Check.php @@ -15,7 +15,7 @@ class Check extends Method * * @return bool */ - public function check(User $user) + public function check(User $user): bool { // админ if ($user->isAdmin) { diff --git a/app/Models/BanList/Delete.php b/app/Models/BanList/Delete.php index c4a27cd2..a6b4aa3b 100644 --- a/app/Models/BanList/Delete.php +++ b/app/Models/BanList/Delete.php @@ -3,6 +3,7 @@ namespace ForkBB\Models\BanList; use ForkBB\Models\Method; +use ForkBB\Models\BanList\Model; class Delete extends Method { @@ -14,7 +15,7 @@ class Delete extends Method * * @return BanList\Model */ - public function delete(array $ids) + public function delete(array $ids): Model { if (! empty($ids)) { $vars = [ diff --git a/app/Models/BanList/Filter.php b/app/Models/BanList/Filter.php index 3a9c8d7a..bb1efd55 100644 --- a/app/Models/BanList/Filter.php +++ b/app/Models/BanList/Filter.php @@ -18,7 +18,7 @@ class Filter extends Method * * @return array */ - public function filter(array $filters, array $order = []) + public function filter(array $filters, array $order = []): array { $fields = $this->c->dbMap->bans; $orderBy = []; diff --git a/app/Models/BanList/GetList.php b/app/Models/BanList/GetList.php index 11949bef..ebaa5cfa 100644 --- a/app/Models/BanList/GetList.php +++ b/app/Models/BanList/GetList.php @@ -13,7 +13,7 @@ class GetList extends Method * * @return array */ - public function getList(array $ids) + public function getList(array $ids): array { $vars = [ ':ids' => $ids, diff --git a/app/Models/BanList/Insert.php b/app/Models/BanList/Insert.php index 7022af7d..1e010019 100644 --- a/app/Models/BanList/Insert.php +++ b/app/Models/BanList/Insert.php @@ -4,6 +4,7 @@ namespace ForkBB\Models\BanList; use ForkBB\Models\Method; use InvalidArgumentException; +use ForkBB\Models\BanList\Model; class Insert extends Method { @@ -14,7 +15,7 @@ class Insert extends Method * * @return BanList\Model */ - public function insert(array $ban) + public function insert(array $ban): Model { if (isset($ban['id']) || ! isset($ban['username']) diff --git a/app/Models/BanList/IsBanned.php b/app/Models/BanList/IsBanned.php index 1d33958a..d42db4dc 100644 --- a/app/Models/BanList/IsBanned.php +++ b/app/Models/BanList/IsBanned.php @@ -14,7 +14,7 @@ class IsBanned extends Method * * @return int */ - public function isBanned(User $user) + public function isBanned(User $user): int { $name = $this->model->trimToNull($user->username, true); // бан имени пользователя diff --git a/app/Models/BanList/Load.php b/app/Models/BanList/Load.php index b0abd2c9..4000e523 100644 --- a/app/Models/BanList/Load.php +++ b/app/Models/BanList/Load.php @@ -3,6 +3,7 @@ namespace ForkBB\Models\BanList; use ForkBB\Models\Method; +use ForkBB\Models\BanList\Model; class Load extends Method { @@ -12,7 +13,7 @@ class Load extends Method * * @return BanList\Model */ - public function load() + public function load(): Model { $userList = []; $emailList = []; diff --git a/app/Models/BanList/Model.php b/app/Models/BanList/Model.php index 4eb204c9..8e22217c 100644 --- a/app/Models/BanList/Model.php +++ b/app/Models/BanList/Model.php @@ -11,7 +11,7 @@ class Model extends ParentModel * * @return BanList\Model */ - public function init() + public function init(): self { if ($this->c->Cache->has('banlist')) { $list = $this->c->Cache->get('banlist'); @@ -39,7 +39,7 @@ class Model extends ParentModel * * @return null|string */ - public function trimToNull($val, $toLower = false) + public function trimToNull($val, bool $toLower = false): ?string { $val = \trim($val); if ($val == '') { @@ -58,7 +58,7 @@ class Model extends ParentModel * * @return string */ - public function ip2hex($ip) + public function ip2hex(string $ip): string { $bin = \inet_pton($ip); diff --git a/app/Models/BanList/Update.php b/app/Models/BanList/Update.php index bf2363fa..e95326e9 100644 --- a/app/Models/BanList/Update.php +++ b/app/Models/BanList/Update.php @@ -4,6 +4,7 @@ namespace ForkBB\Models\BanList; use ForkBB\Models\Method; use InvalidArgumentException; +use ForkBB\Models\BanList\Model; class Update extends Method { @@ -14,7 +15,7 @@ class Update extends Method * * @return BanList\Model */ - public function update(array $ban) + public function update(array $ban): Model { if (empty($ban['id']) || ! isset($ban['username']) diff --git a/app/Models/Categories/Manager.php b/app/Models/Categories/Manager.php index 2b0c552b..b99c1298 100644 --- a/app/Models/Categories/Manager.php +++ b/app/Models/Categories/Manager.php @@ -21,7 +21,7 @@ class Manager extends ManagerModel * * @return Manager */ - public function init() + public function init(): self { $sql = 'SELECT c.id, c.cat_name, c.disp_position FROM ::categories AS c @@ -30,12 +30,12 @@ class Manager extends ManagerModel return $this; } - public function getList() + public function getList(): array { return $this->repository; } - public function set($key, $value) + public function set($key, $value): self { if (! isset($value['cat_name'], $value['disp_position'])) { throw new InvalidArgumentException('Expected array with cat_name and disp_position elements'); @@ -52,9 +52,11 @@ class Manager extends ManagerModel if ($old != $value) { $this->modified[$key] = true; } + + return $this; } - public function update() + public function update(): self { foreach ($this->modified as $key => $value) { $cat = $this->get($key); @@ -73,7 +75,7 @@ class Manager extends ManagerModel return $this; } - public function insert($name) + public function insert(string $name): int { $pos = 0; foreach ($this->repository as $cat) { @@ -98,7 +100,7 @@ class Manager extends ManagerModel return $cid; } - public function delete($cid) + public function delete(int $cid): self { $root = $this->c->forums->get(0); $del = []; diff --git a/app/Models/Censorship/Load.php b/app/Models/Censorship/Load.php index 3248c211..a3af54e0 100644 --- a/app/Models/Censorship/Load.php +++ b/app/Models/Censorship/Load.php @@ -12,7 +12,7 @@ class Load extends Method * * @return array */ - public function load() + public function load(): array { $sql = 'SELECT ce.id, ce.search_for, ce.replace_with FROM ::censoring AS ce diff --git a/app/Models/Censorship/Model.php b/app/Models/Censorship/Model.php index 28bbebe4..35bc8d9d 100644 --- a/app/Models/Censorship/Model.php +++ b/app/Models/Censorship/Model.php @@ -11,7 +11,7 @@ class Model extends ParentModel * * @return Censorship\Model */ - public function init() + public function init(): self { if ('1' == $this->c->config->o_censoring) { if ($this->c->Cache->has('censorship')) { @@ -32,7 +32,7 @@ class Model extends ParentModel * * @return string */ - public function censor($str) + public function censor(string $str): string { if ('1' == $this->c->config->o_censoring) { return (string) \preg_replace($this->searchList, $this->replaceList, $str); diff --git a/app/Models/Censorship/Refresh.php b/app/Models/Censorship/Refresh.php index c0b7af22..86cae784 100644 --- a/app/Models/Censorship/Refresh.php +++ b/app/Models/Censorship/Refresh.php @@ -3,6 +3,7 @@ namespace ForkBB\Models\Censorship; use ForkBB\Models\Method; +use ForkBB\Models\Censorship\Model; class Refresh extends Method { @@ -12,7 +13,7 @@ class Refresh extends Method * * @return Censorship */ - public function refresh() + public function refresh(): Model { $stmt = $this->c->DB->query('SELECT ce.id, ce.search_for, ce.replace_with FROM ::censoring AS ce'); $search = []; diff --git a/app/Models/Censorship/Save.php b/app/Models/Censorship/Save.php index 2221eaa4..aec318eb 100644 --- a/app/Models/Censorship/Save.php +++ b/app/Models/Censorship/Save.php @@ -4,6 +4,7 @@ namespace ForkBB\Models\Censorship; use ForkBB\Models\Method; use PDO; +use ForkBB\Models\Censorship\Model; class Save extends Method { @@ -14,7 +15,7 @@ class Save extends Method * * @return Censorship */ - public function save(array $list) + public function save(array $list): Model { $words = $this->model->load(); $forDel = []; diff --git a/app/Models/Config/Install.php b/app/Models/Config/Install.php index 8387c2ca..1e73b307 100644 --- a/app/Models/Config/Install.php +++ b/app/Models/Config/Install.php @@ -3,6 +3,7 @@ namespace ForkBB\Models\Config; use ForkBB\Models\Method; +use ForkBB\Models\Config\Model; class Install extends Method { @@ -11,7 +12,7 @@ class Install extends Method * * @return Config */ - public function install() + public function install(): Model { $this->model->setAttrs($this->c->forConfig); return $this->model; diff --git a/app/Models/Config/Load.php b/app/Models/Config/Load.php index 5acd51f7..0bc0893d 100644 --- a/app/Models/Config/Load.php +++ b/app/Models/Config/Load.php @@ -4,6 +4,7 @@ namespace ForkBB\Models\Config; use ForkBB\Models\Method; use PDO; +use ForkBB\Models\Config\Model; class Load extends Method { @@ -13,7 +14,7 @@ class Load extends Method * * @return Config */ - public function load() + public function load(): Model { $config = $this->c->DB->query('SELECT cf.conf_name, cf.conf_value FROM ::config AS cf')->fetchAll(PDO::FETCH_KEY_PAIR); $this->model->setAttrs($config); diff --git a/app/Models/Config/Model.php b/app/Models/Config/Model.php index 7aea7e8d..042354a5 100644 --- a/app/Models/Config/Model.php +++ b/app/Models/Config/Model.php @@ -11,7 +11,7 @@ class Model extends DataModel * * @return Config\Model */ - public function init() + public function init(): self { if ($this->c->Cache->has('config')) { $this->setAttrs($this->c->Cache->get('config')); diff --git a/app/Models/Config/Save.php b/app/Models/Config/Save.php index b4d102a4..8efdbf57 100644 --- a/app/Models/Config/Save.php +++ b/app/Models/Config/Save.php @@ -3,6 +3,7 @@ namespace ForkBB\Models\Config; use ForkBB\Models\Method; +use ForkBB\Models\Config\Model; class Save extends Method { @@ -12,7 +13,7 @@ class Save extends Method * * @return Config */ - public function save() + public function save(): Model { $modified = $this->model->getModified(); if (empty($modified)) { diff --git a/app/Models/Cookie/Model.php b/app/Models/Cookie/Model.php index 1fa4656c..1985bc49 100644 --- a/app/Models/Cookie/Model.php +++ b/app/Models/Cookie/Model.php @@ -53,7 +53,7 @@ class Model extends ParentModel * * @return bool */ - public function set($name, $value, $expire = 0, $path = null, $domain = null, $secure = false, $httponly = true) + public function set(string $name, string $value, int $expire = 0, string $path = null, string $domain = null, bool $secure = false, bool $httponly = true): bool { $result = \setcookie( $this->prefix . $name, @@ -78,7 +78,7 @@ class Model extends ParentModel * * @return mixed */ - public function get($name, $default = null) + public function get(string $name, $default = null) { $name = $this->prefix . $name; return isset($_COOKIE[$name]) ? $this->c->Secury->replInvalidChars($_COOKIE[$name]) : $default; @@ -93,7 +93,7 @@ class Model extends ParentModel * * @return bool */ - public function delete($name, $path = null, $domain = null) + public function delete(string $name, string $path = null, string $domain = null): bool { $result = $this->set($name, '', 1, $path, $domain); if ($result) { @@ -105,7 +105,7 @@ class Model extends ParentModel /** * Выделяет данные из куки аутентификации пользователя */ - protected function init() + protected function init(): void { $ckUser = $this->get(self::NAME); @@ -138,7 +138,7 @@ class Model extends ParentModel * * @return bool */ - public function verifyUser(User $user) + public function verifyUser(User $user): bool { return $this->uId === (int) $user->id && \hash_equals( @@ -155,7 +155,7 @@ class Model extends ParentModel * * @return bool */ - public function setUser(User $user, $remember = null) + public function setUser(User $user, bool $remember = null): bool { if ($user->isGuest) { return $this->deleteUser(); @@ -186,7 +186,7 @@ class Model extends ParentModel * * @return bool */ - public function deleteUser() + public function deleteUser(): bool { if (null === $this->get(self::NAME)) { return true; @@ -203,7 +203,7 @@ class Model extends ParentModel * * @throws RuntimeException */ - public function __set($name, $val) + public function __set(string $name, $val): void { if ($this->noSet) { throw new RuntimeException('Model attributes in read-only mode'); diff --git a/app/Models/DBMap/Model.php b/app/Models/DBMap/Model.php index e5ace996..a5707b23 100644 --- a/app/Models/DBMap/Model.php +++ b/app/Models/DBMap/Model.php @@ -11,7 +11,7 @@ class Model extends ParentModel * * @return DBMap\Model */ - public function init() + public function init(): self { if ($this->c->Cache->has('db_map')) { $this->setAttrs($this->c->Cache->get('db_map')); @@ -28,7 +28,7 @@ class Model extends ParentModel * * @return DBMap\Model */ - public function reset() + public function reset(): self { $this->c->Cache->delete('db_map'); return $this; diff --git a/app/Models/DataModel.php b/app/Models/DataModel.php index b26c3882..9d45509f 100644 --- a/app/Models/DataModel.php +++ b/app/Models/DataModel.php @@ -29,7 +29,7 @@ class DataModel extends Model * * @return DataModel */ - public function setAttrs(array $attrs) + public function setAttrs(array $attrs): self { $this->zModFlags = []; $this->zTrackFlags = []; @@ -46,7 +46,7 @@ class DataModel extends Model * * @return DataModel */ - public function replAttrs(array $attrs, $setFlags = false) + public function replAttrs(array $attrs, bool $setFlags = false): self { foreach ($attrs as $name => $value) { $this->__set($name, $value); @@ -64,7 +64,7 @@ class DataModel extends Model * * @return array */ - public function getAttrs() + public function getAttrs(): array { return $this->zAttrs; //???? } @@ -74,7 +74,7 @@ class DataModel extends Model * * @return array */ - public function getModified() + public function getModified(): array { return \array_keys($this->zModFlags); } @@ -82,7 +82,7 @@ class DataModel extends Model /** * Обнуляет массив флагов измененных свойств модели */ - public function resModified() + public function resModified(): void { $this->zModFlags = []; $this->zTrackFlags = []; @@ -94,7 +94,7 @@ class DataModel extends Model * @param string $name * @param mixed $value */ - public function __set($name, $value) + public function __set(string $name, $value): void { // без отслеживания if (\strpos($name, '__') === 0) { @@ -137,7 +137,7 @@ class DataModel extends Model * * @return mixed */ - public function __get($name) + public function __get(string $name) { // без вычисления if (\strpos($name, '__') === 0) { diff --git a/app/Models/Forum/CalcStat.php b/app/Models/Forum/CalcStat.php index 67961a0e..b0a7a8ff 100644 --- a/app/Models/Forum/CalcStat.php +++ b/app/Models/Forum/CalcStat.php @@ -4,6 +4,7 @@ namespace ForkBB\Models\Forum; use ForkBB\Models\Method; use RuntimeException; +use ForkBB\Models\Forum\Model; class CalcStat extends Method { @@ -14,7 +15,7 @@ class CalcStat extends Method * * @return Forum */ - public function calcStat() + public function calcStat(): Model { if ($this->model->id < 1) { throw new RuntimeException('The model does not have ID'); diff --git a/app/Models/Forum/Delete.php b/app/Models/Forum/Delete.php index 43c02fda..51492d7c 100644 --- a/app/Models/Forum/Delete.php +++ b/app/Models/Forum/Delete.php @@ -18,7 +18,7 @@ class Delete extends Action * @throws InvalidArgumentException * @throws RuntimeException */ - public function delete(...$args) + public function delete(...$args): void { if (empty($args)) { throw new InvalidArgumentException('No arguments, expected User(s) or Forum(s)'); diff --git a/app/Models/Forum/LoadTree.php b/app/Models/Forum/LoadTree.php index cffdaf0c..408a3dfa 100644 --- a/app/Models/Forum/LoadTree.php +++ b/app/Models/Forum/LoadTree.php @@ -3,6 +3,7 @@ namespace ForkBB\Models\Forum; use ForkBB\Models\Action; +use ForkBB\Models\Forum\Model; class LoadTree extends Action { @@ -13,7 +14,7 @@ class LoadTree extends Action * * @return null|Forum */ - public function loadTree($rootId) + public function loadTree(int $rootId): ?Model { $root = $this->manager->get($rootId); if (null === $root) { @@ -44,7 +45,7 @@ class LoadTree extends Action * * @param array $list */ - protected function loadData(array $list) + protected function loadData(array $list): void { if (empty($list)) { return; @@ -88,7 +89,7 @@ class LoadTree extends Action * * @param array $list */ - protected function checkForNew(array $list) + protected function checkForNew(array $list): void { if (empty($list) || $this->c->user->isGuest) { return; diff --git a/app/Models/Forum/Manager.php b/app/Models/Forum/Manager.php index a7ae2b93..db72fae0 100644 --- a/app/Models/Forum/Manager.php +++ b/app/Models/Forum/Manager.php @@ -22,7 +22,7 @@ class Manager extends ManagerModel * * @return Forum */ - public function create(array $attrs = []) + public function create(array $attrs = []): Forum { return $this->c->ForumModel->setAttrs($attrs); } @@ -34,7 +34,7 @@ class Manager extends ManagerModel * * @return Manager */ - public function init(Group $group = null) + public function init(Group $group = null): self { if (null === $group) { $gid = $this->c->user->group_id; @@ -66,7 +66,7 @@ class Manager extends ManagerModel * * @return null|Forum */ - public function get($id) + public function get($id): ?Forum { $forum = parent::get($id); @@ -88,7 +88,7 @@ class Manager extends ManagerModel * * @return Forum */ - public function update(Forum $forum) + public function update(Forum $forum): Forum { return $this->Save->update($forum); } @@ -100,7 +100,7 @@ class Manager extends ManagerModel * * @return int */ - public function insert(Forum $forum) + public function insert(Forum $forum): int { $id = $this->Save->insert($forum); $this->set($id, $forum); @@ -116,7 +116,7 @@ class Manager extends ManagerModel * * @return array */ - public function depthList(Forum $forum, $depth, array $list = []) + public function depthList(Forum $forum, int $depth, array $list = []): array { ++$depth; foreach ($forum->subforums as $sub) { diff --git a/app/Models/Forum/Markread.php b/app/Models/Forum/Markread.php index e0cc6e7c..5e1ccb51 100644 --- a/app/Models/Forum/Markread.php +++ b/app/Models/Forum/Markread.php @@ -18,7 +18,7 @@ class Markread extends Action * * @return Forum */ - public function markread(Forum $forum, User $user) + public function markread(Forum $forum, User $user): Forum { if ($user->isGuest) { throw new RuntimeException('Expected user, not guest'); diff --git a/app/Models/Forum/Model.php b/app/Models/Forum/Model.php index 1ce9f26a..aa682c8a 100644 --- a/app/Models/Forum/Model.php +++ b/app/Models/Forum/Model.php @@ -4,6 +4,7 @@ namespace ForkBB\Models\Forum; use ForkBB\Models\DataModel; use ForkBB\Models\User\Model as User; +use ForkBB\Models\Forum\Model as Forum; use RuntimeException; use InvalidArgumentException; use PDO; @@ -17,7 +18,7 @@ class Model extends DataModel * * @return Forum\Model */ - protected function getparent() + protected function getparent(): ?Forum { if (null === $this->parent_forum_id && $this->id !== 0) { throw new RuntimeException('Parent is not defined'); @@ -31,7 +32,7 @@ class Model extends DataModel * * @return bool */ - protected function getcanCreateTopic() + protected function getcanCreateTopic(): bool { $user = $this->c->user; return $this->post_topics == 1 @@ -45,7 +46,7 @@ class Model extends DataModel * * @return bool */ - protected function getcanMarkRead() + protected function getcanMarkRead(): bool { return ! $this->c->user->isGuest; // ???? } @@ -55,7 +56,7 @@ class Model extends DataModel * * @return array */ - protected function getsubforums() + protected function getsubforums(): array { $sub = []; $attr = $this->getAttr('subforums'); @@ -74,7 +75,7 @@ class Model extends DataModel * * @return array */ - protected function getdescendants() + protected function getdescendants(): array { $all = []; $attr = $this->getAttr('descendants'); @@ -93,7 +94,7 @@ class Model extends DataModel * * @return string */ - protected function getlink() + protected function getlink(): string { if (0 === $this->id) { return $this->c->Router->link('Index'); @@ -107,7 +108,7 @@ class Model extends DataModel * * @return string */ - protected function getlinkNew() + protected function getlinkNew(): string { if (0 === $this->id) { return $this->c->Router->link('SearchAction', ['action' => 'new']); @@ -121,7 +122,7 @@ class Model extends DataModel * * @return null|string */ - protected function getlinkLast() + protected function getlinkLast(): ?string { if ($this->last_post_id < 1) { return null; @@ -135,7 +136,7 @@ class Model extends DataModel * * @return string */ - protected function getlinkCreateTopic() + protected function getlinkCreateTopic(): string { return $this->c->Router->link('NewTopic', ['id' => $this->id]); } @@ -145,7 +146,7 @@ class Model extends DataModel * * @return string */ - protected function getlinkMarkRead() + protected function getlinkMarkRead(): string { return $this->c->Router->link('MarkRead', [ 'id' => $this->id, @@ -158,7 +159,7 @@ class Model extends DataModel * * @return array */ - protected function getmoderators() + protected function getmoderators(): array { $attr = $this->getAttr('moderators'); if (empty($attr) || ! \is_array($attr)) { @@ -188,7 +189,7 @@ class Model extends DataModel * * @throws InvalidArgumentException */ - public function modAdd(...$users) + public function modAdd(...$users): void { $attr = $this->getAttr('moderators'); if (empty($attr) || ! \is_array($attr)) { @@ -212,7 +213,7 @@ class Model extends DataModel * * @throws InvalidArgumentException */ - public function modDelete(...$users) + public function modDelete(...$users): void { $attr = $this->getAttr('moderators'); if (empty($attr) || ! \is_array($attr)) { @@ -234,7 +235,7 @@ class Model extends DataModel * * @return Forum\Model */ - protected function gettree() + protected function gettree(): Forum { $attr = $this->getAttr('tree'); @@ -279,7 +280,7 @@ class Model extends DataModel * * @return int */ - protected function getnumPages() + protected function getnumPages(): int { if (null === $this->num_topics) { throw new RuntimeException('The model does not have the required data'); @@ -293,7 +294,7 @@ class Model extends DataModel * * @return array */ - protected function getpagination() + protected function getpagination(): array { return $this->c->Func->paginate($this->numPages, $this->page, 'Forum', ['id' => $this->id, 'name' => $this->forum_name]); } @@ -303,7 +304,7 @@ class Model extends DataModel * * @return bool */ - public function hasPage() + public function hasPage(): bool { return $this->page > 0 && $this->page <= $this->numPages; } @@ -315,7 +316,7 @@ class Model extends DataModel * * @return array */ - public function pageData() + public function pageData(): array { if (! $this->hasPage()) { throw new InvalidArgumentException('Bad number of displayed page'); @@ -358,7 +359,7 @@ class Model extends DataModel * * @return array */ - public function getAttrs() + public function getAttrs(): array { $data = parent::getAttrs(); diff --git a/app/Models/Forum/Refresh.php b/app/Models/Forum/Refresh.php index 92e34f60..c3bf79d9 100644 --- a/app/Models/Forum/Refresh.php +++ b/app/Models/Forum/Refresh.php @@ -20,7 +20,7 @@ class Refresh extends Action * * @return array */ - public function refresh(Group $group = null) + public function refresh(Group $group = null): array { if (null === $group) { $gid = $this->c->user->group_id; @@ -68,7 +68,7 @@ class Refresh extends Action * * @return null|array */ - protected function formatModers($str) + protected function formatModers(string $str): ?array { $moderators = \json_decode($str, true); return $moderators ?: null; @@ -82,7 +82,7 @@ class Refresh extends Action * * @return array */ - protected function createList(array $list, $parent = 0) + protected function createList(array $list, int $parent = 0): array { $sub = []; $all = []; diff --git a/app/Models/Forum/Save.php b/app/Models/Forum/Save.php index b02b460d..16deff4c 100644 --- a/app/Models/Forum/Save.php +++ b/app/Models/Forum/Save.php @@ -17,7 +17,7 @@ class Save extends Action * * @return Forum */ - public function update(Forum $forum) + public function update(Forum $forum): Forum { if ($forum->id < 1) { throw new RuntimeException('The model does not have ID'); @@ -71,7 +71,7 @@ class Save extends Action * * @return int */ - public function insert(Forum $forum) + public function insert(Forum $forum): int { if (null !== $forum->id) { throw new RuntimeException('The model has ID'); diff --git a/app/Models/Group/Delete.php b/app/Models/Group/Delete.php index 8e02a76a..e878f468 100644 --- a/app/Models/Group/Delete.php +++ b/app/Models/Group/Delete.php @@ -18,7 +18,7 @@ class Delete extends Action * @throws InvalidArgumentException * @throws RuntimeException */ - public function delete(Group $group, Group $new = null) + public function delete(Group $group, Group $new = null): void { if (null !== $new) { $this->c->users->promote($group, $new); diff --git a/app/Models/Group/Manager.php b/app/Models/Group/Manager.php index 40a7ff91..71ece2cd 100644 --- a/app/Models/Group/Manager.php +++ b/app/Models/Group/Manager.php @@ -21,12 +21,12 @@ class Manager extends ManagerModel * * @return Group */ - public function create(array $attrs = []) + public function create(array $attrs = []): Group { return $this->c->GroupModel->setAttrs($attrs); } - public function getList() + public function getList(): array { return $this->repository; } @@ -36,7 +36,7 @@ class Manager extends ManagerModel * * @return Manager */ - public function init() + public function init(): self { if (empty($this->flag)) { $stmt = $this->c->DB->query('SELECT g.* FROM ::groups AS g ORDER BY g.g_id'); @@ -55,7 +55,7 @@ class Manager extends ManagerModel * * @return null|Group */ - public function get($id) + public function get($id): ?Group { $group = parent::get($id); @@ -69,7 +69,7 @@ class Manager extends ManagerModel * * @return Group */ - public function update(Group $group) + public function update(Group $group): Group { return $this->Save->update($group); } @@ -81,7 +81,7 @@ class Manager extends ManagerModel * * @return int */ - public function insert(Group $group) + public function insert(Group $group): int { $id = $this->Save->insert($group); $this->set($id, $group); diff --git a/app/Models/Group/Model.php b/app/Models/Group/Model.php index 7a4b1702..8b75727b 100644 --- a/app/Models/Group/Model.php +++ b/app/Models/Group/Model.php @@ -8,12 +8,12 @@ use InvalidArgumentException; class Model extends DataModel { - protected function getlinkEdit() + protected function getlinkEdit(): string { return $this->c->Router->link('AdminGroupsEdit', ['id' => $this->g_id]); } - protected function getcanDelete() + protected function getcanDelete(): bool { $notDeleted = [ $this->c->GROUP_ADMIN, @@ -24,22 +24,22 @@ class Model extends DataModel return ! \in_array($this->g_id, $notDeleted) && $this->g_id != $this->c->config->o_default_user_group; } - protected function getlinkDelete() + protected function getlinkDelete(): ?string { return $this->canDelete ? $this->c->Router->link('AdminGroupsDelete', ['id' => $this->g_id]) : null; } - protected function getgroupGuest() + protected function getgroupGuest(): bool { return $this->g_id === $this->c->GROUP_GUEST; } - protected function getgroupMember() + protected function getgroupMember(): bool { return $this->g_id === $this->c->GROUP_MEMBER; } - protected function getgroupAdmin() + protected function getgroupAdmin(): bool { return $this->g_id === $this->c->GROUP_ADMIN; } diff --git a/app/Models/Group/Perm.php b/app/Models/Group/Perm.php index a29bb0b8..e1b0b9c4 100644 --- a/app/Models/Group/Perm.php +++ b/app/Models/Group/Perm.php @@ -24,7 +24,7 @@ class Perm extends Action * * @return array */ - public function get(Forum $forum) + public function get(Forum $forum): array { $vars = [ ':fid' => $forum->id > 0 ? $forum->id : 0, @@ -66,7 +66,7 @@ class Perm extends Action * * @throws RuntimeException */ - public function update(Forum $forum, array $perms) + public function update(Forum $forum, array $perms): void { if ($forum->id < 1) { throw new RuntimeException('The forum does not have ID'); @@ -122,7 +122,7 @@ class Perm extends Action * * @throws RuntimeException */ - public function reset(Forum $forum) + public function reset(Forum $forum): void { if ($forum->id < 1) { throw new RuntimeException('The forum does not have ID'); @@ -143,7 +143,7 @@ class Perm extends Action * * @throws RuntimeException */ - public function delete(Group $group) + public function delete(Group $group): void { if ($group->g_id < 1) { throw new RuntimeException('The group does not have ID'); @@ -165,7 +165,7 @@ class Perm extends Action * * @throws RuntimeException */ - public function copy(Group $from, Group $to) + public function copy(Group $from, Group $to): void { if ($from->g_id < 1 || $to->g_id < 1) { throw new RuntimeException('The group does not have ID'); diff --git a/app/Models/Group/Save.php b/app/Models/Group/Save.php index 59b2edb7..f2ee7cfa 100644 --- a/app/Models/Group/Save.php +++ b/app/Models/Group/Save.php @@ -17,7 +17,7 @@ class Save extends Action * * @return Group */ - public function update(Group $group) + public function update(Group $group): Group { if ($group->g_id < 1) { throw new RuntimeException('The model does not have ID'); @@ -55,7 +55,7 @@ class Save extends Action * * @return int */ - public function insert(Group $group) + public function insert(Group $group): int { if (null !== $group->g_id) { throw new RuntimeException('The model has ID'); diff --git a/app/Models/ManagerModel.php b/app/Models/ManagerModel.php index a466c820..55344b9f 100644 --- a/app/Models/ManagerModel.php +++ b/app/Models/ManagerModel.php @@ -16,7 +16,7 @@ class ManagerModel extends Model return isset($this->repository[$key]) ? $this->repository[$key] : null; } - public function set($key, $value) + public function set($key, $value): self { $this->repository[$key] = $value; @@ -30,7 +30,7 @@ class ManagerModel extends Model * * @return mixed */ - public function __get($name) + public function __get(string $name) { $key = \str_replace(['ForkBB\\Models\\', 'ForkBB\\', '\\'], '', \get_class($this)); @@ -45,7 +45,7 @@ class ManagerModel extends Model * * @return mixed */ - public function __call($name, array $args) + public function __call(string $name, array $args) { return $this->__get($name)->$name(...$args); } diff --git a/app/Models/Method.php b/app/Models/Method.php index 3ffe6673..3ebbb56e 100644 --- a/app/Models/Method.php +++ b/app/Models/Method.php @@ -31,12 +31,12 @@ class Method /** * Объявление модели - * + * * @param Model $model - * + * * @return Method */ - public function setModel(Model $model) + public function setModel(Model $model): self { $this->model = $model; return $this; diff --git a/app/Models/Model.php b/app/Models/Model.php index 8a5f5ba0..c7031a6f 100644 --- a/app/Models/Model.php +++ b/app/Models/Model.php @@ -48,7 +48,7 @@ class Model * * @return bool */ - public function __isset($name) + public function __isset($name): bool { return \array_key_exists($name, $this->zAttrs) || \array_key_exists($name, $this->zAttrsCalc) @@ -60,7 +60,7 @@ class Model * * @param mixed $name */ - public function __unset($name) + public function __unset($name): void { unset($this->zAttrs[$name]); $this->unsetCalc($name); @@ -71,7 +71,7 @@ class Model * * @param mixed $name */ - protected function unsetCalc($name) + protected function unsetCalc($name): void { unset($this->zAttrsCalc[$name]); //???? @@ -86,7 +86,7 @@ class Model * @param string $name * @param mixed $value */ - public function __set($name, $value) + public function __set(string $name, $value): void { $this->unsetCalc($name); @@ -106,7 +106,7 @@ class Model * * @return Model */ - public function setAttr($name, $value) + public function setAttr(string $name, $value): self { $this->unsetCalc($name); $this->zAttrs[$name] = $value; @@ -122,7 +122,7 @@ class Model * * @return Model */ - public function setAttrs(array $attrs) + public function setAttrs(array $attrs): self { $this->zAttrs = $attrs; //???? $this->zAttrsCalc = []; @@ -137,7 +137,7 @@ class Model * * @return mixed */ - public function __get($name) + public function __get(string $name) { if (\array_key_exists($name, $this->zAttrsCalc)) { return $this->zAttrsCalc[$name]; @@ -157,7 +157,7 @@ class Model * * @return mixed */ - public function getAttr($name, $default = null) + public function getAttr(string $name, $default = null) { return \array_key_exists($name, $this->zAttrs) ? $this->zAttrs[$name] : $default; } @@ -170,7 +170,7 @@ class Model * * @return mixed */ - public function __call($name, array $args) + public function __call(string $name, array $args) { $key = \str_replace(['ForkBB\\Models\\', 'ForkBB\\', '\\'], '', \get_class($this)); diff --git a/app/Models/Online/Info.php b/app/Models/Online/Info.php index 5c872681..bbe80e58 100644 --- a/app/Models/Online/Info.php +++ b/app/Models/Online/Info.php @@ -3,6 +3,7 @@ namespace ForkBB\Models\Online; use ForkBB\Models\Method; +use ForkBB\Models\Online\Model as Online; class Info extends Method { @@ -11,7 +12,7 @@ class Info extends Method * * @return null|Online\Model */ - public function info() + public function info(): ?Online { if (! $this->model->detail) { return null; diff --git a/app/Models/Online/Model.php b/app/Models/Online/Model.php index bb47c729..a49d381e 100644 --- a/app/Models/Online/Model.php +++ b/app/Models/Online/Model.php @@ -17,7 +17,7 @@ class Model extends ParentModel * * @return Online\Model */ - public function calc(Page $page) + public function calc(Page $page): self { if ($this->done) { return $this; @@ -138,7 +138,7 @@ class Model extends ParentModel * * @param string $position */ - protected function updateUser($position) + protected function updateUser(string $position): void { // гость if ($this->c->user->isGuest) { @@ -174,7 +174,7 @@ class Model extends ParentModel * * @param User $user */ - public function delete(User $user) + public function delete(User $user): void { if ($user->isGuest) { $this->c->DB->exec('DELETE FROM ::online WHERE user_id=1 AND ident=?s:ip', [':ip' => $user->ip]); diff --git a/app/Models/Page.php b/app/Models/Page.php index f6b8200b..c6691a16 100644 --- a/app/Models/Page.php +++ b/app/Models/Page.php @@ -43,7 +43,7 @@ abstract class Page extends Model /** * Подготовка страницы к отображению */ - public function prepare() + public function prepare(): void { $this->fNavigation = $this->fNavigation(); $this->maintenance(); @@ -54,7 +54,7 @@ abstract class Page extends Model * * @return array */ - protected function fNavigation() + protected function fNavigation(): array { $r = $this->c->Router; @@ -141,7 +141,7 @@ abstract class Page extends Model /** * Вывод информации о режиме обслуживания для админа */ - protected function maintenance() + protected function maintenance(): void { if ($this->c->config->o_maintenance == '1' && $this->user->isAdmin) { $this->fIswev = ['w', \ForkBB\__('Maintenance mode enabled', $this->c->Router->link('AdminMaintenance'))]; @@ -160,7 +160,7 @@ abstract class Page extends Model * * @return string */ - protected function getpageTitle(array $titles = []) + protected function getpageTitle(array $titles = []): string { if (empty($titles)) { $titles = $this->titles; @@ -175,7 +175,7 @@ abstract class Page extends Model * * @return array */ - protected function getpageHeaders() + protected function getpageHeaders(): array { $headers = [ ['link', 'rel="stylesheet" type="text/css" href="' . $this->c->PUBLIC_URL . '/style/' . $this->user->style . '/style.css' . '"'], @@ -205,7 +205,7 @@ abstract class Page extends Model * * @return Page */ - public function addStyle($name, $value) + public function addStyle(string $name, string $value): self { $attr = $this->getAttr('pageHeaders', []); $attr['style'][$name] = $value; @@ -222,7 +222,7 @@ abstract class Page extends Model * * @return Page */ - public function header($key, $value, $replace = true) + public function header(string $key, string $value, $replace = true): self { if ('HTTP/' === \substr($key, 0, 5)) { if (\preg_match('%^HTTP/\d\.\d%', $_SERVER['SERVER_PROTOCOL'], $match)) { @@ -245,7 +245,7 @@ abstract class Page extends Model * * @return array */ - protected function gethttpHeaders() + protected function gethttpHeaders(): array { $now = gmdate('D, d M Y H:i:s') . ' GMT'; @@ -265,7 +265,7 @@ abstract class Page extends Model * * @return Page */ - protected function httpStatus() + protected function httpStatus(): self { $list = [ 403 => '403 Forbidden', @@ -287,7 +287,7 @@ abstract class Page extends Model * * @param string $value */ - public function settitles($value) + public function settitles(string $value): void { $attr = $this->getAttr('titles', []); $attr[] = $value; @@ -300,7 +300,7 @@ abstract class Page extends Model * * @param array $value */ - public function setfIswev(array $value) + public function setfIswev(array $value): void { $attr = $this->getAttr('fIswev', []); @@ -321,7 +321,7 @@ abstract class Page extends Model * * @return array */ - protected function crumbs(...$crumbs) + protected function crumbs(...$crumbs): array { $result = []; $active = true; diff --git a/app/Models/Pages/Admin.php b/app/Models/Pages/Admin.php index 02071742..b7a8b5a6 100644 --- a/app/Models/Pages/Admin.php +++ b/app/Models/Pages/Admin.php @@ -32,7 +32,7 @@ class Admin extends Page /** * Подготовка страницы к отображению */ - public function prepare() + public function prepare(): void { $this->aNavigation = $this->aNavigation(); $this->crumbs = $this->crumbs(...$this->aCrumbs); @@ -45,7 +45,7 @@ class Admin extends Page * * @return array */ - protected function aNavigation() + protected function aNavigation(): array { $r = $this->c->Router; $nav = [ @@ -83,7 +83,7 @@ class Admin extends Page * * @return array */ - protected function crumbs(...$crumbs) + protected function crumbs(...$crumbs): array { if ('index' !== $this->aIndex) { if (isset($this->aNavigation[$this->aIndex])) { diff --git a/app/Models/Pages/Admin/Bans.php b/app/Models/Pages/Admin/Bans.php index 8de1c529..fc4c8851 100644 --- a/app/Models/Pages/Admin/Bans.php +++ b/app/Models/Pages/Admin/Bans.php @@ -4,6 +4,7 @@ namespace ForkBB\Models\Pages\Admin; use ForkBB\Core\Container; use ForkBB\Core\Validator; +use ForkBB\Models\Page; use ForkBB\Models\Pages\Admin; use ForkBB\Models\User\Model as User; use RuntimeException; @@ -31,7 +32,7 @@ class Bans extends Admin * * @return string */ - protected function encodeData(array $data) + protected function encodeData(array $data): string { unset($data['token']); $data = \base64_encode(\json_encode($data)); @@ -46,7 +47,7 @@ class Bans extends Admin * * @return mixed */ - protected function decodeData($data) + protected function decodeData(string $data) { $data = \explode(':', $data); @@ -72,7 +73,7 @@ class Bans extends Admin * * @return Page */ - public function view(array $args, $method, array $data = []) + public function view(array $args, string $method, array $data = []): Page { $this->nameTpl = 'admin/bans'; $this->formBanPage = 'AdminBansNew'; @@ -128,7 +129,7 @@ class Bans extends Admin * * @return array */ - protected function formSearch(array $data = []) + protected function formSearch(array $data = []): array { $form = [ 'action' => $this->c->Router->link('AdminBans'), @@ -248,7 +249,7 @@ class Bans extends Admin * * @return array */ - protected function formBan(array $data = [], array $args = []) + protected function formBan(array $data = [], array $args = []): array { $form = [ 'action' => $this->c->Router->link($this->formBanPage, $args), @@ -334,7 +335,7 @@ class Bans extends Admin * * @return array */ - protected function forFilter(array $data) + protected function forFilter(array $data): array { $order = [ $data['order_by'] => $data['direction'], @@ -376,7 +377,7 @@ class Bans extends Admin * * @return Page */ - public function result(array $args, $method) + public function result(array $args, string $method): Page { $data = $this->decodeData($args['data']); if (false === $data) { @@ -420,7 +421,7 @@ class Bans extends Admin * * @return array */ - protected function form(array $bans, $number, array $args) + protected function form(array $bans, int $number, array $args): array { $form = [ 'sets' => [], @@ -545,7 +546,7 @@ class Bans extends Admin * * @return Page */ - public function add(array $args, $method) + public function add(array $args, string $method): Page { $this->banCount = 0; $userList = []; @@ -604,7 +605,7 @@ class Bans extends Admin * * @return Page */ - public function edit(array $args, $method) + public function edit(array $args, string $method): Page { $this->banCount = 1; @@ -640,7 +641,7 @@ class Bans extends Admin * * @return Page */ - protected function ban($isNew, array $args, $method, array $userList, array $data = []) + protected function ban(bool $isNew, array $args, string $method, array $userList, array $data = []): Page { if ('POST' === $method) { $v = $this->c->Validator->reset() @@ -880,7 +881,7 @@ class Bans extends Admin * * @return Page */ - public function delete(array $args, $method) + public function delete(array $args, string $method): Page { if (! $this->c->Csrf->verify($args['token'], 'AdminBansDelete', $args)) { return $this->c->Message->message('Bad token'); diff --git a/app/Models/Pages/Admin/Categories.php b/app/Models/Pages/Admin/Categories.php index 18e7b927..c84bdd62 100644 --- a/app/Models/Pages/Admin/Categories.php +++ b/app/Models/Pages/Admin/Categories.php @@ -3,6 +3,7 @@ namespace ForkBB\Models\Pages\Admin; use ForkBB\Core\Container; +use ForkBB\Models\Page; use ForkBB\Models\Forum\Model as Forum; use ForkBB\Models\Pages\Admin; @@ -16,7 +17,7 @@ class Categories extends Admin * * @return Page */ - public function view(array $args, $method) + public function view(array $args, string $method): Page { $this->c->Lang->load('admin_categories'); @@ -64,7 +65,7 @@ class Categories extends Admin * * @return array */ - protected function formEdit() + protected function formEdit(): array { $form = [ 'action' => $this->c->Router->link('AdminCategories'), @@ -137,7 +138,7 @@ class Categories extends Admin * * @return Page */ - public function delete(array $args, $method) + public function delete(array $args, string $method): Page { $category = $this->c->categories->get((int) $args['id']); if (! $category) { @@ -187,7 +188,7 @@ class Categories extends Admin * * @return array */ - protected function formDelete(array $args, array $category) + protected function formDelete(array $args, array $category): array { return [ 'action' => $this->c->Router->link('AdminCategoriesDelete', $args), diff --git a/app/Models/Pages/Admin/Censoring.php b/app/Models/Pages/Admin/Censoring.php index 4aedfd4b..704ed362 100644 --- a/app/Models/Pages/Admin/Censoring.php +++ b/app/Models/Pages/Admin/Censoring.php @@ -2,6 +2,7 @@ namespace ForkBB\Models\Pages\Admin; +use ForkBB\Models\Page; use ForkBB\Models\Pages\Admin; class Censoring extends Admin @@ -14,7 +15,7 @@ class Censoring extends Admin * * @return Page */ - public function edit(array $args, $method) + public function edit(array $args, string $method): Page { $this->c->Lang->load('admin_censoring'); @@ -56,7 +57,7 @@ class Censoring extends Admin * * @return array */ - protected function formEdit() + protected function formEdit(): array { $form = [ 'action' => $this->c->Router->link('AdminCensoring'), diff --git a/app/Models/Pages/Admin/Forums.php b/app/Models/Pages/Admin/Forums.php index 8a891aaa..45eac3ed 100644 --- a/app/Models/Pages/Admin/Forums.php +++ b/app/Models/Pages/Admin/Forums.php @@ -3,6 +3,7 @@ namespace ForkBB\Models\Pages\Admin; use ForkBB\Core\Container; +use ForkBB\Models\Page; use ForkBB\Models\Forum\Model as Forum; use ForkBB\Models\Pages\Admin; @@ -13,7 +14,7 @@ class Forums extends Admin * * @param Forum $forum */ - protected function calcList(Forum $forum) + protected function calcList(Forum $forum): void { $cid = null; $categories = $this->c->categories->getList(); @@ -56,7 +57,7 @@ class Forums extends Admin * * @return int */ - protected function forumPos(Forum $forum) + protected function forumPos(Forum $forum): int { if (\is_int($forum->disp_position)) { return $forum->disp_position; @@ -85,7 +86,7 @@ class Forums extends Admin * * @return Page */ - public function view(array $args, $method) + public function view(array $args, string $method): Page { $this->c->Lang->load('admin_forums'); @@ -128,7 +129,7 @@ class Forums extends Admin * * @return array */ - protected function formView() + protected function formView(): array { $form = [ 'action' => $this->c->Router->link('AdminForums'), @@ -214,7 +215,7 @@ class Forums extends Admin * * @return Page */ - public function delete(array $args, $method) + public function delete(array $args, string $method): Page { $forum = $this->c->forums->get((int) $args['id']); if (! $forum instanceof Forum || $forum->subforums) { @@ -264,7 +265,7 @@ class Forums extends Admin * * @return array */ - protected function formDelete(array $args, Forum $forum) + protected function formDelete(array $args, Forum $forum): array { return [ 'action' => $this->c->Router->link('AdminForumsDelete', $args), @@ -318,7 +319,7 @@ class Forums extends Admin * * @return Page */ - public function edit(array $args, $method) + public function edit(array $args, string $method): Page { $this->c->Lang->load('admin_forums'); @@ -418,7 +419,7 @@ class Forums extends Admin * * @return array */ - protected function formEdit(array $args, Forum $forum, $marker) + protected function formEdit(array $args, Forum $forum, string $marker): array { $form = [ 'action' => $this->c->Router->link($marker, $args), diff --git a/app/Models/Pages/Admin/Groups.php b/app/Models/Pages/Admin/Groups.php index 87335b37..1b499337 100644 --- a/app/Models/Pages/Admin/Groups.php +++ b/app/Models/Pages/Admin/Groups.php @@ -3,6 +3,7 @@ namespace ForkBB\Models\Pages\Admin; use ForkBB\Core\Container; +use ForkBB\Models\Page; use ForkBB\Models\Group\Model as Group; use ForkBB\Models\Pages\Admin; @@ -47,7 +48,7 @@ class Groups extends Admin * * @return Page */ - public function view() + public function view(): Page { $this->nameTpl = 'admin/groups'; $this->formNew = $this->formNew(); @@ -61,7 +62,7 @@ class Groups extends Admin * * @return array */ - protected function formNew() + protected function formNew(): array { return [ 'action' => $this->c->Router->link('AdminGroupsNew'), @@ -98,7 +99,7 @@ class Groups extends Admin * * @return array */ - protected function formDefault() + protected function formDefault(): array { return [ 'action' => $this->c->Router->link('AdminGroupsDefault'), @@ -134,7 +135,7 @@ class Groups extends Admin * * @return Page */ - public function defaultSet() + public function defaultSet(): Page { $v = $this->c->Validator->reset() ->addRules([ @@ -163,7 +164,7 @@ class Groups extends Admin * * @return Page */ - public function edit(array $args, $method) + public function edit(array $args, string $method): Page { // начало создания новой группы if (empty($args['id']) && empty($args['base'])) { @@ -295,7 +296,7 @@ class Groups extends Admin * * @return Page */ - public function save(Group $group, Group $baseGroup, array $data) + public function save(Group $group, Group $baseGroup, array $data): Page { if (! $group->groupAdmin && isset($data['g_moderator']) && 0 === $data['g_moderator']) { $data['g_mod_edit_users'] = 0; @@ -341,7 +342,7 @@ class Groups extends Admin * * @return array */ - protected function formEdit(array $args, Group $group, $marker) + protected function formEdit(array $args, Group $group, string $marker): array { $form = [ 'action' => $this->c->Router->link($marker, $args), @@ -629,7 +630,7 @@ class Groups extends Admin * * @return Page */ - public function delete(array $args, $method) + public function delete(array $args, string $method): Page { $group = $this->c->groups->get((int) $args['id']); @@ -698,7 +699,7 @@ class Groups extends Admin * * @return array */ - protected function formDelete(array $args, Group $group, $count, array $groups) + protected function formDelete(array $args, Group $group, int $count, array $groups): array { $form = [ 'action' => $this->c->Router->link('AdminGroupsDelete', $args), diff --git a/app/Models/Pages/Admin/Host.php b/app/Models/Pages/Admin/Host.php index 6ecdb336..5b52385d 100644 --- a/app/Models/Pages/Admin/Host.php +++ b/app/Models/Pages/Admin/Host.php @@ -2,6 +2,7 @@ namespace ForkBB\Models\Pages\Admin; +use ForkBB\Models\Page; use ForkBB\Models\Pages\Admin; class Host extends Admin @@ -14,7 +15,7 @@ class Host extends Admin * * @return Page */ - public function view(array $args, $method) + public function view(array $args, string $method): Page { $this->c->Lang->load('admin_host'); diff --git a/app/Models/Pages/Admin/Index.php b/app/Models/Pages/Admin/Index.php index 6702b6be..c1cfa7e1 100644 --- a/app/Models/Pages/Admin/Index.php +++ b/app/Models/Pages/Admin/Index.php @@ -2,6 +2,7 @@ namespace ForkBB\Models\Pages\Admin; +use ForkBB\Models\Page; use ForkBB\Models\Pages\Admin; class Index extends Admin @@ -11,7 +12,7 @@ class Index extends Admin * * @return Page */ - public function index() + public function index(): Page { $this->c->Lang->load('admin_index'); diff --git a/app/Models/Pages/Admin/Maintenance.php b/app/Models/Pages/Admin/Maintenance.php index d1d98fd2..d5c8e3c5 100644 --- a/app/Models/Pages/Admin/Maintenance.php +++ b/app/Models/Pages/Admin/Maintenance.php @@ -3,6 +3,7 @@ namespace ForkBB\Models\Pages\Admin; use ForkBB\Core\Validator; +use ForkBB\Models\Page; use ForkBB\Models\Pages\Admin; use ForkBB\Models\Config\Model as Config; @@ -16,7 +17,7 @@ class Maintenance extends Admin * * @return Page */ - public function view(array $args, $method) + public function view(array $args, string $method): Page { $this->c->Lang->load('admin_maintenance'); @@ -61,7 +62,7 @@ class Maintenance extends Admin * * @return array */ - protected function formMaintenance(Config $config) + protected function formMaintenance(Config $config): array { return [ 'action' => $this->c->Router->link('AdminMaintenance'), @@ -103,7 +104,7 @@ class Maintenance extends Admin * * @return array */ - protected function formRebuild() + protected function formRebuild(): array { return [ 'action' => $this->c->Router->link('AdminMaintenanceRebuild'), @@ -193,7 +194,7 @@ class Maintenance extends Admin * * @return Page */ - public function rebuild(array $args, $method) + public function rebuild(array $args, string $method): Page { $this->c->Lang->load('admin_maintenance'); diff --git a/app/Models/Pages/Admin/Options.php b/app/Models/Pages/Admin/Options.php index ddac0726..cf8fbdd6 100644 --- a/app/Models/Pages/Admin/Options.php +++ b/app/Models/Pages/Admin/Options.php @@ -3,6 +3,7 @@ namespace ForkBB\Models\Pages\Admin; use ForkBB\Core\Validator; +use ForkBB\Models\Page; use ForkBB\Models\Pages\Admin; use ForkBB\Models\Config\Model as Config; @@ -16,7 +17,7 @@ class Options extends Admin * * @return Page */ - public function edit(array $args, $method) + public function edit(array $args, string $method): Page { $this->c->Lang->load('admin_options'); $this->c->Lang->load('profile_other'); @@ -179,7 +180,7 @@ class Options extends Admin * * @return array */ - protected function formEdit(Config $config) + protected function formEdit(Config $config): array { $form = [ 'action' => $this->c->Router->link('AdminOptions'), diff --git a/app/Models/Pages/Admin/Permissions.php b/app/Models/Pages/Admin/Permissions.php index ebda3d18..20ca922f 100644 --- a/app/Models/Pages/Admin/Permissions.php +++ b/app/Models/Pages/Admin/Permissions.php @@ -3,6 +3,7 @@ namespace ForkBB\Models\Pages\Admin; use ForkBB\Core\Validator; +use ForkBB\Models\Page; use ForkBB\Models\Pages\Admin; use ForkBB\Models\Config\Model as Config; @@ -16,7 +17,7 @@ class Permissions extends Admin * * @return Page */ - public function edit(array $args, $method) + public function edit(array $args, string $method): Page { $this->c->Lang->load('admin_permissions'); @@ -76,7 +77,7 @@ class Permissions extends Admin * * @return array */ - protected function formEdit(Config $config) + protected function formEdit(Config $config): array { $form = [ 'action' => $this->c->Router->link('AdminPermissions'), diff --git a/app/Models/Pages/Admin/Statistics.php b/app/Models/Pages/Admin/Statistics.php index 6c5b3c8d..9440214f 100644 --- a/app/Models/Pages/Admin/Statistics.php +++ b/app/Models/Pages/Admin/Statistics.php @@ -2,6 +2,7 @@ namespace ForkBB\Models\Pages\Admin; +use ForkBB\Models\Page; use ForkBB\Models\Pages\Admin; class Statistics extends Admin @@ -11,7 +12,7 @@ class Statistics extends Admin * * @return Page */ - public function info() + public function info(): Page { // Is phpinfo() a disabled function? if (\strpos(\strtolower((string) \ini_get('disable_functions')), 'phpinfo') !== false) { @@ -59,7 +60,7 @@ class Statistics extends Admin * * @return Page */ - public function statistics() + public function statistics(): Page { $this->c->Lang->load('admin_index'); diff --git a/app/Models/Pages/Admin/Users.php b/app/Models/Pages/Admin/Users.php index cb199c6a..6490a232 100644 --- a/app/Models/Pages/Admin/Users.php +++ b/app/Models/Pages/Admin/Users.php @@ -5,7 +5,6 @@ namespace ForkBB\Models\Pages\Admin; use ForkBB\Core\Container; use ForkBB\Models\Pages\Admin; use ForkBB\Models\User\Model as User; -use ForkBB\Models\Rules; abstract class Users extends Admin { @@ -34,7 +33,7 @@ abstract class Users extends Admin * * @return string */ - protected function encodeData($data) + protected function encodeData($data): string { if (\is_array($data)) { unset($data['token']); @@ -53,7 +52,7 @@ abstract class Users extends Admin * * @return mixed */ - protected function decodeData($data) + protected function decodeData(string $data) { $data = \explode(':', $data); @@ -84,7 +83,7 @@ abstract class Users extends Admin * * @return false|array */ - protected function checkSelected(array $selected, $action, $profile = false) + protected function checkSelected(array $selected, string $action, bool $profile = false) { $selected = \array_map(function ($value) { // ???? return (int) $value; diff --git a/app/Models/Pages/Admin/Users/Action.php b/app/Models/Pages/Admin/Users/Action.php index b0e86d61..75e48712 100644 --- a/app/Models/Pages/Admin/Users/Action.php +++ b/app/Models/Pages/Admin/Users/Action.php @@ -3,6 +3,7 @@ namespace ForkBB\Models\Pages\Admin\Users; use ForkBB\Core\Validator; +use ForkBB\Models\Page; use ForkBB\Models\Pages\Admin\Users; use RuntimeException; @@ -15,7 +16,7 @@ class Action extends Users * * @return array */ - protected function nameList(array $users) + protected function nameList(array $users): array { $result = []; foreach ($users as $user) { @@ -35,7 +36,7 @@ class Action extends Users * * @return Page */ - public function view(array $args, $method) + public function view(array $args, string $method): Page { if (isset($args['token'])) { if (! $this->c->Csrf->verify($args['token'], 'AdminUsersAction', $args)) { @@ -105,7 +106,7 @@ class Action extends Users * * @return Page */ - protected function delete(array $args, $method) + protected function delete(array $args, string $method): Page { if ('POST' === $method) { $v = $this->c->Validator->reset() @@ -152,7 +153,7 @@ class Action extends Users * * @return array */ - protected function formDelete(array $args) + protected function formDelete(array $args): array { $yn = [1 => \ForkBB\__('Yes'), 0 => \ForkBB\__('No')]; $names = \implode(', ', $this->nameList($this->userList)); @@ -213,7 +214,7 @@ class Action extends Users * * @return array */ - protected function groupListForChange($profile) + protected function groupListForChange(bool $profile): array { $list = []; foreach ($this->c->groups->getList() as $id => $group) { @@ -237,7 +238,7 @@ class Action extends Users * * @return Page */ - protected function change(array $args, $method, $profile) + protected function change(array $args, string $method, bool $profile): Page { $rulePass = 'absent'; @@ -330,7 +331,7 @@ class Action extends Users * * @return array */ - protected function formChange(array $args, $profile, $linkCancel, $checkPass) + protected function formChange(array $args, bool $profile, string $linkCancel, bool $checkPass): array { $yn = [1 => \ForkBB\__('Yes'), 0 => \ForkBB\__('No')]; $names = \implode(', ', $this->nameList($this->userList)); diff --git a/app/Models/Pages/Admin/Users/Promote.php b/app/Models/Pages/Admin/Users/Promote.php index 5f234d6f..9ef80aa2 100644 --- a/app/Models/Pages/Admin/Users/Promote.php +++ b/app/Models/Pages/Admin/Users/Promote.php @@ -2,6 +2,7 @@ namespace ForkBB\Models\Pages\Admin\Users; +use ForkBB\Models\Page; use ForkBB\Models\Pages\Admin\Users; class Promote extends Users @@ -14,7 +15,7 @@ class Promote extends Users * * @return Page */ - public function promote(array $args, $method) + public function promote(array $args, string $method): Page { if (! $this->c->Csrf->verify($args['token'], 'AdminUserPromote', $args)) { return $this->c->Message->message('Bad token'); diff --git a/app/Models/Pages/Admin/Users/Result.php b/app/Models/Pages/Admin/Users/Result.php index d4a266fe..0ecd668c 100644 --- a/app/Models/Pages/Admin/Users/Result.php +++ b/app/Models/Pages/Admin/Users/Result.php @@ -3,6 +3,7 @@ namespace ForkBB\Models\Pages\Admin\Users; use ForkBB\Core\Validator; +use ForkBB\Models\Page; use ForkBB\Models\Pages\Admin\Users; use ForkBB\Models\User\Model as User; @@ -16,7 +17,7 @@ class Result extends Users * * @return Page */ - public function view(array $args, $method) + public function view(array $args, string $method): Page { $data = $this->decodeData($args['data']); if (false === $data) { @@ -136,7 +137,7 @@ class Result extends Users * * @return array */ - protected function forIP($ip) + protected function forIP(string $ip): array { $fromPosts = $this->c->posts->userInfoFromIP($ip); $ids = $this->c->users->filter([ @@ -161,7 +162,7 @@ class Result extends Users * * @return array */ - protected function forFilter(array $data) + protected function forFilter(array $data): array { $order = [ $data['order_by'] => $data['direction'], @@ -208,7 +209,7 @@ class Result extends Users * * @return array */ - protected function form(array $users, $number, array $args) + protected function form(array $users, int $number, array $args): array { $form = [ 'action' => $this->c->Router->link('AdminUsersResult', $args), diff --git a/app/Models/Pages/Admin/Users/Stat.php b/app/Models/Pages/Admin/Users/Stat.php index 1cf7d0d9..ca7ba010 100644 --- a/app/Models/Pages/Admin/Users/Stat.php +++ b/app/Models/Pages/Admin/Users/Stat.php @@ -3,6 +3,7 @@ namespace ForkBB\Models\Pages\Admin\Users; use ForkBB\Core\Validator; +use ForkBB\Models\Page; use ForkBB\Models\Pages\Admin\Users; class Stat extends Users @@ -15,7 +16,7 @@ class Stat extends Users * * @return Page */ - public function view(array $args, $method) + public function view(array $args, string $method): Page { $stat = $this->c->posts->userStat((int) $args['id']); $number = \count($stat); @@ -53,7 +54,7 @@ class Stat extends Users * * @return array */ - protected function form(array $stat, $number) + protected function form(array $stat, int $number): array { $form = [ 'action' => null, diff --git a/app/Models/Pages/Admin/Users/View.php b/app/Models/Pages/Admin/Users/View.php index 40c205e6..240d0ff0 100644 --- a/app/Models/Pages/Admin/Users/View.php +++ b/app/Models/Pages/Admin/Users/View.php @@ -3,6 +3,7 @@ namespace ForkBB\Models\Pages\Admin\Users; use ForkBB\Core\Validator; +use ForkBB\Models\Page; use ForkBB\Models\Pages\Admin\Users; class View extends Users @@ -14,7 +15,7 @@ class View extends Users * * @return array */ - protected function groups($onlyKeys = false) + protected function groups(bool $onlyKeys = false): array { $groups = [ -1 => \ForkBB\__('All groups'), @@ -39,7 +40,7 @@ class View extends Users * * @return Page */ - public function view(array $args, $method, array $data = []) + public function view(array $args, string $method, array $data = []): Page { if ('POST' === $method) { $v = $this->c->Validator->reset() @@ -133,7 +134,7 @@ class View extends Users * * @return array */ - protected function form(array $data) + protected function form(array $data): array { $form = [ 'action' => $this->c->Router->link('AdminUsers'), @@ -359,7 +360,7 @@ class View extends Users * * @return array */ - protected function formIP(array $data) + protected function formIP(array $data): array { $form = [ 'action' => $this->c->Router->link('AdminUsers'), diff --git a/app/Models/Pages/Auth.php b/app/Models/Pages/Auth.php index a8597f0e..e1d8f49e 100644 --- a/app/Models/Pages/Auth.php +++ b/app/Models/Pages/Auth.php @@ -16,7 +16,7 @@ class Auth extends Page * * @return Page */ - public function logout($args) + public function logout(array $args): Page { if (! $this->c->Csrf->verify($args['token'], 'Logout', $args)) { return $this->c->Redirect->page('Index')->message('Bad token'); @@ -38,7 +38,7 @@ class Auth extends Page * * @return Page */ - public function login(array $args, $method) + public function login(array $args, string $method): Page { $this->c->Lang->load('auth'); @@ -91,7 +91,7 @@ class Auth extends Page * * @return array */ - protected function formLogin($username, $save, $redirect) + protected function formLogin(string $username, $save, string $redirect): array { return [ 'action' => $this->c->Router->link('Login'), @@ -188,7 +188,7 @@ class Auth extends Page * * @return Page */ - public function forget(array $args, $method) + public function forget(array $args, string $method): Page { $this->c->Lang->load('auth'); @@ -267,7 +267,7 @@ class Auth extends Page * * @return array */ - protected function formForget($email) + protected function formForget(string $email): array { return [ 'action' => $this->c->Router->link('Forget'), @@ -308,7 +308,7 @@ class Auth extends Page * * @return Page */ - public function changePass(array $args, $method) + public function changePass(array $args, string $method): Page { if (! \hash_equals($args['hash'], $this->c->Secury->hash($args['id'] . $args['key'])) || ! ($user = $this->c->users->load((int) $args['id'])) instanceof User @@ -378,7 +378,7 @@ class Auth extends Page * * @return array */ - protected function formChange(array $args) + protected function formChange(array $args): array { return [ 'action' => $this->c->Router->link('ChangePassword', $args), diff --git a/app/Models/Pages/Ban.php b/app/Models/Pages/Ban.php index efe32a68..ba299d4e 100644 --- a/app/Models/Pages/Ban.php +++ b/app/Models/Pages/Ban.php @@ -14,7 +14,7 @@ class Ban extends Page * * @return Page */ - public function ban(User $user) + public function ban(User $user): Page { $this->httpStatus = 403; $this->nameTpl = 'ban'; @@ -31,7 +31,7 @@ class Ban extends Page /** * Подготовка страницы к отображению */ - public function prepare() + public function prepare(): void { } } diff --git a/app/Models/Pages/Debug.php b/app/Models/Pages/Debug.php index df01c810..d5075c16 100644 --- a/app/Models/Pages/Debug.php +++ b/app/Models/Pages/Debug.php @@ -11,7 +11,7 @@ class Debug extends Page * * @return Page */ - public function debug() + public function debug(): Page { if ($this->c->isInit('DB')) { $this->numQueries = $this->c->DB->getCount(); @@ -41,7 +41,7 @@ class Debug extends Page /** * Подготовка страницы к отображению */ - public function prepare() + public function prepare(): void { } @@ -51,7 +51,7 @@ class Debug extends Page * * @return array */ - protected function getHttpHeaders() + protected function getHttpHeaders(): array { return []; } diff --git a/app/Models/Pages/Delete.php b/app/Models/Pages/Delete.php index 7bc846a4..409223cb 100644 --- a/app/Models/Pages/Delete.php +++ b/app/Models/Pages/Delete.php @@ -15,7 +15,7 @@ class Delete extends Page * * @return Page */ - public function delete(array $args, $method) + public function delete(array $args, string $method): Page { $post = $this->c->posts->load((int) $args['id']); @@ -76,7 +76,7 @@ class Delete extends Page * * @return array */ - protected function formDelete(array $args, Post $post, $deleteTopic) + protected function formDelete(array $args, Post $post, bool $deleteTopic): array { return [ 'action' => $this->c->Router->link('DeletePost', ['id' => $post->id]), diff --git a/app/Models/Pages/Edit.php b/app/Models/Pages/Edit.php index 13c8fbb8..ed27f337 100644 --- a/app/Models/Pages/Edit.php +++ b/app/Models/Pages/Edit.php @@ -3,8 +3,8 @@ namespace ForkBB\Models\Pages; use ForkBB\Core\Validator; -use ForkBB\Models\Post\Model as Post; use ForkBB\Models\Page; +use ForkBB\Models\Post\Model as Post; class Edit extends Page { @@ -19,7 +19,7 @@ class Edit extends Page * * @return Page */ - public function edit(array $args, $method) + public function edit(array $args, string $method): Page { $post = $this->c->posts->load((int) $args['id']); @@ -75,7 +75,7 @@ class Edit extends Page * * @return Page */ - protected function endEdit(Post $post, Validator $v) + protected function endEdit(Post $post, Validator $v): Page { $now = \time(); $executive = $this->user->isAdmin || $this->user->isModerator($post); diff --git a/app/Models/Pages/Forum.php b/app/Models/Pages/Forum.php index 51982f0e..cd44d982 100644 --- a/app/Models/Pages/Forum.php +++ b/app/Models/Pages/Forum.php @@ -13,7 +13,7 @@ class Forum extends Page * * @return Page */ - public function view(array $args) + public function view(array $args): Page { $this->c->Lang->load('forum'); $this->c->Lang->load('subforums'); diff --git a/app/Models/Pages/Index.php b/app/Models/Pages/Index.php index 98786483..ca34a751 100644 --- a/app/Models/Pages/Index.php +++ b/app/Models/Pages/Index.php @@ -11,7 +11,7 @@ class Index extends Page * * @return Page */ - public function view() + public function view(): Page { $this->c->Lang->load('index'); $this->c->Lang->load('subforums'); diff --git a/app/Models/Pages/Install.php b/app/Models/Pages/Install.php index ce4ced8e..954ad241 100644 --- a/app/Models/Pages/Install.php +++ b/app/Models/Pages/Install.php @@ -30,7 +30,7 @@ class Install extends Page * * @return array */ - protected function DBTypes() + protected function DBTypes(): array { $dbTypes = []; $pdoDrivers = PDO::getAvailableDrivers(); @@ -63,7 +63,7 @@ class Install extends Page * * @return Page */ - public function install(array $args, $method) + public function install(array $args, string $method): Page { $changeLang = false; if ('POST' === $method) { @@ -489,7 +489,7 @@ class Install extends Page * * @return Page */ - protected function installEnd(Validator $v) + protected function installEnd(Validator $v): Page { @\set_time_limit(0); $this->c->Cache->clear(); diff --git a/app/Models/Pages/Maintenance.php b/app/Models/Pages/Maintenance.php index 76f387b4..5b6b004f 100644 --- a/app/Models/Pages/Maintenance.php +++ b/app/Models/Pages/Maintenance.php @@ -32,7 +32,7 @@ class Maintenance extends Page /** * Подготовка страницы к отображению */ - public function prepare() + public function prepare(): void { } } diff --git a/app/Models/Pages/Message.php b/app/Models/Pages/Message.php index 63529aeb..874c91d1 100644 --- a/app/Models/Pages/Message.php +++ b/app/Models/Pages/Message.php @@ -12,10 +12,11 @@ class Message extends Page * @param string $message * @param bool $back * @param int $status + * @param array $headers * * @return Page */ - public function message($message, $back = true, $status = 404, array $headers = []) + public function message(string $message, bool $back = true, int $status = 404, array $headers = []): Page { $this->nameTpl = 'message'; $this->httpStatus = \max(200, $status); diff --git a/app/Models/Pages/Misc.php b/app/Models/Pages/Misc.php index 709ea6da..963599a3 100644 --- a/app/Models/Pages/Misc.php +++ b/app/Models/Pages/Misc.php @@ -13,7 +13,7 @@ class Misc extends Page * * @return Page */ - public function markread(array $args) + public function markread(array $args): Page { $forum = $this->c->forums->loadTree($args['id']); if (null === $forum) { diff --git a/app/Models/Pages/Post.php b/app/Models/Pages/Post.php index 26a478f2..4381c7d3 100644 --- a/app/Models/Pages/Post.php +++ b/app/Models/Pages/Post.php @@ -4,9 +4,8 @@ namespace ForkBB\Models\Pages; use ForkBB\Core\Validator; use ForkBB\Models\Model; -use ForkBB\Models\Forum; -use ForkBB\Models\Topic\Model as Topic; use ForkBB\Models\Page; +use ForkBB\Models\Topic\Model as Topic; class Post extends Page { @@ -21,7 +20,7 @@ class Post extends Page * * @return Page */ - public function newTopic(array $args, $method) + public function newTopic(array $args, string $method): Post { $forum = $this->c->forums->get((int) $args['id']); @@ -65,7 +64,7 @@ class Post extends Page * * @return Page */ - public function newReply(array $args, $method) + public function newReply(array $args, string $method): Post { $topic = $this->c->topics->load((int) $args['id']); @@ -122,7 +121,7 @@ class Post extends Page * * @return Page */ - protected function endPost(Model $model, Validator $v) + protected function endPost(Model $model, Validator $v): Post { $now = \time(); $username = $this->user->isGuest ? $v->username : $this->user->username; diff --git a/app/Models/Pages/PostFormTrait.php b/app/Models/Pages/PostFormTrait.php index 70ca2983..70f61298 100644 --- a/app/Models/Pages/PostFormTrait.php +++ b/app/Models/Pages/PostFormTrait.php @@ -18,7 +18,7 @@ trait PostFormTrait * * @return array */ - protected function messageForm(array $args, Model $model, $marker, $editPost = false, $editSubject = false, $quickReply = false) + protected function messageForm(array $args, Model $model, string $marker, bool $editPost = false, bool $editSubject = false, bool $quickReply = false): array { $vars = isset($args['_vars']) ? $args['_vars'] : null; unset($args['_vars']); diff --git a/app/Models/Pages/PostValidatorTrait.php b/app/Models/Pages/PostValidatorTrait.php index 671653f7..eebd8312 100644 --- a/app/Models/Pages/PostValidatorTrait.php +++ b/app/Models/Pages/PostValidatorTrait.php @@ -97,7 +97,7 @@ trait PostValidatorTrait * * @return Validator */ - protected function messageValidator(Model $model, $marker, array $args, $editPost = false, $editSubject = false) + protected function messageValidator(Model $model, string $marker, array $args, bool $editPost = false, bool $editSubject = false): Validator { if ($this->user->isGuest) { $ruleEmail = ('1' == $this->c->config->p_force_guest_email ? 'required|' : '') . 'string:trim|email:noban'; diff --git a/app/Models/Pages/Profile.php b/app/Models/Pages/Profile.php index 1dc3ebf3..af5144ec 100644 --- a/app/Models/Pages/Profile.php +++ b/app/Models/Pages/Profile.php @@ -15,7 +15,7 @@ abstract class Profile extends Page * * @return bool */ - protected function initProfile($id) + protected function initProfile($id): bool { $this->curUser = $this->c->users->load((int) $id); @@ -63,7 +63,7 @@ abstract class Profile extends Page * * @return array */ - protected function crumbs(...$crumbs) + protected function crumbs(...$crumbs): array { $crumbs[] = [$this->curUser->link, \ForkBB\__('User %s', $this->curUser->username)]; $crumbs[] = [$this->c->Router->link('Userlist'), \ForkBB\__('User list')]; @@ -78,7 +78,7 @@ abstract class Profile extends Page * * @return array */ - protected function btns($type) + protected function btns(string $type): array { $btns = []; if ($this->user->isAdmin && ! $this->rules->editProfile) { @@ -143,7 +143,7 @@ abstract class Profile extends Page * * @return string */ - protected function linkChangeGroup() + protected function linkChangeGroup(): string { return $this->c->Router->link('AdminUsersAction', [ 'action' => 'change_group', diff --git a/app/Models/Pages/Profile/Config.php b/app/Models/Pages/Profile/Config.php index 03932041..0241029b 100644 --- a/app/Models/Pages/Profile/Config.php +++ b/app/Models/Pages/Profile/Config.php @@ -3,6 +3,7 @@ namespace ForkBB\Models\Pages\Profile; use ForkBB\Core\Validator; +use ForkBB\Models\Page; use ForkBB\Models\Pages\Profile; class Config extends Profile @@ -15,7 +16,7 @@ class Config extends Profile * * @return Page */ - public function config(array $args, $method) + public function config(array $args, string $method): Page { if (false === $this->initProfile($args['id']) || ! $this->rules->editConfig) { return $this->c->Message->message('Bad request'); @@ -100,7 +101,7 @@ class Config extends Profile * * @return array */ - protected function form() + protected function form(): array { $form = [ 'action' => $this->c->Router->link('EditUserBoardConfig', ['id' => $this->curUser->id]), diff --git a/app/Models/Pages/Profile/Edit.php b/app/Models/Pages/Profile/Edit.php index b01cd7a2..4486d6ac 100644 --- a/app/Models/Pages/Profile/Edit.php +++ b/app/Models/Pages/Profile/Edit.php @@ -5,6 +5,7 @@ namespace ForkBB\Models\Pages\Profile; use ForkBB\Core\Image; use ForkBB\Core\Validator; use ForkBB\Core\Exceptions\MailException; +use ForkBB\Models\Page; use ForkBB\Models\Pages\Profile; use ForkBB\Models\User\Model as User; @@ -18,7 +19,7 @@ class Edit extends Profile * * @return Page */ - public function edit(array $args, $method) + public function edit(array $args, string $method): Page { if (false === $this->initProfile($args['id']) || ! $this->rules->editProfile) { return $this->c->Message->message('Bad request'); @@ -177,7 +178,7 @@ class Edit extends Profile * * @return array */ - protected function form() + protected function form(): array { $form = [ 'action' => $this->c->Router->link('EditUserProfile', ['id' => $this->curUser->id]), diff --git a/app/Models/Pages/Profile/Email.php b/app/Models/Pages/Profile/Email.php index 72db5569..163b2176 100644 --- a/app/Models/Pages/Profile/Email.php +++ b/app/Models/Pages/Profile/Email.php @@ -4,6 +4,7 @@ namespace ForkBB\Models\Pages\Profile; use ForkBB\Core\Validator; use ForkBB\Core\Exceptions\MailException; +use ForkBB\Models\Page; use ForkBB\Models\Pages\Profile; use ForkBB\Models\User\Model as User; @@ -17,7 +18,7 @@ class Email extends Profile * * @return Page */ - public function setEmail(array $args, $method) + public function setEmail(array $args, string $method): Page { if ($this->user->id !== (int) $args['id'] || ! \hash_equals($args['hash'], $this->c->Secury->hash($args['id'] . $args['email'] . $args['key'])) @@ -46,7 +47,7 @@ class Email extends Profile * * @return Page */ - public function email(array $args, $method) + public function email(array $args, string $method): Page { if (false === $this->initProfile($args['id']) || ! $this->rules->editEmail) { return $this->c->Message->message('Bad request'); @@ -139,7 +140,7 @@ class Email extends Profile * * @return array */ - protected function form() + protected function form(): array { $form = [ 'action' => $this->c->Router->link('EditUserEmail', ['id' => $this->curUser->id]), diff --git a/app/Models/Pages/Profile/Mod.php b/app/Models/Pages/Profile/Mod.php index 75ccf752..3a73658e 100644 --- a/app/Models/Pages/Profile/Mod.php +++ b/app/Models/Pages/Profile/Mod.php @@ -4,6 +4,7 @@ namespace ForkBB\Models\Pages\Profile; use ForkBB\Core\Image; use ForkBB\Core\Validator; +use ForkBB\Models\Page; use ForkBB\Models\Pages\Profile; use ForkBB\Models\User\Model as User; use ForkBB\Models\Forum\Model as Forum; @@ -19,7 +20,7 @@ class Mod extends Profile * * @return Page */ - public function moderation(array $args, $method) + public function moderation(array $args, string $method): Page { if (false === $this->initProfile($args['id']) || ! $this->rules->confModer) { return $this->c->Message->message('Bad request'); @@ -70,7 +71,7 @@ class Mod extends Profile * * @return array */ - protected function getcurForums() + protected function getcurForums(): array { $forums = new ForumManager($this->c); $forums->init($this->c->groups->get($this->curUser->group_id)); @@ -84,7 +85,7 @@ class Mod extends Profile * * @return array */ - protected function form() + protected function form(): array { $form = [ 'action' => $this->c->Router->link('EditUserModeration', ['id' => $this->curUser->id]), diff --git a/app/Models/Pages/Profile/Pass.php b/app/Models/Pages/Profile/Pass.php index ae85dc86..2cfb2f9f 100644 --- a/app/Models/Pages/Profile/Pass.php +++ b/app/Models/Pages/Profile/Pass.php @@ -5,6 +5,7 @@ namespace ForkBB\Models\Pages\Profile; use ForkBB\Core\Image; use ForkBB\Core\Validator; use ForkBB\Core\Exceptions\MailException; +use ForkBB\Models\Page; use ForkBB\Models\Pages\Profile; use ForkBB\Models\User\Model as User; @@ -18,7 +19,7 @@ class Pass extends Profile * * @return Page */ - public function pass(array $args, $method) + public function pass(array $args, string $method): Page { if (false === $this->initProfile($args['id']) || ! $this->rules->editPass) { return $this->c->Message->message('Bad request'); @@ -76,7 +77,7 @@ class Pass extends Profile * * @return array */ - protected function form() + protected function form(): array { $form = [ 'action' => $this->c->Router->link('EditUserPass', ['id' => $this->curUser->id]), diff --git a/app/Models/Pages/Profile/View.php b/app/Models/Pages/Profile/View.php index 45517477..529a4d06 100644 --- a/app/Models/Pages/Profile/View.php +++ b/app/Models/Pages/Profile/View.php @@ -2,6 +2,7 @@ namespace ForkBB\Models\Pages\Profile; +use ForkBB\Models\Page; use ForkBB\Models\Pages\Profile; class View extends Profile @@ -14,7 +15,7 @@ class View extends Profile * * @return Page */ - public function view(array $args, $method) + public function view(array $args, string $method): Page { if (false === $this->initProfile($args['id'])) { return $this->c->Message->message('Bad request'); @@ -34,7 +35,7 @@ class View extends Profile * * @return array */ - protected function form() + protected function form(): array { $form = [ 'sets' => [] diff --git a/app/Models/Pages/Redirect.php b/app/Models/Pages/Redirect.php index c4b9cc18..565ab906 100644 --- a/app/Models/Pages/Redirect.php +++ b/app/Models/Pages/Redirect.php @@ -11,7 +11,7 @@ class Redirect extends Page * * @return Page */ - public function toIndex() + public function toIndex(): Page { return $this->page('Index'); //->message('Redirecting to index'); } @@ -24,7 +24,7 @@ class Redirect extends Page * * @return Page */ - public function page($marker, array $args = []) + public function page(string $marker, array $args = []): Page { $this->link = $this->c->Router->link($marker, $args); return $this; @@ -37,7 +37,7 @@ class Redirect extends Page * * @return Page */ - public function url($url) + public function url(string $url): Page { $this->link = $url; return $this; @@ -50,7 +50,7 @@ class Redirect extends Page * * @return Page */ - public function message($message) + public function message(string $message): Page { // переадресация без вывода сообщения if ($this->c->config->o_redirect_delay == '0') { @@ -72,7 +72,7 @@ class Redirect extends Page * * @return array */ - protected function getHttpHeaders() + protected function getHttpHeaders(): array { if (null === $this->nameTpl) { $this->header('Location', $this->link); @@ -83,7 +83,7 @@ class Redirect extends Page /** * Подготовка страницы к отображению */ - public function prepare() + public function prepare(): void { } } diff --git a/app/Models/Pages/Register.php b/app/Models/Pages/Register.php index 7df4077a..f32e573e 100644 --- a/app/Models/Pages/Register.php +++ b/app/Models/Pages/Register.php @@ -14,7 +14,7 @@ class Register extends Page * * @return Page */ - public function reg() + public function reg(): Page { $this->c->Lang->load('register'); @@ -67,7 +67,7 @@ class Register extends Page * * @return array */ - protected function formReg(Validator $v) + protected function formReg(Validator $v): array { return [ 'action' => $this->c->Router->link('RegisterForm'), @@ -128,7 +128,7 @@ class Register extends Page * * @return Page */ - protected function regEnd(Validator $v) + protected function regEnd(Validator $v): Page { if ('1' == $this->c->config->o_regs_verify) { $groupId = 0; @@ -233,7 +233,7 @@ class Register extends Page * * @return Page */ - public function activate(array $args) + public function activate(array $args): Page { if (! \hash_equals($args['hash'], $this->c->Secury->hash($args['id'] . $args['key'])) || ! ($user = $this->c->users->load($args['id'])) instanceof User diff --git a/app/Models/Pages/Report.php b/app/Models/Pages/Report.php index 185f3ea6..84829954 100644 --- a/app/Models/Pages/Report.php +++ b/app/Models/Pages/Report.php @@ -17,7 +17,7 @@ class Report extends Page * * @return Page */ - public function report(array $args, $method) + public function report(array $args, string $method): Page { $post = $this->c->posts->load((int) $args['id']); @@ -105,7 +105,7 @@ class Report extends Page * * @return array */ - protected function formReport(array $args, array $data) + protected function formReport(array $args, array $data): array { return [ 'action' => $this->c->Router->link('ReportPost', $args), @@ -149,7 +149,7 @@ class Report extends Page * * @return bool */ - protected function sendReport(ReportModel $report) + protected function sendReport(ReportModel $report): bool { $tplData = [ 'fMailer' => \ForkBB\__('Mailer', $this->c->config->o_board_title), diff --git a/app/Models/Pages/Rules.php b/app/Models/Pages/Rules.php index 42eae80a..322bea33 100644 --- a/app/Models/Pages/Rules.php +++ b/app/Models/Pages/Rules.php @@ -11,7 +11,7 @@ class Rules extends Page * * @return Page */ - public function view() + public function view(): Page { $this->fIndex = 'rules'; $this->nameTpl = 'rules'; @@ -29,7 +29,7 @@ class Rules extends Page * * @return Page */ - public function confirmation() + public function confirmation(): Page { $this->c->Lang->load('register'); @@ -50,7 +50,7 @@ class Rules extends Page * * @return array */ - protected function formAgree() + protected function formAgree(): array { return [ 'action' => $this->c->Router->link('RegisterForm'), diff --git a/app/Models/Pages/Search.php b/app/Models/Pages/Search.php index 9fee398c..d49c3418 100644 --- a/app/Models/Pages/Search.php +++ b/app/Models/Pages/Search.php @@ -2,8 +2,8 @@ namespace ForkBB\Models\Pages; -use ForkBB\Models\Page; use ForkBB\Core\Validator; +use ForkBB\Models\Page; use ForkBB\Models\Forum\Model as Forum; use ForkBB\Models\User\Model as User; use InvalidArgumentException; @@ -13,7 +13,7 @@ class Search extends Page /** * Составление списка категорий/разделов для выбора */ - protected function calcList() + protected function calcList(): void { $cid = null; $options = []; @@ -48,7 +48,7 @@ class Search extends Page * * @return Page */ - public function viewAdvanced(array $args, $method) + public function viewAdvanced(array $args, string $method): Page { return $this->view($args, $method, true); } @@ -62,7 +62,7 @@ class Search extends Page * * @return Page */ - public function view(array $args, $method, $advanced = false) + public function view(array $args, string $method, bool $advanced = false): Page { $this->c->Lang->load('search'); $this->calcList(); @@ -143,7 +143,7 @@ class Search extends Page * * @return array */ - protected function formSearch(Validator $v = null) + protected function formSearch(Validator $v = null): array { return [ 'action' => $this->c->Router->link('Search'), @@ -187,7 +187,7 @@ class Search extends Page * * @return array */ - protected function formSearchAdvanced(Validator $v = null) + protected function formSearchAdvanced(Validator $v = null): array { return [ 'action' => $this->c->Router->link('SearchAdvanced'), @@ -417,7 +417,7 @@ class Search extends Page * * @return Page */ - public function action(array $args, $method, $advanced = false) + public function action(array $args, string $method, bool $advanced = false): Page { $this->c->Lang->load('search'); @@ -541,7 +541,7 @@ class Search extends Page * * @return array */ - protected function crumbs(...$crumbs) + protected function crumbs(...$crumbs): array { $crumbs[] = [$this->c->Router->link('Search'), \ForkBB\__('Search')]; return parent::crumbs(...$crumbs); diff --git a/app/Models/Pages/Topic.php b/app/Models/Pages/Topic.php index 7c365583..3d0679d0 100644 --- a/app/Models/Pages/Topic.php +++ b/app/Models/Pages/Topic.php @@ -16,7 +16,7 @@ class Topic extends Page * * @return Page */ - public function viewNew(array $args) + public function viewNew(array $args): Page { return $this->view('new', $args); } @@ -28,7 +28,7 @@ class Topic extends Page * * @return Page */ - public function viewUnread(array $args) + public function viewUnread(array $args): Page { return $this->view('unread', $args); } @@ -40,7 +40,7 @@ class Topic extends Page * * @return Page */ - public function viewLast(array $args) + public function viewLast(array $args): Page { return $this->view('last', $args); } @@ -53,7 +53,7 @@ class Topic extends Page * * @return Page */ - public function viewPost(array $args) + public function viewPost(array $args): Page { return $this->view('post', $args); } @@ -65,7 +65,7 @@ class Topic extends Page * * @return Page */ - public function viewTopic(array $args) + public function viewTopic(array $args): Page { return $this->view('topic', $args); } @@ -76,7 +76,7 @@ class Topic extends Page * * @param Page */ - protected function go($type, ModelTopic $topic) + protected function go(string $type, ModelTopic $topic): Page { switch ($type) { case 'new': @@ -103,7 +103,7 @@ class Topic extends Page * * @return Page */ - protected function view($type, array $args) + protected function view(string $type, array $args): Page { if ($type === 'post') { $post = $this->c->posts->load((int) $args['id']); diff --git a/app/Models/Pages/Userlist.php b/app/Models/Pages/Userlist.php index 3dd30ea1..2d67d4be 100644 --- a/app/Models/Pages/Userlist.php +++ b/app/Models/Pages/Userlist.php @@ -2,8 +2,8 @@ namespace ForkBB\Models\Pages; -use ForkBB\Models\Page; use ForkBB\Core\Validator; +use ForkBB\Models\Page; use ForkBB\Models\Forum\Model as Forum; use InvalidArgumentException; @@ -14,7 +14,7 @@ class Userlist extends Page * * @return array */ - protected function getgroupList() + protected function getgroupList(): array { $list = [ 'all' => \ForkBB\__('All users'), @@ -37,7 +37,7 @@ class Userlist extends Page * * @return Page */ - public function view(array $args, $method) + public function view(array $args, string $method): Page { $this->c->Lang->load('userlist'); @@ -147,7 +147,7 @@ class Userlist extends Page * * @return array */ - protected function formUserlist(Validator $v) + protected function formUserlist(Validator $v): array { $form = [ 'action' => $this->c->Router->link('Userlist'), diff --git a/app/Models/Post/Delete.php b/app/Models/Post/Delete.php index a5b379ab..8c03a1ae 100644 --- a/app/Models/Post/Delete.php +++ b/app/Models/Post/Delete.php @@ -21,7 +21,7 @@ class Delete extends Action * @throws InvalidArgumentException * @throws RuntimeException */ - public function delete(...$args) + public function delete(...$args): void { if (empty($args)) { throw new InvalidArgumentException('No arguments, expected User(s), Forum(s), Topic(s) or Post(s)'); diff --git a/app/Models/Post/Load.php b/app/Models/Post/Load.php index bd5ee5e3..519a321b 100644 --- a/app/Models/Post/Load.php +++ b/app/Models/Post/Load.php @@ -3,12 +3,13 @@ namespace ForkBB\Models\Post; use ForkBB\Models\Action; +use ForkBB\Models\Post\Model as Post; class Load extends Action { protected $aliases; - protected function queryFields(array $args) + protected function queryFields(array $args): string { $result = []; $fields = []; @@ -43,7 +44,7 @@ class Load extends Action return \implode(', ', $result); } - protected function setData(array $args, array $data) + protected function setData(array $args, array $data): void { foreach ($args as $aliases => $model) { $attrs = []; @@ -69,7 +70,7 @@ class Load extends Action * * @return null|Post */ - public function loadFromTopic($id, $tid) + public function loadFromTopic(int $id, int $tid): ?Post { $vars = [ ':pid' => $id, @@ -105,7 +106,7 @@ class Load extends Action * * @return null|Post */ - public function load($id) + public function load(int $id): ?Post { if ($this->c->user->isGuest) { $vars = [ diff --git a/app/Models/Post/Manager.php b/app/Models/Post/Manager.php index bd0c56f7..4d9f99cc 100644 --- a/app/Models/Post/Manager.php +++ b/app/Models/Post/Manager.php @@ -10,25 +10,25 @@ class Manager extends ManagerModel { /** * Создает новую модель сообщения - * + * * @param array $attrs - * + * * @return Post */ - public function create(array $attrs = []) + public function create(array $attrs = []): Post { return $this->c->PostModel->setAttrs($attrs); } /** - * Загружает сообщение из БД - * + * Загружает сообщение из БД + * * @param int $id * @param int $tid - * + * * @return null|Post */ - public function load($id, $tid = null) + public function load(int $id, int $tid = null): ?Post { $post = $this->get($id); @@ -52,10 +52,10 @@ class Manager extends ManagerModel * Обновляет сообщение в БД * * @param Post $post - * + * * @return Post */ - public function update(Post $post) + public function update(Post $post): Post { return $this->Save->update($post); } @@ -64,10 +64,10 @@ class Manager extends ManagerModel * Добавляет новое сообщение в БД * * @param Post $post - * + * * @return int */ - public function insert(Post $post) + public function insert(Post $post): int { $id = $this->Save->insert($post); $this->set($id, $post); diff --git a/app/Models/Post/Model.php b/app/Models/Post/Model.php index 14da8596..84cc94d7 100644 --- a/app/Models/Post/Model.php +++ b/app/Models/Post/Model.php @@ -4,6 +4,7 @@ namespace ForkBB\Models\Post; use ForkBB\Models\DataModel; use ForkBB\Models\User\Model as User; +use ForkBB\Models\Topic\Model as Topic; use RuntimeException; class Model extends DataModel @@ -15,7 +16,7 @@ class Model extends DataModel * * @return Topic\Model */ - protected function getparent() + protected function getparent(): Topic { if ($this->topic_id < 1) { throw new RuntimeException('Parent is not defined'); @@ -29,7 +30,7 @@ class Model extends DataModel * * @return string */ - protected function getlink() + protected function getlink(): string { return $this->c->Router->link('ViewPost', ['id' => $this->id]); } @@ -41,7 +42,7 @@ class Model extends DataModel * * @return User\Model */ - protected function getuser() //???? + protected function getuser(): User //???? { $user = $this->c->users->load($this->poster_id); @@ -59,17 +60,17 @@ class Model extends DataModel return $user; } - protected function getcanReport() + protected function getcanReport(): bool { return ! $this->c->user->isAdmin && ! $this->c->user->isGuest; } - protected function getlinkReport() + protected function getlinkReport(): string { return $this->c->Router->link('ReportPost', ['id' => $this->id]); } - protected function getcanDelete() + protected function getcanDelete(): bool { if ($this->c->user->isGuest) { return false; @@ -89,12 +90,12 @@ class Model extends DataModel ); } - protected function getlinkDelete() + protected function getlinkDelete(): string { return $this->c->Router->link('DeletePost', ['id' => $this->id]); } - protected function getcanEdit() + protected function getcanEdit(): bool { if ($this->c->user->isGuest) { return false; @@ -112,17 +113,17 @@ class Model extends DataModel ); } - protected function getlinkEdit() + protected function getlinkEdit(): string { return $this->c->Router->link('EditPost', ['id' => $this->id]); } - protected function getcanQuote() + protected function getcanQuote(): bool { return $this->parent->canReply; } - protected function getlinkQuote() + protected function getlinkQuote(): string { return $this->c->Router->link('NewReply', ['id' => $this->parent->id, 'quote' => $this->id]); } @@ -132,7 +133,7 @@ class Model extends DataModel * * @return string */ - public function html() + public function html(): string { return $this->c->censorship->censor($this->c->Parser->parseMessage($this->message, (bool) $this->hide_smilies)); } diff --git a/app/Models/Post/PreviousPost.php b/app/Models/Post/PreviousPost.php index 12720ef0..96e1b4f9 100644 --- a/app/Models/Post/PreviousPost.php +++ b/app/Models/Post/PreviousPost.php @@ -9,12 +9,12 @@ class PreviousPost extends Action { /** * Вычисляет номер сообщения перед указанным - * + * * @param Post $post - * + * * @return null|int */ - public function previousPost(Post $post) + public function previousPost(Post $post): ?int { $vars = [ ':pid' => $post->id, diff --git a/app/Models/Post/RebuildIndex.php b/app/Models/Post/RebuildIndex.php index 279585ae..f3ae093f 100644 --- a/app/Models/Post/RebuildIndex.php +++ b/app/Models/Post/RebuildIndex.php @@ -16,7 +16,7 @@ class RebuildIndex extends Action * * @return int */ - public function rebuildIndex($start, $limit, $mode) + public function rebuildIndex(int $start, int $limit, string $mode): int { $vars = [ ':start' => $start, diff --git a/app/Models/Post/Save.php b/app/Models/Post/Save.php index 82728796..bdb86205 100644 --- a/app/Models/Post/Save.php +++ b/app/Models/Post/Save.php @@ -17,7 +17,7 @@ class Save extends Action * * @return Post */ - public function update(Post $post) + public function update(Post $post): Post { if ($post->id < 1) { throw new RuntimeException('The model does not have ID'); @@ -55,7 +55,7 @@ class Save extends Action * * @return int */ - public function insert(Post $post) + public function insert(Post $post): int { if (null !== $post->id) { throw new RuntimeException('The model has ID'); diff --git a/app/Models/Post/UserInfoFromIP.php b/app/Models/Post/UserInfoFromIP.php index 37ed4b62..c10e34b3 100644 --- a/app/Models/Post/UserInfoFromIP.php +++ b/app/Models/Post/UserInfoFromIP.php @@ -14,7 +14,7 @@ class UserInfoFromIP extends Action * * @return array */ - public function userInfoFromIP($ip) + public function userInfoFromIP(string $ip): array { $vars = [ ':ip' => $ip, diff --git a/app/Models/Post/UserStat.php b/app/Models/Post/UserStat.php index 2a7358f7..5d79baf6 100644 --- a/app/Models/Post/UserStat.php +++ b/app/Models/Post/UserStat.php @@ -15,7 +15,7 @@ class UserStat extends Action * * @return array */ - public function userStat($id) + public function userStat(int $id): array { $vars = [ ':id' => $id, diff --git a/app/Models/Post/View.php b/app/Models/Post/View.php index b3a494bf..aa8e0b90 100644 --- a/app/Models/Post/View.php +++ b/app/Models/Post/View.php @@ -14,7 +14,7 @@ class View extends Action { protected $aliases; - protected function queryFields(array $args) + protected function queryFields(array $args): string { $result = []; $fields = []; @@ -49,7 +49,7 @@ class View extends Action return \implode(', ', $result); } - protected function setData(array $args, array $data) + protected function setData(array $args, array $data): void { foreach ($args as $aliases => $model) { $attrs = []; @@ -77,7 +77,7 @@ class View extends Action * * @return array */ - public function view($arg, $review = false) + public function view($arg, bool $review = false): array { if (! $arg instanceof Topic && ! $arg instanceof Search) { throw new InvalidArgumentException('Expected Topic or Search'); diff --git a/app/Models/Report/Manager.php b/app/Models/Report/Manager.php index f984666b..d2737e35 100644 --- a/app/Models/Report/Manager.php +++ b/app/Models/Report/Manager.php @@ -16,7 +16,7 @@ class Manager extends ManagerModel * * @return Report */ - public function create(array $attrs = []) + public function create(array $attrs = []): Report { return $this->c->ReportModel->setAttrs($attrs); } @@ -29,7 +29,7 @@ class Manager extends ManagerModel * * @return null|Report */ - public function load($id, $tid = null) + public function load(int $id, int $tid = null): ?Report { $post = $this->get($id); @@ -56,7 +56,7 @@ class Manager extends ManagerModel * * @return Report */ - public function update(Report $post) + public function update(Report $post): Report { return $this->Save->update($post); } @@ -68,7 +68,7 @@ class Manager extends ManagerModel * * @return int */ - public function insert(Report $post) + public function insert(Report $post): int { $id = $this->Save->insert($post); $this->set($id, $post); @@ -80,7 +80,7 @@ class Manager extends ManagerModel * * @return int */ - public function lastId() + public function lastId(): int { if ($this->c->Cache->has('report')) { $last = $this->list = $this->c->Cache->get('report'); diff --git a/app/Models/Report/Model.php b/app/Models/Report/Model.php index 75bf6d2a..8e48228f 100644 --- a/app/Models/Report/Model.php +++ b/app/Models/Report/Model.php @@ -16,7 +16,7 @@ class Model extends DataModel * * @throws RuntimeException */ - protected function setauthor(User $user) + protected function setauthor(User $user): void { if ($user->isGuest) { throw new RuntimeException('Bad author'); @@ -32,7 +32,7 @@ class Model extends DataModel * * @return User */ - protected function getauthor() + protected function getauthor(): User { if ($this->reported_by < 1) { throw new RuntimeException('No author data'); @@ -57,7 +57,7 @@ class Model extends DataModel * * @throws RuntimeException */ - protected function setpost(Post $post) + protected function setpost(Post $post): void { if ($post->id < 1) { throw new RuntimeException('Bad post'); @@ -73,7 +73,7 @@ class Model extends DataModel * * @return null|Post */ - protected function getpost() + protected function getpost(): ?Post { if ($this->post_id < 1) { throw new RuntimeException('No post data'); diff --git a/app/Models/Report/Save.php b/app/Models/Report/Save.php index 608aad0c..db9b5be4 100644 --- a/app/Models/Report/Save.php +++ b/app/Models/Report/Save.php @@ -17,7 +17,7 @@ class Save extends Action * * @return Report */ - public function update(Report $report) + public function update(Report $report): Report { if ($report->id < 1) { throw new RuntimeException('The model does not have ID'); @@ -55,7 +55,7 @@ class Save extends Action * * @return int */ - public function insert(Report $report) + public function insert(Report $report): int { if (null !== $report->id) { throw new RuntimeException('The model has ID'); diff --git a/app/Models/Rules.php b/app/Models/Rules.php index 99213cb6..098bace9 100644 --- a/app/Models/Rules.php +++ b/app/Models/Rules.php @@ -21,7 +21,7 @@ class Rules extends Model * * @return mixed */ - public function __get($name) + public function __get(string $name) { if (true === $this->ready) { return parent::__get($name); diff --git a/app/Models/Rules/Profile.php b/app/Models/Rules/Profile.php index 07afa2cf..4dd59f6d 100644 --- a/app/Models/Rules/Profile.php +++ b/app/Models/Rules/Profile.php @@ -20,7 +20,7 @@ class Profile extends Rules * * @return Rules\Profile */ - public function setUser(User $curUser) + public function setUser(User $curUser): self { $this->setAttrs([]); @@ -36,27 +36,27 @@ class Profile extends Rules return $this; } - protected function getrename() + protected function getrename(): bool { return $this->admin || ($this->moderator && '1' == $this->user->g_mod_rename_users); } - protected function geteditPass() + protected function geteditPass(): bool { return $this->my || $this->admin || ($this->moderator && '1' == $this->user->g_mod_change_passwords); } - protected function getsetTitle() + protected function getsetTitle(): bool { return $this->admin || $this->moderator || '1' == $this->user->g_set_title; } - protected function getviewOEmail() + protected function getviewOEmail(): bool { return $this->my || $this->user->isAdmMod; } - protected function getviewEmail() // ????? + protected function getviewEmail(): bool // ????? { return ! $this->my && (($this->user->isAdmMod && 1 === $this->curUser->email_setting) @@ -64,17 +64,17 @@ class Profile extends Rules ); } - protected function geteditEmail() + protected function geteditEmail(): bool { return $this->my || $this->admin; } - protected function getviewLastVisit() + protected function getviewLastVisit(): bool { return $this->my || $this->user->isAdmMod; } - protected function getbanUser() + protected function getbanUser(): bool { return ! $this->my && ($this->admin || ($this->moderator && '1' == $this->user->g_mod_ban_users)) @@ -82,7 +82,7 @@ class Profile extends Rules && ! $this->curUser->isGuest; } - protected function getdeleteUser() + protected function getdeleteUser(): bool { return ! $this->my && $this->admin @@ -90,37 +90,37 @@ class Profile extends Rules && ! $this->curUser->isGuest; } - protected function getviewIP() + protected function getviewIP(): bool { return $this->user->canViewIP; } - protected function getuseAvatar() + protected function getuseAvatar(): bool { return '1' == $this->c->config->o_avatars; } - protected function getuseSignature() + protected function getuseSignature(): bool { return '1' == $this->c->config->o_signatures; } - protected function getviewWebsite() + protected function getviewWebsite(): bool { return $this->user->isAdmMod || '1' == $this->curUser->g_post_links; } - protected function geteditWebsite() + protected function geteditWebsite(): bool { return $this->admin || (($this->moderator || $this->my) && '1' == $this->user->g_post_links); //???? } - protected function getchangeGroup() + protected function getchangeGroup(): bool { return $this->admin || ($this->my && $this->moderator); } - protected function getconfModer() + protected function getconfModer(): bool { return $this->user->isAdmin && $this->curUser->isAdmMod && ! $this->curUser->isAdmin; } diff --git a/app/Models/Rules/Users.php b/app/Models/Rules/Users.php index 36cfd2dc..65503840 100644 --- a/app/Models/Rules/Users.php +++ b/app/Models/Rules/Users.php @@ -15,7 +15,7 @@ class Users extends Rules * * @return Rules\Users */ - public function init() + public function init(): self { $this->setAttrs([]); @@ -25,27 +25,27 @@ class Users extends Rules return $this; } - protected function getviewIP() + protected function getviewIP(): bool { return $this->user->canViewIP; } - protected function getdeleteUsers() + protected function getdeleteUsers(): bool { return $this->user->isAdmin; } - protected function getbanUsers() + protected function getbanUsers(): bool { return $this->user->isAdmin || ($this->user->isAdmMod && '1' == $this->user->g_mod_ban_users); } - protected function getchangeGroup() + protected function getchangeGroup(): bool { return $this->user->isAdmin; } - public function canDeleteUser(User $user) + public function canDeleteUser(User $user): bool { if (! $this->profileRules instanceof ProfileRules) { $this->profileRules = $this->c->ProfileRules; @@ -54,7 +54,7 @@ class Users extends Rules return $this->profileRules->setUser($user)->deleteUser; } - public function canBanUser(User $user) + public function canBanUser(User $user): bool { if (! $this->profileRules instanceof ProfileRules) { $this->profileRules = $this->c->ProfileRules; @@ -63,7 +63,7 @@ class Users extends Rules return $this->profileRules->setUser($user)->banUser; } - public function canChangeGroup(User $user, $profile = false) + public function canChangeGroup(User $user, bool $profile = false): bool { if (! $this->profileRules instanceof ProfileRules) { $this->profileRules = $this->c->ProfileRules; diff --git a/app/Models/Search/ActionP.php b/app/Models/Search/ActionP.php index 044dbe1a..54b5ea19 100644 --- a/app/Models/Search/ActionP.php +++ b/app/Models/Search/ActionP.php @@ -21,7 +21,7 @@ class ActionP extends Method * * @return false|array */ - public function actionP($action, Forum $root, $uid = null) + public function actionP(string $action, Forum $root, int $uid = null) { $forums = \array_keys($root->descendants); if ($root->id) { diff --git a/app/Models/Search/ActionT.php b/app/Models/Search/ActionT.php index 7c0d8adf..f5b1c626 100644 --- a/app/Models/Search/ActionT.php +++ b/app/Models/Search/ActionT.php @@ -21,7 +21,7 @@ class ActionT extends Method * * @return false|array */ - public function actionT($action, Forum $root, $uid = null) + public function actionT(string $action, Forum $root, int $uid = null) { $forums = \array_keys($root->descendants); if ($root->id) { diff --git a/app/Models/Search/Delete.php b/app/Models/Search/Delete.php index 61efa219..143f9f2b 100644 --- a/app/Models/Search/Delete.php +++ b/app/Models/Search/Delete.php @@ -21,7 +21,7 @@ class Delete extends Method * @throws InvalidArgumentException * @throws RuntimeException */ - public function delete(...$args) + public function delete(...$args): void { if (empty($args)) { throw new InvalidArgumentException('No arguments, expected User(s), Forum(s), Topic(s) or Post(s)'); diff --git a/app/Models/Search/Execute.php b/app/Models/Search/Execute.php index 469d94da..c8832bc1 100644 --- a/app/Models/Search/Execute.php +++ b/app/Models/Search/Execute.php @@ -32,7 +32,7 @@ class Execute extends Method * * @return bool */ - public function execute(Validator $v, array $forumIdxs, $flood) + public function execute(Validator $v, array $forumIdxs, bool $flood): bool { if (! \is_array($this->model->queryWords) || ! \is_string($this->model->queryText)) { throw new RuntimeException('No query data'); @@ -107,7 +107,7 @@ class Execute extends Method * * @return array */ - protected function exec(array $words, array $vars) + protected function exec(array $words, array $vars): array { $type = 'AND'; $count = 0; @@ -185,7 +185,7 @@ class Execute extends Method * * @return array */ - protected function buildSelect(Validator $v, array $forumIdxs) + protected function buildSelect(Validator $v, array $forumIdxs): array { $vars = []; $whereIdx = []; diff --git a/app/Models/Search/Index.php b/app/Models/Search/Index.php index e33a7966..0bc07915 100644 --- a/app/Models/Search/Index.php +++ b/app/Models/Search/Index.php @@ -17,7 +17,7 @@ class Index extends Method * @param Post $post * @param string $mode */ - public function index(Post $post, $mode = 'add') + public function index(Post $post, string $mode = 'add'): void { //???? пост после валидации должен иметь дерево тегов $mesWords = $this->words(\mb_strtolower($this->c->Parser->getText(), 'UTF-8')); @@ -134,7 +134,7 @@ class Index extends Method * * @return array */ - protected function words($text) + protected function words(string $text): array { $text = $this->model->cleanText($text, true); diff --git a/app/Models/Search/Model.php b/app/Models/Search/Model.php index 311882e1..9cf0c7a9 100644 --- a/app/Models/Search/Model.php +++ b/app/Models/Search/Model.php @@ -40,7 +40,7 @@ class Model extends ParentModel * * @return string */ - protected function getlink() + protected function getlink(): string { return $this->c->Router->link($this->linkMarker, $this->linkArgs); } @@ -50,7 +50,7 @@ class Model extends ParentModel * * @return array */ - protected function getpagination() + protected function getpagination(): array { return $this->c->Func->paginate($this->numPages, $this->page, $this->linkMarker, $this->linkArgs); } @@ -60,7 +60,7 @@ class Model extends ParentModel * * @return bool */ - public function hasPage() + public function hasPage(): bool { return $this->page > 0 && $this->page <= $this->numPages; } @@ -73,7 +73,7 @@ class Model extends ParentModel * * @return string */ - public function cleanText($text, $indexing = false) + public function cleanText(string $text, bool $indexing = false): string { $text = \str_replace(['`', '’', 'ё'], ['\'', '\'', 'е'], $text); // четыре одинаковых буквы в одну @@ -107,7 +107,7 @@ class Model extends ParentModel * * @return null|string */ - public function word($word, $indexing = false) + public function word(string $word, bool $indexing = false): ?string { if (isset($this->c->stopwords->list[$word])) { return null; @@ -137,7 +137,7 @@ class Model extends ParentModel * * @return bool */ - public function isCJKWord($word) + public function isCJKWord(string $word): bool { return \preg_match('%' . self::CJK_REGEX . '%u', $word) ? true : false; //????? } diff --git a/app/Models/Search/Prepare.php b/app/Models/Search/Prepare.php index 5f4c97f4..ec9c87e7 100644 --- a/app/Models/Search/Prepare.php +++ b/app/Models/Search/Prepare.php @@ -16,9 +16,9 @@ class Prepare extends Method * * @param string $query * - * @return array + * @return bool */ - public function prepare($query) + public function prepare(string $query): bool { if (\substr_count($query, '"') % 2) { $this->model->queryError = 'Odd number of quotes: \'%s\''; @@ -179,7 +179,7 @@ class Prepare extends Method * * @return string */ - protected function queryText(array $words) + protected function queryText(array $words): string { $space = ''; $result = ''; diff --git a/app/Models/Search/TruncateIndex.php b/app/Models/Search/TruncateIndex.php index 365b22e5..cee6d95b 100644 --- a/app/Models/Search/TruncateIndex.php +++ b/app/Models/Search/TruncateIndex.php @@ -14,7 +14,7 @@ class TruncateIndex extends Method /** * Очистка поискового индекса */ - public function truncateIndex() + public function truncateIndex(): void { $this->c->DB->truncateTable('search_cache'); $this->c->DB->truncateTable('search_matches'); diff --git a/app/Models/SmileyList/Load.php b/app/Models/SmileyList/Load.php index 2e13af4d..36208d4a 100644 --- a/app/Models/SmileyList/Load.php +++ b/app/Models/SmileyList/Load.php @@ -3,6 +3,7 @@ namespace ForkBB\Models\SmileyList; use ForkBB\Models\Method; +use orkBB\Models\SmileyList\Model as SmileyList; use PDO; class Load extends Method @@ -13,7 +14,7 @@ class Load extends Method * * @return SmileyList\Model */ - public function load() + public function load(): SmileyList { $list = $this->c->DB->query('SELECT sm.text, sm.image FROM ::smilies AS sm ORDER BY sm.disp_position')->fetchAll(PDO::FETCH_KEY_PAIR); //???? text уникальное? $this->model->list = $list; diff --git a/app/Models/SmileyList/Model.php b/app/Models/SmileyList/Model.php index 9e9684f6..75486e8d 100644 --- a/app/Models/SmileyList/Model.php +++ b/app/Models/SmileyList/Model.php @@ -11,7 +11,7 @@ class Model extends ParentModel * * @return SmileyList\Model */ - public function init() + public function init(): self { if ($this->c->Cache->has('smilies')) { $this->list = $this->c->Cache->get('smilies'); diff --git a/app/Models/Stats/Model.php b/app/Models/Stats/Model.php index 9670798e..aabf15bd 100644 --- a/app/Models/Stats/Model.php +++ b/app/Models/Stats/Model.php @@ -12,7 +12,7 @@ class Model extends ParentModel * * @return Models\Stats */ - public function init() + public function init(): self { if ($this->c->Cache->has('stats')) { $list = $this->c->Cache->get('stats'); @@ -33,7 +33,7 @@ class Model extends ParentModel * * @return Models\Stats */ - public function reset() + public function reset(): self { $this->c->Cache->delete('stats'); return $this; diff --git a/app/Models/Stopwords/Model.php b/app/Models/Stopwords/Model.php index 002ae60d..809da58e 100644 --- a/app/Models/Stopwords/Model.php +++ b/app/Models/Stopwords/Model.php @@ -11,7 +11,7 @@ class Model extends ParentModel * * @return Stopwords\Model */ - public function init() + public function init(): self { $data = $this->c->Cache->get('stopwords'); if (isset($data['id'], $data['stopwords']) && $data['id'] === $this->generateId()) { @@ -27,7 +27,7 @@ class Model extends ParentModel * * @return string */ - protected function generateId() + protected function generateId(): string { if (! empty($this->id)) { return $this->id; @@ -54,7 +54,7 @@ class Model extends ParentModel * * @return Stopwords\Model */ - protected function load() + protected function load(): self { $id = $this->generateId(); diff --git a/app/Models/Topic/CalcStat.php b/app/Models/Topic/CalcStat.php index be91f0b5..a9c0abb6 100644 --- a/app/Models/Topic/CalcStat.php +++ b/app/Models/Topic/CalcStat.php @@ -3,6 +3,7 @@ namespace ForkBB\Models\Topic; use ForkBB\Models\Method; +use ForkBB\Models\Topic\Model as Topic; use RuntimeException; class CalcStat extends Method @@ -14,7 +15,7 @@ class CalcStat extends Method * * @return Topic */ - public function calcStat() + public function calcStat(): Topic { if ($this->model->id < 1) { throw new RuntimeException('The model does not have ID'); diff --git a/app/Models/Topic/Delete.php b/app/Models/Topic/Delete.php index 2021937b..f9b648bc 100644 --- a/app/Models/Topic/Delete.php +++ b/app/Models/Topic/Delete.php @@ -20,7 +20,7 @@ class Delete extends Action * @throws InvalidArgumentException * @throws RuntimeException */ - public function delete(...$args) + public function delete(...$args): void { if (empty($args)) { throw new InvalidArgumentException('No arguments, expected User(s), Forum(s) or Topic(s)'); diff --git a/app/Models/Topic/Load.php b/app/Models/Topic/Load.php index 5c3cc41f..308471b9 100644 --- a/app/Models/Topic/Load.php +++ b/app/Models/Topic/Load.php @@ -14,7 +14,7 @@ class Load extends Action * * @return null|Topic */ - public function load($id) + public function load($id): ?Topic { $vars = [ ':tid' => $id, diff --git a/app/Models/Topic/Manager.php b/app/Models/Topic/Manager.php index 4ed6f578..027d5b88 100644 --- a/app/Models/Topic/Manager.php +++ b/app/Models/Topic/Manager.php @@ -15,7 +15,7 @@ class Manager extends ManagerModel * * @return Topic */ - public function create(array $attrs = []) + public function create(array $attrs = []): Topic { return $this->c->TopicModel->setAttrs($attrs); } @@ -27,7 +27,7 @@ class Manager extends ManagerModel * * @return null|Topic */ - public function load($id) + public function load(int $id): ?Topic { $topic = $this->get($id); @@ -46,7 +46,7 @@ class Manager extends ManagerModel * * @return Topic */ - public function update(Topic $topic) + public function update(Topic $topic): Topic { return $this->Save->update($topic); } @@ -58,7 +58,7 @@ class Manager extends ManagerModel * * @return int */ - public function insert(Topic $topic) + public function insert(Topic $topic): int { $id = $this->Save->insert($topic); $this->set($id, $topic); diff --git a/app/Models/Topic/Model.php b/app/Models/Topic/Model.php index 2d40f2dc..0f9c3e57 100644 --- a/app/Models/Topic/Model.php +++ b/app/Models/Topic/Model.php @@ -3,6 +3,7 @@ namespace ForkBB\Models\Topic; use ForkBB\Models\DataModel; +use ForkBB\Models\Forum\Model as Forum; use PDO; use RuntimeException; @@ -15,7 +16,7 @@ class Model extends DataModel * * @return Forum\Model */ - protected function getparent() + protected function getparent(): Forum { if ($this->forum_id < 1) { throw new RuntimeException('Parent is not defined'); @@ -29,7 +30,7 @@ class Model extends DataModel * * @return bool */ - protected function getcanReply() + protected function getcanReply(): bool { if ($this->c->user->isAdmin) { return true; @@ -50,7 +51,7 @@ class Model extends DataModel * * @return string */ - protected function getlink() + protected function getlink(): string { return $this->c->Router->link('Topic', ['id' => $this->moved_to ?: $this->id, 'name' => \ForkBB\cens($this->subject)]); } @@ -60,7 +61,7 @@ class Model extends DataModel * * @return string */ - protected function getlinkReply() + protected function getlinkReply(): string { return $this->c->Router->link('NewReply', ['id' => $this->id]); } @@ -70,7 +71,7 @@ class Model extends DataModel * * @return null|string */ - protected function getlinkLast() + protected function getlinkLast(): ?string { if ($this->moved_to) { return null; @@ -84,7 +85,7 @@ class Model extends DataModel * * @return string */ - protected function getlinkNew() + protected function getlinkNew(): string { return $this->c->Router->link('TopicViewNew', ['id' => $this->id]); } @@ -92,7 +93,7 @@ class Model extends DataModel /** * Ссылка для перехода на первое не прочитанное сообщение в теме */ - protected function getlinkUnread() + protected function getlinkUnread(): string { return $this->c->Router->link('TopicViewUnread', ['id' => $this->id]); } @@ -143,7 +144,7 @@ class Model extends DataModel * * @return int */ - protected function getfirstNew() + protected function getfirstNew(): int { if (false === $this->hasNew) { return 0; @@ -165,7 +166,7 @@ class Model extends DataModel * * @return int */ - protected function getfirstUnread() + protected function getfirstUnread(): int { if (false === $this->hasUnread) { return 0; @@ -189,7 +190,7 @@ class Model extends DataModel * * @return int */ - protected function getnumPages() + protected function getnumPages(): int { if (null === $this->num_replies) { throw new RuntimeException('The model does not have the required data'); @@ -203,7 +204,7 @@ class Model extends DataModel * * @return array */ - protected function getpagination() + protected function getpagination(): array { $page = (int) $this->page; @@ -220,7 +221,7 @@ class Model extends DataModel * * @return bool */ - public function hasPage() + public function hasPage(): bool { return $this->page > 0 && $this->page <= $this->numPages; } @@ -232,7 +233,7 @@ class Model extends DataModel * * @return array */ - public function pageData() + public function pageData(): array { if (! $this->hasPage()) { throw new InvalidArgumentException('Bad number of displayed page'); @@ -264,7 +265,7 @@ class Model extends DataModel * * @return array */ - public function review() + public function review(): array { if ($this->c->config->o_topic_review < 1) { return []; @@ -291,7 +292,7 @@ class Model extends DataModel * * @param int $pid */ - public function calcPage($pid) + public function calcPage(int $pid): void { $vars = [ ':tid' => $this->id, @@ -312,7 +313,7 @@ class Model extends DataModel * * @return bool */ - protected function getshowViews() + protected function getshowViews(): bool { return $this->c->config->o_topic_views == '1'; } @@ -320,7 +321,7 @@ class Model extends DataModel /** * Увеличивает на 1 количество просмотров темы */ - public function incViews() + public function incViews(): void { $vars = [ ':tid' => $this->id, @@ -333,7 +334,7 @@ class Model extends DataModel /** * Обновление меток последнего визита и последнего прочитанного сообщения */ - public function updateVisits() + public function updateVisits(): void { if ($this->c->user->isGuest) { return; diff --git a/app/Models/Topic/Save.php b/app/Models/Topic/Save.php index c513cbe5..b277a934 100644 --- a/app/Models/Topic/Save.php +++ b/app/Models/Topic/Save.php @@ -17,7 +17,7 @@ class Save extends Action * * @return Topic */ - public function update(Topic $topic) + public function update(Topic $topic): Topic { if ($topic->id < 1) { throw new RuntimeException('The model does not have ID'); @@ -55,7 +55,7 @@ class Save extends Action * * @return int */ - public function insert(Topic $topic) + public function insert(Topic $topic): int { if (null !== $topic->id) { throw new RuntimeException('The model has ID'); diff --git a/app/Models/Topic/View.php b/app/Models/Topic/View.php index 0d32f2d5..6f8ae085 100644 --- a/app/Models/Topic/View.php +++ b/app/Models/Topic/View.php @@ -22,7 +22,7 @@ class View extends Action * * @return array */ - public function view($arg) + public function view($arg): array { if ($arg instanceof Forum) { $expanded = false; diff --git a/app/Models/User/AdminsIds.php b/app/Models/User/AdminsIds.php index d8e81a9a..19646b06 100644 --- a/app/Models/User/AdminsIds.php +++ b/app/Models/User/AdminsIds.php @@ -12,7 +12,7 @@ class AdminsIds extends Action * * @return array */ - public function adminsIds() + public function adminsIds(): array { $vars = [ ':gid' => $this->c->GROUP_ADMIN, diff --git a/app/Models/User/ChangeGroup.php b/app/Models/User/ChangeGroup.php index f69110a0..a0e015e5 100644 --- a/app/Models/User/ChangeGroup.php +++ b/app/Models/User/ChangeGroup.php @@ -19,7 +19,7 @@ class ChangeGroup extends Action * @throws InvalidArgumentException * @throws RuntimeException */ - public function changeGroup($newGroupId, ...$users) + public function changeGroup(int $newGroupId, ...$users): void { $newGroup = $this->c->groups->get($newGroupId); if (null === $newGroup || $newGroup->groupGuest) { diff --git a/app/Models/User/Current.php b/app/Models/User/Current.php index 8277c3e2..c57a8093 100644 --- a/app/Models/User/Current.php +++ b/app/Models/User/Current.php @@ -3,6 +3,7 @@ namespace ForkBB\Models\User; use ForkBB\Models\Action; +use ForkBB\Models\User\Model as User; use RuntimeException; class Current extends Action @@ -13,7 +14,7 @@ class Current extends Action * * @return User */ - public function current() + public function current(): User { $cookie = $this->c->Cookie; $user = $this->load((int) $cookie->uId); @@ -78,7 +79,7 @@ class Current extends Action * * @return User; */ - protected function load($id) + protected function load(int $id): User { $data = null; $ip = $this->getIp(); @@ -103,7 +104,7 @@ class Current extends Action * * @return string */ - protected function getIp() + protected function getIp(): string { return \filter_var($_SERVER['REMOTE_ADDR'], \FILTER_VALIDATE_IP) ?: 'unknow'; } @@ -113,7 +114,7 @@ class Current extends Action * * @return string */ - protected function getUserAgent() + protected function getUserAgent(): string { $ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; return \is_string($ua) ? \trim($ua) : ''; @@ -165,7 +166,7 @@ class Current extends Action * * @return string */ - protected function nameBot($agent, $agentL) + protected function nameBot(string $agent, string $agentL): string { if (\strpos($agentL, 'mozilla') !== false) { $agent = \preg_replace('%Mozilla.*?compatible%i', ' ', $agent); @@ -255,7 +256,7 @@ class Current extends Action * * @return string */ - protected function getLangFromHTTP() + protected function getLangFromHTTP(): string { if (! empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $langs = $this->c->Func->getLangs(); diff --git a/app/Models/User/Delete.php b/app/Models/User/Delete.php index 00af3bdd..8d2f60f4 100644 --- a/app/Models/User/Delete.php +++ b/app/Models/User/Delete.php @@ -19,7 +19,7 @@ class Delete extends Action * @throws InvalidArgumentException * @throws RuntimeException */ - public function delete(...$users) + public function delete(...$users): void { if (empty($users)) { throw new InvalidArgumentException('No arguments, expected User(s)'); diff --git a/app/Models/User/Filter.php b/app/Models/User/Filter.php index 3d9f7929..e9a0c893 100644 --- a/app/Models/User/Filter.php +++ b/app/Models/User/Filter.php @@ -18,7 +18,7 @@ class Filter extends Action * * @return array */ - public function filter(array $filters, array $order = []) + public function filter(array $filters, array $order = []): array { $fields = $this->c->dbMap->users; $orderBy = []; diff --git a/app/Models/User/IsUniqueName.php b/app/Models/User/IsUniqueName.php index e70c0218..e1a6e78e 100644 --- a/app/Models/User/IsUniqueName.php +++ b/app/Models/User/IsUniqueName.php @@ -14,7 +14,7 @@ class IsUniqueName extends Action * * @return bool */ - public function isUniqueName(User $user) + public function isUniqueName(User $user): bool { $vars = [ ':id' => (int) $user->id, diff --git a/app/Models/User/Manager.php b/app/Models/User/Manager.php index 0f9ca47e..6f467ad3 100644 --- a/app/Models/User/Manager.php +++ b/app/Models/User/Manager.php @@ -15,7 +15,7 @@ class Manager extends ManagerModel * * @return User */ - public function create(array $attrs = []) + public function create(array $attrs = []): User { return $this->c->UserModel->setAttrs($attrs); } @@ -89,7 +89,7 @@ class Manager extends ManagerModel * * @return User */ - public function update(User $user) + public function update(User $user): User { return $this->Save->update($user); } @@ -101,7 +101,7 @@ class Manager extends ManagerModel * * @return int */ - public function insert(User $user) + public function insert(User $user): int { $id = $this->Save->insert($user); $this->set($id, $user); diff --git a/app/Models/User/Model.php b/app/Models/User/Model.php index a9d5a0e0..9964d912 100644 --- a/app/Models/User/Model.php +++ b/app/Models/User/Model.php @@ -40,7 +40,7 @@ class Model extends DataModel * * @return bool */ - protected function getisUnverified() + protected function getisUnverified(): bool { return 0 === $this->group_id; } @@ -50,7 +50,7 @@ class Model extends DataModel * * @return bool */ - protected function getisGuest() + protected function getisGuest(): bool { return $this->group_id === $this->c->GROUP_GUEST || $this->id < 2 @@ -62,7 +62,7 @@ class Model extends DataModel * * @return bool */ - protected function getisAdmin() + protected function getisAdmin(): bool { return $this->group_id === $this->c->GROUP_ADMIN; } @@ -72,7 +72,7 @@ class Model extends DataModel * * @return bool */ - protected function getisAdmMod() + protected function getisAdmMod(): bool { return $this->group_id === $this->c->GROUP_ADMIN || 1 == $this->g_moderator; @@ -87,7 +87,7 @@ class Model extends DataModel * * @return bool */ - public function isModerator(BaseModel $model) + public function isModerator(BaseModel $model): bool { if (1 != $this->g_moderator) { return false; @@ -107,7 +107,7 @@ class Model extends DataModel * * @return int */ - protected function getlogged() + protected function getlogged(): int { $attr = $this->getAttr('logged'); @@ -123,7 +123,7 @@ class Model extends DataModel * * @return bool */ - protected function getisLogged() + protected function getisLogged(): bool { $attr = $this->getAttr('logged'); return ! empty($attr); @@ -134,7 +134,7 @@ class Model extends DataModel * * @return string */ - protected function getlanguage() + protected function getlanguage(): string { $langs = $this->c->Func->getLangs(); $lang = $this->getAttr('language'); @@ -155,7 +155,7 @@ class Model extends DataModel * * @return string */ - protected function getstyle() + protected function getstyle(): string { $styles = $this->c->Func->getStyles(); $style = $this->getAttr('style'); @@ -176,7 +176,7 @@ class Model extends DataModel * * @return null|string */ - protected function getlink() + protected function getlink(): ?string { if ($this->isGuest) { return null; @@ -190,7 +190,7 @@ class Model extends DataModel * * @return null|string */ - protected function getavatar() + protected function getavatar(): ?string { foreach ($this->avatarTypes as $type) { $path = $this->c->DIR_PUBLIC . "{$this->c->config->o_avatars_dir}/{$this->id}.{$type}"; @@ -206,7 +206,7 @@ class Model extends DataModel /** * Удаляет аватару пользователя */ - public function deleteAvatar() + public function deleteAvatar(): void { foreach ($this->avatarTypes as $type) { $path = $this->c->DIR_PUBLIC . "{$this->c->config->o_avatars_dir}/{$this->id}.{$type}"; @@ -222,7 +222,7 @@ class Model extends DataModel * * @return string */ - public function title() + public function title(): string { if (isset($this->c->bans->userList[\mb_strtolower($this->username)])) { //???? return \ForkBB\__('Banned'); @@ -244,7 +244,7 @@ class Model extends DataModel * * @return bool */ - protected function getonline() + protected function getonline(): bool { return isset($this->c->Online->online[$this->id]); } @@ -254,7 +254,7 @@ class Model extends DataModel * * @return string */ - protected function gethtmlSign() + protected function gethtmlSign(): string { return $this->c->censorship->censor($this->c->Parser->parseSignature($this->signature)); } @@ -264,7 +264,7 @@ class Model extends DataModel * * @return bool */ - protected function getviewUsers() + protected function getviewUsers(): bool { return 1 == $this->g_view_users || $this->isAdmin; } @@ -274,7 +274,7 @@ class Model extends DataModel * * @return bool */ - protected function getsearchUsers() + protected function getsearchUsers(): bool { return 1 == $this->g_search_users || $this->isAdmin; } @@ -284,7 +284,7 @@ class Model extends DataModel * * @return bool */ - protected function getshowAvatar() + protected function getshowAvatar(): bool { return '1' == $this->c->config->o_avatars && 1 == $this->show_avatars; } @@ -294,7 +294,7 @@ class Model extends DataModel * * @return bool */ - protected function getshowUserInfo() + protected function getshowUserInfo(): bool { return '1' == $this->c->config->o_show_user_info; } @@ -304,7 +304,7 @@ class Model extends DataModel * * @return bool */ - protected function getshowSignature() + protected function getshowSignature(): bool { return '1' == $this->c->config->o_signatures && 1 == $this->show_sig; } @@ -314,7 +314,7 @@ class Model extends DataModel * * @return bool */ - protected function getshowPostCount() + protected function getshowPostCount(): bool { return '1' == $this->c->config->o_show_post_count || $this->isAdmMod; } @@ -324,7 +324,7 @@ class Model extends DataModel * * @return int */ - protected function getdisp_topics() + protected function getdisp_topics(): int { $attr = $this->getAttr('disp_topics'); @@ -340,7 +340,7 @@ class Model extends DataModel * * @return int */ - protected function getdisp_posts() + protected function getdisp_posts(): int { $attr = $this->getAttr('disp_topics'); @@ -356,7 +356,7 @@ class Model extends DataModel * * @return bool */ - protected function getcanViewIP() + protected function getcanViewIP(): bool { return $this->isAdmin; } @@ -368,7 +368,7 @@ class Model extends DataModel * * @return null|string */ - public function linkPromote(Post $post) + public function linkPromote(Post $post): ?string { if (($this->isAdmin || ($this->isAdmMod && 1 == $this->g_mod_promote_users)) && $this->id !== $post->user->id //???? @@ -392,7 +392,7 @@ class Model extends DataModel * * @param string $email */ - protected function setemail($email) + protected function setemail(string $email): void { $this->setAttr('email', $email); diff --git a/app/Models/User/Promote.php b/app/Models/User/Promote.php index ea86c3bc..e3cad2be 100644 --- a/app/Models/User/Promote.php +++ b/app/Models/User/Promote.php @@ -18,7 +18,7 @@ class Promote extends Action * * @return int */ - public function promote(...$args) + public function promote(...$args): int { $count = \count($args); diff --git a/app/Models/User/Save.php b/app/Models/User/Save.php index 9459dc6d..aaf25c74 100644 --- a/app/Models/User/Save.php +++ b/app/Models/User/Save.php @@ -17,7 +17,7 @@ class Save extends Action * * @return User */ - public function update(User $user) + public function update(User $user): User { if ($user->id < 1) { throw new RuntimeException('The model does not have ID'); @@ -77,7 +77,7 @@ class Save extends Action * * @return int */ - public function insert(User $user) + public function insert(User $user): int { if (null !== $user->id) { throw new RuntimeException('The model has ID'); diff --git a/app/Models/User/Stats.php b/app/Models/User/Stats.php index 8fc21bfc..7b0160af 100644 --- a/app/Models/User/Stats.php +++ b/app/Models/User/Stats.php @@ -11,7 +11,7 @@ class Stats extends Action * * @return array */ - public function stats() + public function stats(): array { $total = $this->c->DB->query('SELECT COUNT(u.id)-1 FROM ::users AS u WHERE u.group_id!=0')->fetchColumn(); $last = $this->c->DB->query('SELECT u.id, u.username FROM ::users AS u WHERE u.group_id!=0 ORDER BY u.registered DESC LIMIT 1')->fetch(); diff --git a/app/Models/User/UpdateCountPosts.php b/app/Models/User/UpdateCountPosts.php index ae92a9f0..6e8f6058 100644 --- a/app/Models/User/UpdateCountPosts.php +++ b/app/Models/User/UpdateCountPosts.php @@ -15,7 +15,7 @@ class UpdateCountPosts extends Action * * @throws InvalidArgumentException */ - public function updateCountPosts(...$args) + public function updateCountPosts(...$args): void { $ids = []; foreach ($args as $arg) { diff --git a/app/Models/User/UpdateCountTopics.php b/app/Models/User/UpdateCountTopics.php index a211afe1..3794b00f 100644 --- a/app/Models/User/UpdateCountTopics.php +++ b/app/Models/User/UpdateCountTopics.php @@ -15,7 +15,7 @@ class UpdateCountTopics extends Action * * @throws InvalidArgumentException */ - public function updateCountTopics(...$args) + public function updateCountTopics(...$args): void { $ids = []; foreach ($args as $arg) { diff --git a/app/Models/User/UpdateLastVisit.php b/app/Models/User/UpdateLastVisit.php index 45f77a1e..9a29aa6f 100644 --- a/app/Models/User/UpdateLastVisit.php +++ b/app/Models/User/UpdateLastVisit.php @@ -10,12 +10,12 @@ class UpdateLastVisit extends Action { /** * Обновляет время последнего визита пользователя - * + * * @param User $user * * @throws RuntimeException */ - public function updateLastVisit(User $user) + public function updateLastVisit(User $user): void { if ($user->id < 2) { throw new RuntimeException('Expected user'); diff --git a/app/Models/User/UsersNumber.php b/app/Models/User/UsersNumber.php index 00b181b4..3574f0f9 100644 --- a/app/Models/User/UsersNumber.php +++ b/app/Models/User/UsersNumber.php @@ -14,7 +14,7 @@ class UsersNumber extends Action * * @return int */ - public function usersNumber(Group $group) + public function usersNumber(Group $group): int { if (empty($group->g_id) || $group->g_id === $this->c->GROUP_GUEST) { return 0; diff --git a/app/Models/Validators/Email.php b/app/Models/Validators/Email.php index 948a7ad5..7daed88f 100644 --- a/app/Models/Validators/Email.php +++ b/app/Models/Validators/Email.php @@ -20,7 +20,7 @@ class Email extends Validators * * @return string */ - public function email(Validator $v, $email, $attrs, $originalUser) + public function email(Validator $v, $email, $attrs, $originalUser): ?string { // поле отсутствует if (null === $email) { diff --git a/app/Models/Validators/Username.php b/app/Models/Validators/Username.php index 7250a982..8b45ce95 100644 --- a/app/Models/Validators/Username.php +++ b/app/Models/Validators/Username.php @@ -18,7 +18,7 @@ class Username extends Validators * * @return null|string */ - public function username(Validator $v, $username, $z, $originalUser) + public function username(Validator $v, $username, $z, $originalUser): ?string { if ($originalUser instanceof User) { $id = $originalUser->id; diff --git a/app/functions.php b/app/functions.php index fa7a3015..f02384d0 100644 --- a/app/functions.php +++ b/app/functions.php @@ -9,28 +9,28 @@ use ForkBB\Core\Container; * * @param Container $c */ -function _init(Container $c) +function _init(Container $c): void { - __($c); - cens($c); - dt($c); + __(null, $c); + cens('', $c); + dt(0, true, '', '', true, true, $c); } /** * Транслирует строку с подстановкой аргументов * - * @param Container|string $arg + * @param string $arg * @param mixed ...$args * * @return string */ -function __($arg, ...$args) +function __(?string $arg, ...$args): string { static $c; - if (empty($c)) { - $c = $arg; - return; + if (null === $arg && $args[0] instanceof Container) { + $c = $args[0]; + return ''; } $tr = $c->Lang->get($arg); @@ -62,7 +62,7 @@ function __($arg, ...$args) * * @return string */ -function e($arg) +function e(string $arg): string { return \htmlspecialchars($arg, \ENT_HTML5 | \ENT_QUOTES | \ENT_SUBSTITUTE, 'UTF-8'); } @@ -70,17 +70,18 @@ function e($arg) /** * Цензура * - * @param Container|string $arg + * @param string $arg + * @param Container $container * * @return string */ -function cens($arg) +function cens(string $arg, Container $container = null): string { static $c; - if (empty($c)) { - $c = $arg; - return; + if (null !== $container) { + $c = $container; + return ''; } return $c->censorship->censor($arg); @@ -94,7 +95,7 @@ function cens($arg) * * @return string */ -function num($number, $decimals = 0) +function num($number, int $decimals = 0): string { return \is_numeric($number) ? \number_format($number, $decimals, __('lang_decimal_point'), __('lang_thousands_sep')) @@ -104,22 +105,23 @@ function num($number, $decimals = 0) /** * Возвращает дату/время в формате текущего пользователя * - * @param Container|int $arg + * @param int $arg * @param bool $dateOnly * @param string $dateFormat * @param string $timeFormat * @param bool $timeOnly * @param bool $noText + * @param Container $container * * @return string */ -function dt($arg, $dateOnly = false, $dateFormat = null, $timeFormat = null, $timeOnly = false, $noText = false) +function dt(int $arg, bool $dateOnly = false, string $dateFormat = null, string $timeFormat = null, bool $timeOnly = false, bool $noText = false, Container $container = null): string { static $c; - if (empty($c)) { - $c = $arg; - return; + if (null !== $container) { + $c = $container; + return ''; } if (empty($arg)) { @@ -164,7 +166,7 @@ function dt($arg, $dateOnly = false, $dateFormat = null, $timeFormat = null, $ti * * @return string */ -function utc($timestamp) +function utc(int $timestamp): string { return \gmdate('c', $timestamp); // Y-m-d\TH:i:s\Z } @@ -176,7 +178,7 @@ function utc($timestamp) * * @return string */ -function size($size) +function size(int $size): string { $units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB'];