From 41703b50f950098be60c2336d2681f297fd6529b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20D?= Date: Sun, 20 Dec 2020 14:24:42 +0100 Subject: [PATCH] * [MOD] Strict type checking (WIP) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rubén D --- app/modules/api/Init.php | 2 +- .../web/Controllers/BootstrapController.php | 4 +- .../web/Controllers/ControllerBase.php | 5 +- .../web/Controllers/Helpers/Grid/GridBase.php | 4 +- app/modules/web/Forms/AccountForm.php | 2 +- app/modules/web/Init.php | 10 +- .../material-blue/views/_layouts/main.inc | 2 +- .../views/_partials/fixed-header.inc | 2 +- lib/BaseFunctions.php | 22 ++-- lib/SP/Bootstrap.php | 4 +- lib/SP/Config/ConfigUtil.php | 2 +- .../Core/Acl/AccountPermissionException.php | 2 +- lib/SP/Core/Acl/Acl.php | 8 +- lib/SP/Core/Acl/Actions.php | 6 +- .../Core/Acl/UnauthorizedActionException.php | 10 +- lib/SP/Core/Acl/UnauthorizedPageException.php | 8 +- lib/SP/Core/Context/ContextInterface.php | 34 ++--- lib/SP/Core/Context/SessionContext.php | 94 +++++++------- lib/SP/Core/Context/StatelessContext.php | 40 +++--- lib/SP/Core/Crypt/CSRF.php | 4 +- lib/SP/Core/Crypt/Cookie.php | 10 +- lib/SP/Core/Crypt/Crypt.php | 12 +- lib/SP/Core/Crypt/CryptPKI.php | 10 +- lib/SP/Core/Crypt/Hash.php | 10 +- lib/SP/Core/Crypt/SecureKeyCookie.php | 8 +- lib/SP/Core/Crypt/Session.php | 4 +- lib/SP/Core/Crypt/UUIDCookie.php | 6 +- lib/SP/Core/Crypt/Vault.php | 16 +-- lib/SP/Core/DataCollection.php | 17 ++- lib/SP/Core/Events/Event.php | 9 +- lib/SP/Core/Events/EventDispatcherBase.php | 10 +- .../Core/Events/EventDispatcherInterface.php | 6 +- lib/SP/Core/Events/EventMessage.php | 34 ++--- lib/SP/Core/Events/EventReceiver.php | 8 +- lib/SP/Core/Language.php | 12 +- lib/SP/Core/Messages/HtmlFormatter.php | 2 +- lib/SP/Core/Messages/LogMessage.php | 18 +-- lib/SP/Core/Messages/MailMessage.php | 4 +- lib/SP/Core/Messages/MessageBase.php | 2 +- lib/SP/Core/Messages/MessageInterface.php | 6 +- lib/SP/Core/Messages/NotificationMessage.php | 4 +- lib/SP/Core/Messages/TaskMessage.php | 41 +++---- lib/SP/Core/ModuleBase.php | 6 +- lib/SP/Core/PhpExtensionChecker.php | 26 ++-- lib/SP/Core/UI/Theme.php | 35 ++++-- lib/SP/Core/UI/ThemeInterface.php | 14 +-- lib/SP/DataModel/ItemSearchData.php | 32 ++--- lib/SP/Html/Assets/FontIcon.php | 10 +- lib/SP/Html/Assets/IconBase.php | 22 ++-- lib/SP/Html/Assets/IconInterface.php | 16 +-- lib/SP/Html/Assets/ImageIcon.php | 6 +- .../DataGrid/Action/DataGridActionBase.php | 90 +++++++------- .../Action/DataGridActionInterface.php | 100 +++++++-------- .../DataGrid/Action/DataGridActionSearch.php | 6 +- lib/SP/Html/DataGrid/DataGrid.php | 4 +- lib/SP/Html/DataGrid/DataGridBase.php | 83 +++++++------ lib/SP/Html/DataGrid/DataGridDataBase.php | 37 +++--- .../Html/DataGrid/DataGridDataInterface.php | 25 ++-- lib/SP/Html/DataGrid/DataGridInterface.php | 48 ++++---- lib/SP/Html/DataGrid/DataGridSort.php | 26 ++-- .../Html/DataGrid/DataGridSortInterface.php | 24 ++-- lib/SP/Html/DataGrid/DataGridTab.php | 4 +- .../DataGrid/Layout/DataGridHeaderBase.php | 4 +- .../Layout/DataGridHeaderInterface.php | 4 +- .../DataGrid/Layout/DataGridHeaderSort.php | 10 +- lib/SP/Html/Html.php | 25 ++-- lib/SP/Html/Minify.php | 40 +++--- lib/SP/Http/Address.php | 8 +- lib/SP/Http/Client.php | 2 +- lib/SP/Http/Json.php | 18 +-- lib/SP/Http/JsonResponse.php | 44 +++---- lib/SP/Http/Message.php | 16 +-- lib/SP/Http/Request.php | 54 ++++---- lib/SP/Http/Uri.php | 12 +- lib/SP/Http/XMLRPCResponseParse.php | 18 +-- lib/SP/Mvc/Controller/ControllerTrait.php | 9 +- lib/SP/Mvc/Controller/ItemTrait.php | 26 ++-- .../Validators/PasswordValidator.php | 2 +- .../Mvc/Controller/Validators/Validator.php | 16 +-- lib/SP/Mvc/Model/QueryCondition.php | 14 +-- lib/SP/Mvc/View/Template.php | 96 +++++++-------- lib/SP/Plugin/PluginBase.php | 12 +- lib/SP/Plugin/PluginInterface.php | 32 ++--- lib/SP/Plugin/PluginManager.php | 18 +-- lib/SP/Plugin/PluginOperation.php | 4 +- lib/SP/Providers/Acl/AclHandler.php | 6 +- lib/SP/Providers/Auth/AuthDataBase.php | 38 +++--- lib/SP/Providers/Auth/AuthInterface.php | 2 +- lib/SP/Providers/Auth/AuthResult.php | 8 +- lib/SP/Providers/Auth/Browser/Browser.php | 10 +- lib/SP/Providers/Auth/Database/Database.php | 14 ++- lib/SP/Providers/Auth/Ldap/Ldap.php | 6 +- lib/SP/Providers/Auth/Ldap/LdapActions.php | 28 +++-- lib/SP/Providers/Auth/Ldap/LdapAuth.php | 15 ++- lib/SP/Providers/Auth/Ldap/LdapAuthData.php | 14 +-- lib/SP/Providers/Auth/Ldap/LdapConnection.php | 25 ++-- .../Auth/Ldap/LdapConnectionInterface.php | 10 +- lib/SP/Providers/Auth/Ldap/LdapInterface.php | 10 +- lib/SP/Providers/Auth/Ldap/LdapMsAds.php | 4 +- lib/SP/Providers/Auth/Ldap/LdapParams.php | 48 ++++---- lib/SP/Providers/Auth/Ldap/LdapStd.php | 4 +- lib/SP/Providers/Auth/Ldap/LdapUtil.php | 6 +- lib/SP/Providers/Log/DatabaseLogHandler.php | 6 +- lib/SP/Providers/Log/FileLogHandler.php | 4 +- lib/SP/Providers/Log/LoggerBase.php | 8 +- lib/SP/Providers/Log/RemoteSyslogHandler.php | 4 +- lib/SP/Providers/Log/SyslogHandler.php | 4 +- lib/SP/Providers/Mail/MailHandler.php | 6 +- lib/SP/Providers/Mail/MailProvider.php | 4 +- .../Notification/NotificationHandler.php | 6 +- .../Account/AccountHistoryRepository.php | 6 +- .../Notification/NotificationRepository.php | 20 +-- lib/SP/Services/Account/AccountAcl.php | 54 ++++---- lib/SP/Services/Account/AccountAclService.php | 8 +- lib/SP/Services/Backup/FileBackupService.php | 4 +- lib/SP/Services/Import/SyspassImport.php | 2 +- lib/SP/Services/User/UserPassService.php | 2 +- .../Storage/Database/DBStorageInterface.php | 18 +-- lib/SP/Storage/Database/Database.php | 52 ++++---- .../Database/DatabaseConnectionData.php | 38 +++--- .../Database/DatabaseFileInterface.php | 2 +- lib/SP/Storage/Database/DatabaseInterface.php | 28 ++--- lib/SP/Storage/Database/DatabaseUtil.php | 8 +- lib/SP/Storage/Database/MySQLFileParser.php | 2 +- lib/SP/Storage/Database/MySQLHandler.php | 12 +- lib/SP/Storage/Database/QueryData.php | 116 ++++++------------ lib/SP/Storage/Database/QueryResult.php | 18 ++- lib/SP/Storage/File/ArchiveHandler.php | 2 +- lib/SP/Storage/File/FileCache.php | 2 +- lib/SP/Storage/File/FileCacheBase.php | 8 +- lib/SP/Storage/File/FileCacheInterface.php | 8 +- lib/SP/Storage/File/FileCachePacked.php | 2 +- lib/SP/Storage/File/FileHandler.php | 30 ++--- .../Storage/File/XmlFileStorageInterface.php | 6 +- lib/SP/Storage/File/XmlHandler.php | 6 +- lib/SP/Util/ArrayUtil.php | 13 +- lib/SP/Util/Checks.php | 6 +- lib/SP/Util/Connection.php | 35 +++--- lib/SP/Util/ConnectionInterface.php | 6 +- lib/SP/Util/DateUtil.php | 4 +- lib/SP/Util/ErrorUtil.php | 21 ++-- lib/SP/Util/FileUtil.php | 4 +- lib/SP/Util/Filter.php | 10 +- lib/SP/Util/ImageUtil.php | 4 +- lib/SP/Util/Link.php | 7 +- lib/SP/Util/PasswordUtil.php | 10 +- lib/SP/Util/Util.php | 15 +-- lib/SP/Util/VersionUtil.php | 10 +- .../NotificationRepositoryTest.php | 14 +-- tests/res/config/config.xml | 6 +- tests/res/scripts/reset_db.sh | 9 ++ 151 files changed, 1303 insertions(+), 1227 deletions(-) diff --git a/app/modules/api/Init.php b/app/modules/api/Init.php index a7223970..39e4741b 100644 --- a/app/modules/api/Init.php +++ b/app/modules/api/Init.php @@ -79,7 +79,7 @@ final class Init extends ModuleBase * @throws EnvironmentIsBrokenException * @throws FileException */ - public function initialize($controller) + public function initialize(string $controller) { logger(__FUNCTION__); diff --git a/app/modules/web/Controllers/BootstrapController.php b/app/modules/web/Controllers/BootstrapController.php index a8fd69f1..5e0c14c3 100644 --- a/app/modules/web/Controllers/BootstrapController.php +++ b/app/modules/web/Controllers/BootstrapController.php @@ -162,9 +162,9 @@ final class BootstrapController extends SimpleControllerBase /** * Generate the CSRF token if not set * - * @return bool + * @return string|null */ - private function getCSRF() + private function getCSRF(): ?string { logger(sprintf('CSRF key (get): %s', $this->session->getCSRF())); diff --git a/app/modules/web/Controllers/ControllerBase.php b/app/modules/web/Controllers/ControllerBase.php index fe12348e..aa1eb361 100644 --- a/app/modules/web/Controllers/ControllerBase.php +++ b/app/modules/web/Controllers/ControllerBase.php @@ -94,7 +94,6 @@ abstract class ControllerBase * * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface - * @throws SessionTimeout */ public final function __construct(Container $container, $actionName) { @@ -158,6 +157,8 @@ abstract class ControllerBase /** * @return void + * @throws DependencyException + * @throws NotFoundException */ private function handleSessionTimeout() { @@ -193,7 +194,7 @@ abstract class ControllerBase /** * Renderizar los datos de la plantilla y devolverlos */ - protected function render() + protected function render(): string { try { return $this->view->render(); diff --git a/app/modules/web/Controllers/Helpers/Grid/GridBase.php b/app/modules/web/Controllers/Helpers/Grid/GridBase.php index 2906c6d0..3bdf66f8 100644 --- a/app/modules/web/Controllers/Helpers/Grid/GridBase.php +++ b/app/modules/web/Controllers/Helpers/Grid/GridBase.php @@ -64,7 +64,7 @@ abstract class GridBase extends HelperBase implements GridInterface * * @return DataGridInterface */ - public function updatePager(DataGridInterface $dataGrid, ItemSearchData $itemSearchData) + public function updatePager(DataGridInterface $dataGrid, ItemSearchData $itemSearchData): DataGridInterface { $dataGrid->getPager() ->setLimitStart($itemSearchData->getLimitStart()) @@ -83,7 +83,7 @@ abstract class GridBase extends HelperBase implements GridInterface * * @return DataGridPager */ - final protected function getPager(DataGridActionSearch $sourceAction) + final protected function getPager(DataGridActionSearch $sourceAction): DataGridPager { $gridPager = new DataGridPager(); $gridPager->setSourceAction($sourceAction); diff --git a/app/modules/web/Forms/AccountForm.php b/app/modules/web/Forms/AccountForm.php index 254fd924..4ad7c6a9 100644 --- a/app/modules/web/Forms/AccountForm.php +++ b/app/modules/web/Forms/AccountForm.php @@ -52,7 +52,7 @@ final class AccountForm extends FormBase implements FormInterface /** * Validar el formulario * - * @param $action + * @param int $action * * @return AccountForm * @throws ValidationException diff --git a/app/modules/web/Init.php b/app/modules/web/Init.php index b8551196..b62e702c 100644 --- a/app/modules/web/Init.php +++ b/app/modules/web/Init.php @@ -151,7 +151,7 @@ final class Init extends ModuleBase * @throws NoSuchItemException * @throws Exception */ - public function initialize($controller) + public function initialize(string $controller) { logger(__METHOD__); @@ -318,7 +318,7 @@ final class Init extends ModuleBase * * @throws FileException */ - private function checkUpgrade() + private function checkUpgrade(): bool { UpgradeUtil::fixAppUpgrade($this->configData, $this->config); @@ -376,7 +376,7 @@ final class Init extends ModuleBase * * @return int con el tiempo en segundos */ - private function getSessionLifeTime() + private function getSessionLifeTime(): int { $timeout = $this->context->getSessionTimeout(); @@ -396,7 +396,7 @@ final class Init extends ModuleBase } /** - * @param int $default + * @param int|null $default * * @return int * @throws ConstraintException @@ -404,7 +404,7 @@ final class Init extends ModuleBase * @throws NoSuchPropertyException * @throws QueryException */ - private function getSessionTimeoutForUser(int $default = null) + private function getSessionTimeoutForUser(?int $default = null): ?int { if ($this->context->isLoggedIn()) { $itemPreset = $this->itemPresetService->getForCurrentUser(ItemPresetInterface::ITEM_TYPE_SESSION_TIMEOUT); diff --git a/app/modules/web/themes/material-blue/views/_layouts/main.inc b/app/modules/web/themes/material-blue/views/_layouts/main.inc index 3fe97f8e..e0936bf1 100644 --- a/app/modules/web/themes/material-blue/views/_layouts/main.inc +++ b/app/modules/web/themes/material-blue/views/_layouts/main.inc @@ -37,7 +37,7 @@ use SP\Mvc\View\Template; includePartial('fixed-header'); - elseif ($this->hashContentTemplates()): + elseif ($this->hasContentTemplates()): foreach ($this->getContentTemplates() as $template): include $template; endforeach; diff --git a/app/modules/web/themes/material-blue/views/_partials/fixed-header.inc b/app/modules/web/themes/material-blue/views/_partials/fixed-header.inc index b9ab3192..fa2ffd16 100644 --- a/app/modules/web/themes/material-blue/views/_partials/fixed-header.inc +++ b/app/modules/web/themes/material-blue/views/_partials/fixed-header.inc @@ -186,7 +186,7 @@ use SP\Mvc\View\Template;
- hashContentTemplates()): + hasContentTemplates()): foreach ($this->getContentTemplates() as $template): include $template; endforeach; diff --git a/lib/BaseFunctions.php b/lib/BaseFunctions.php index a64b858d..f2052cd5 100644 --- a/lib/BaseFunctions.php +++ b/lib/BaseFunctions.php @@ -40,10 +40,10 @@ define('LOG_FORMAT_OWN', '[%s] syspass.%s: logger {"message":"%s","caller":"%s"} * * A more advanced event logging should be handled through EventDispatcher * - * @param mixed $data - * @param string $type + * @param mixed $data + * @param string|null $type */ -function logger($data, $type = 'DEBUG') +function logger($data, ?string $type = 'DEBUG') { if (!DEBUG && $type === 'DEBUG') { return; @@ -88,7 +88,7 @@ function printLastCallers() * * @return string */ -function getLastCaller($skip = 2) +function getLastCaller($skip = 2): string { $callers = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 5); @@ -104,7 +104,7 @@ function getLastCaller($skip = 2) * * @return string */ -function formatStackTrace(Throwable $e) +function formatStackTrace(Throwable $e): string { $out = []; @@ -156,11 +156,11 @@ function processException(\Exception $exception) } /** - * @param $trace + * @param array $trace * * @return string */ -function formatTrace($trace) +function formatTrace(array $trace): string { $btLine = []; $i = 0; @@ -185,7 +185,7 @@ function formatTrace($trace) * * @return string */ -function __($message, $translate = true) +function __(string $message, $translate = true): string { return $translate === true && $message !== '' && mb_strlen($message) < 4096 ? gettext($message) : $message; } @@ -198,7 +198,7 @@ function __($message, $translate = true) * * @return string */ -function __u($message) +function __u(string $message): string { return $message; } @@ -212,7 +212,7 @@ function __u($message) * * @return string */ -function _t($domain, $message, $translate = true) +function _t(string $domain, string $message, bool $translate = true): string { return $translate === true && $message !== '' && mb_strlen($message) < 4096 ? dgettext($domain, $message) : $message; } @@ -224,7 +224,7 @@ function _t($domain, $message, $translate = true) * * @return string */ -function mb_ucfirst($string) +function mb_ucfirst($string): string { return mb_strtoupper(mb_substr($string, 0, 1)); } diff --git a/lib/SP/Bootstrap.php b/lib/SP/Bootstrap.php index f51c6015..3c8a0605 100644 --- a/lib/SP/Bootstrap.php +++ b/lib/SP/Bootstrap.php @@ -452,9 +452,9 @@ final class Bootstrap * @throws DependencyException * @throws NotFoundException */ - public static function run(Container $container, $module = APP_MODULE) + public static function run(Container $container, string $module = APP_MODULE) { - $bs = new static($container); + $bs = new Bootstrap($container); switch ($module) { case 'web': diff --git a/lib/SP/Config/ConfigUtil.php b/lib/SP/Config/ConfigUtil.php index d7cc3f5e..a06ab5f4 100644 --- a/lib/SP/Config/ConfigUtil.php +++ b/lib/SP/Config/ConfigUtil.php @@ -41,7 +41,7 @@ final class ConfigUtil * * @return array */ - public static function filesExtsAdapter($filesAllowedExts) + public static function filesExtsAdapter(string $filesAllowedExts) { if (empty($filesAllowedExts)) { return []; diff --git a/lib/SP/Core/Acl/AccountPermissionException.php b/lib/SP/Core/Acl/AccountPermissionException.php index f28a176b..2c4d2e86 100644 --- a/lib/SP/Core/Acl/AccountPermissionException.php +++ b/lib/SP/Core/Acl/AccountPermissionException.php @@ -41,7 +41,7 @@ final class AccountPermissionException extends SPException * @param int $code * @param Exception|null $previous */ - public function __construct($type, $code = 0, Exception $previous = null) + public function __construct(string $type, $code = 0, Exception $previous = null) { parent::__construct(__u('You don\'t have permission to access this account'), $type, __u('Please contact to the administrator'), $code, $previous); } diff --git a/lib/SP/Core/Acl/Acl.php b/lib/SP/Core/Acl/Acl.php index cca4756d..f94831aa 100644 --- a/lib/SP/Core/Acl/Acl.php +++ b/lib/SP/Core/Acl/Acl.php @@ -69,11 +69,11 @@ final class Acl implements ActionsInterface /** * Returns action route * - * @param $actionId + * @param string $actionId * * @return string */ - public static function getActionRoute($actionId) + public static function getActionRoute(string $actionId): string { try { return self::$action !== null ? self::$action->getActionById($actionId)->getRoute() : ''; @@ -93,7 +93,7 @@ final class Acl implements ActionsInterface * @return string * @internal param bool $shortName Si se devuelve el nombre corto de la acción */ - public static function getActionInfo($actionId, $translate = true) + public static function getActionInfo(int $actionId, $translate = true): string { try { $text = self::$action->getActionById($actionId)->getText(); @@ -113,7 +113,7 @@ final class Acl implements ActionsInterface * * @return bool */ - public function checkUserAccess($action, $userId = 0) + public function checkUserAccess(int $action, $userId = 0): bool { if (!($userProfile = $this->context->getUserProfile())) { return false; diff --git a/lib/SP/Core/Acl/Actions.php b/lib/SP/Core/Acl/Actions.php index 8caed340..7b276e6d 100644 --- a/lib/SP/Core/Acl/Actions.php +++ b/lib/SP/Core/Acl/Actions.php @@ -144,7 +144,7 @@ final class Actions * @return ActionData[] * @throws FileException */ - protected function load() + protected function load(): array { return $this->xmlFileStorage->load('actions')->getItems(); } @@ -166,12 +166,12 @@ final class Actions /** * Returns an action by id * - * @param $id + * @param int $id * * @return ActionData * @throws ActionNotFoundException */ - public function getActionById($id) + public function getActionById(int $id): ActionData { if (!isset($this->actions[$id])) { throw new ActionNotFoundException(__u('Action not found')); diff --git a/lib/SP/Core/Acl/UnauthorizedActionException.php b/lib/SP/Core/Acl/UnauthorizedActionException.php index 5bdf773a..6127b3d7 100644 --- a/lib/SP/Core/Acl/UnauthorizedActionException.php +++ b/lib/SP/Core/Acl/UnauthorizedActionException.php @@ -42,8 +42,14 @@ final class UnauthorizedActionException extends SPException * @param int $code * @param Exception|null $previous */ - public function __construct($type, $code = 0, Exception $previous = null) + public function __construct(string $type, $code = 0, Exception $previous = null) { - parent::__construct(__u('You don\'t have permission to do this operation'), $type, __u('Please contact to the administrator'), $code, $previous); + parent::__construct( + __u('You don\'t have permission to do this operation'), + $type, + __u('Please contact to the administrator'), + $code, + $previous + ); } } \ No newline at end of file diff --git a/lib/SP/Core/Acl/UnauthorizedPageException.php b/lib/SP/Core/Acl/UnauthorizedPageException.php index d50b8fa3..dbc00879 100644 --- a/lib/SP/Core/Acl/UnauthorizedPageException.php +++ b/lib/SP/Core/Acl/UnauthorizedPageException.php @@ -43,7 +43,13 @@ final class UnauthorizedPageException extends SPException */ public function __construct($type, $code = 0, Exception $previous = null) { - parent::__construct(__u('You don\'t have permission to access this page'), $type, __u('Please contact to the administrator'), $code, $previous); + parent::__construct( + __u('You don\'t have permission to access this page'), + $type, + __u('Please contact to the administrator'), + $code, + $previous + ); } } \ No newline at end of file diff --git a/lib/SP/Core/Context/ContextInterface.php b/lib/SP/Core/Context/ContextInterface.php index 1b1eea25..46390c2b 100644 --- a/lib/SP/Core/Context/ContextInterface.php +++ b/lib/SP/Core/Context/ContextInterface.php @@ -45,28 +45,28 @@ interface ContextInterface * * @param int $time */ - public function setConfigTime($time); + public function setConfigTime(int $time); /** * Devolver la hora de carga de la configuración * * @return int */ - public function getConfigTime(); + public function getConfigTime(): int; /** * Establece los datos del usuario en la sesión. * - * @param UserLoginResponse $userLoginResponse + * @param UserLoginResponse|null $userLoginResponse */ - public function setUserData(UserLoginResponse $userLoginResponse = null); + public function setUserData(?UserLoginResponse $userLoginResponse = null); /** * Obtiene el objeto de perfil de usuario de la sesión. * - * @return ProfileData + * @return ProfileData|null */ - public function getUserProfile(); + public function getUserProfile(): ?ProfileData; /** * Establece el objeto de perfil de usuario en la sesión. @@ -80,14 +80,14 @@ interface ContextInterface * * @return bool */ - public function isLoggedIn(); + public function isLoggedIn(): bool; /** * Devuelve los datos del usuario en la sesión. * - * @return UserLoginResponse + * @return UserLoginResponse|null */ - public function getUserData(); + public function getUserData(): ?UserLoginResponse; /** * Establecer el lenguaje de la sesión @@ -99,35 +99,35 @@ interface ContextInterface /** * Devuelve el lenguaje de la sesión * - * @return string + * @return string|null */ - public function getLocale(); + public function getLocale(): ?string; /** * Devuelve el estado de la aplicación * - * @return bool + * @return bool|null */ - public function getAppStatus(); + public function getAppStatus(): ?bool; /** * Establecer el estado de la aplicación * * @param string $status */ - public function setAppStatus($status); + public function setAppStatus(string $status); /** * Reset del estado de la aplicación * - * @return bool + * @return bool|null */ - public function resetAppStatus(); + public function resetAppStatus(): ?bool; /** * @return AccountCache[]|null */ - public function getAccountsCache(); + public function getAccountsCache(): ?array; /** * Sets an arbitrary key in the trasient collection. diff --git a/lib/SP/Core/Context/SessionContext.php b/lib/SP/Core/Context/SessionContext.php index 7d3d1d7e..31dd4ab5 100644 --- a/lib/SP/Core/Context/SessionContext.php +++ b/lib/SP/Core/Context/SessionContext.php @@ -45,7 +45,7 @@ final class SessionContext extends ContextBase /** * @return bool */ - public static function isLocked() + public static function isLocked(): bool { return self::$isLocked; } @@ -81,7 +81,7 @@ final class SessionContext extends ContextBase * * @return string */ - public function getTheme() + public function getTheme(): string { return $this->getContextKey('theme'); } @@ -110,7 +110,7 @@ final class SessionContext extends ContextBase * * @param $theme string El tema visual a utilizar */ - public function setTheme($theme) + public function setTheme(string $theme) { $this->setContextKey('theme', $theme); } @@ -145,7 +145,7 @@ final class SessionContext extends ContextBase * * @param int $time */ - public function setConfigTime($time) + public function setConfigTime(int $time) { $this->setContextKey('configTime', (int)$time); } @@ -155,15 +155,15 @@ final class SessionContext extends ContextBase * * @return int */ - public function getConfigTime() + public function getConfigTime(): int { - return $this->getContextKey('configTime'); + return (int)$this->getContextKey('configTime'); } /** * Establece los datos del usuario en la sesión. * - * @param UserLoginResponse $userLoginResponse + * @param UserLoginResponse|null $userLoginResponse */ public function setUserData(UserLoginResponse $userLoginResponse = null) { @@ -173,9 +173,9 @@ final class SessionContext extends ContextBase /** * Obtiene el objeto de perfil de usuario de la sesión. * - * @return ProfileData + * @return ProfileData|null */ - public function getUserProfile() + public function getUserProfile(): ?ProfileData { return $this->getContextKey('userProfile'); } @@ -191,11 +191,11 @@ final class SessionContext extends ContextBase } /** - * @return AccountSearchFilter + * @return AccountSearchFilter|null */ - public function getSearchFilters() + public function getSearchFilters(): ?AccountSearchFilter { - return $this->getContextKey('searchFilters', null); + return $this->getContextKey('searchFilters'); } /** @@ -216,7 +216,7 @@ final class SessionContext extends ContextBase * * @return bool */ - public function isLoggedIn() + public function isLoggedIn(): bool { return self::$isReset === false && $this->getUserData()->getLogin() && is_object($this->getUserData()->getPreferences()); @@ -227,7 +227,7 @@ final class SessionContext extends ContextBase * * @return UserLoginResponse */ - public function getUserData() + public function getUserData(): UserLoginResponse { return $this->getContextKey('userData', new UserLoginResponse()); } @@ -253,9 +253,9 @@ final class SessionContext extends ContextBase /** * Devolver la clave maestra temporal * - * @return string + * @return ?string */ - public function getTemporaryMasterPass() + public function getTemporaryMasterPass(): ?string { return $this->getContextKey('tempmasterpass'); } @@ -273,9 +273,9 @@ final class SessionContext extends ContextBase /** * Devolver la clave pública * - * @return mixed + * @return string|null */ - public function getPublicKey() + public function getPublicKey(): ?string { return $this->getContextKey('pubkey'); } @@ -295,7 +295,7 @@ final class SessionContext extends ContextBase * * @return int|null El valor en segundos */ - public function getSessionTimeout() + public function getSessionTimeout(): ?int { return $this->getContextKey('sessionTimeout'); } @@ -307,7 +307,7 @@ final class SessionContext extends ContextBase * * @return int */ - public function setSessionTimeout($timeout) + public function setSessionTimeout(int $timeout): int { $this->setContextKey('sessionTimeout', $timeout); @@ -319,7 +319,7 @@ final class SessionContext extends ContextBase * * @return int */ - public function getLastActivity() + public function getLastActivity(): int { return $this->getContextKey('lastActivity', 0); } @@ -329,7 +329,7 @@ final class SessionContext extends ContextBase * * @param $time int La marca de hora */ - public function setLastActivity($time) + public function setLastActivity(int $time) { $this->setContextKey('lastActivity', $time); } @@ -339,7 +339,7 @@ final class SessionContext extends ContextBase * * @return int */ - public function getStartActivity() + public function getStartActivity(): int { return $this->getContextKey('startActivity', 0); } @@ -357,9 +357,9 @@ final class SessionContext extends ContextBase /** * Devuelve el lenguaje de la sesión * - * @return string + * @return string|null */ - public function getLocale() + public function getLocale(): ?string { return $this->getContextKey('locale'); } @@ -387,9 +387,9 @@ final class SessionContext extends ContextBase /** * Devuelve el estado de la aplicación * - * @return bool + * @return bool|null */ - public function getAppStatus() + public function getAppStatus(): ?bool { return $this->getContextKey('status'); } @@ -399,7 +399,7 @@ final class SessionContext extends ContextBase * * @param string $status */ - public function setAppStatus($status) + public function setAppStatus(string $status) { $this->setContextKey('status', $status); } @@ -407,9 +407,9 @@ final class SessionContext extends ContextBase /** * Return the CSRF key * - * @return bool + * @return string|null */ - public function getCSRF() + public function getCSRF(): ?string { return $this->getContextKey('csrf'); } @@ -419,7 +419,7 @@ final class SessionContext extends ContextBase * * @param string $csrf */ - public function setCSRF($csrf) + public function setCSRF(string $csrf) { $this->setContextKey('csrf', $csrf); } @@ -427,9 +427,9 @@ final class SessionContext extends ContextBase /** * Reset del estado de la aplicación * - * @return bool + * @return bool|null */ - public function resetAppStatus() + public function resetAppStatus(): ?bool { return $this->setContextKey('status', null); } @@ -437,9 +437,9 @@ final class SessionContext extends ContextBase /** * Devuelve la clave maestra encriptada * - * @return Vault + * @return Vault|null */ - public function getVault() + public function getVault(): ?Vault { return $this->getContextKey('vault'); } @@ -467,9 +467,9 @@ final class SessionContext extends ContextBase /** * Devuelve la cache de cuentas * - * @return AccountCache[] + * @return AccountCache[]|null */ - public function getAccountsCache() + public function getAccountsCache(): ?array { return $this->getContextKey('accountsCache'); } @@ -497,7 +497,7 @@ final class SessionContext extends ContextBase * * @return int */ - public function getSidStartTime() + public function getSidStartTime(): int { return $this->getContextKey('sidStartTime', 0); } @@ -509,7 +509,7 @@ final class SessionContext extends ContextBase * * @return int */ - public function setSidStartTime($time) + public function setSidStartTime(int $time): int { $this->setContextKey('sidStartTime', $time); @@ -523,7 +523,7 @@ final class SessionContext extends ContextBase * * @return int */ - public function setStartActivity($time) + public function setStartActivity(int $time): int { $this->setContextKey('startActivity', $time); @@ -531,32 +531,32 @@ final class SessionContext extends ContextBase } /** - * @param string $ctxKeyName + * @param string $pluginName * @param string $key * @param mixed $value * * @return mixed */ - public function setPluginKey(string $ctxKeyName, string $key, $value) + public function setPluginKey(string $pluginName, string $key, $value) { /** @var ContextCollection $ctxKey */ - $ctxKey = $this->getContextKey($ctxKeyName, new ContextCollection()); + $ctxKey = $this->getContextKey($pluginName, new ContextCollection()); - $this->setContextKey($ctxKeyName, $ctxKey->set($key, $value)); + $this->setContextKey($pluginName, $ctxKey->set($key, $value)); return $value; } /** - * @param string $ctxKeyName + * @param string $pluginName * @param string $key * * @return mixed */ - public function getPluginKey(string $ctxKeyName, string $key) + public function getPluginKey(string $pluginName, string $key) { /** @var ContextCollection $ctxKey */ - $ctxKey = $this->getContextKey($ctxKeyName); + $ctxKey = $this->getContextKey($pluginName); if ($ctxKey !== null) { return $ctxKey->get($key); diff --git a/lib/SP/Core/Context/StatelessContext.php b/lib/SP/Core/Context/StatelessContext.php index 362b0f2d..521f3850 100644 --- a/lib/SP/Core/Context/StatelessContext.php +++ b/lib/SP/Core/Context/StatelessContext.php @@ -34,6 +34,16 @@ use SP\Services\User\UserLoginResponse; */ final class StatelessContext extends ContextBase { + /** + * Establece los datos del usuario en la sesión. + * + * @param UserLoginResponse|null $userLoginResponse + */ + public function setUserData(UserLoginResponse $userLoginResponse = null) + { + $this->setContextKey('userData', $userLoginResponse); + } + /** * Establecer una variable de sesión * @@ -55,22 +65,12 @@ final class StatelessContext extends ContextBase return null; } - /** - * Establece los datos del usuario en la sesión. - * - * @param UserLoginResponse $userLoginResponse - */ - public function setUserData(UserLoginResponse $userLoginResponse = null) - { - $this->setContextKey('userData', $userLoginResponse); - } - /** * Obtiene el objeto de perfil de usuario de la sesión. * * @return ProfileData */ - public function getUserProfile() + public function getUserProfile(): ?ProfileData { return $this->getContextKey('userProfile'); } @@ -109,7 +109,7 @@ final class StatelessContext extends ContextBase * * @return bool */ - public function isLoggedIn() + public function isLoggedIn(): bool { return !empty($this->getUserData()->getLogin()); } @@ -119,7 +119,7 @@ final class StatelessContext extends ContextBase * * @return UserLoginResponse */ - public function getUserData() + public function getUserData(): ?UserLoginResponse { return $this->getContextKey('userData', new UserLoginResponse()); } @@ -139,7 +139,7 @@ final class StatelessContext extends ContextBase * * @return string */ - public function getLocale() + public function getLocale(): ?string { return $this->getContextKey('locale'); } @@ -149,7 +149,7 @@ final class StatelessContext extends ContextBase * * @return bool */ - public function getAppStatus() + public function getAppStatus(): ?bool { return $this->getContextKey('status'); } @@ -159,7 +159,7 @@ final class StatelessContext extends ContextBase * * @param string $status */ - public function setAppStatus($status) + public function setAppStatus(string $status) { $this->setContextKey('status', $status); } @@ -169,7 +169,7 @@ final class StatelessContext extends ContextBase * * @return bool */ - public function resetAppStatus() + public function resetAppStatus(): ?bool { return $this->setContextKey('status', null); } @@ -188,7 +188,7 @@ final class StatelessContext extends ContextBase * * @param int $time */ - public function setConfigTime($time) + public function setConfigTime(int $time) { $this->setContextKey('configTime', (int)$time); } @@ -198,7 +198,7 @@ final class StatelessContext extends ContextBase * * @return int */ - public function getConfigTime() + public function getConfigTime(): int { return $this->getContextKey('configTime'); } @@ -206,7 +206,7 @@ final class StatelessContext extends ContextBase /** * @return null */ - public function getAccountsCache() + public function getAccountsCache(): ?array { return null; } diff --git a/lib/SP/Core/Crypt/CSRF.php b/lib/SP/Core/Crypt/CSRF.php index 520760a9..86fa4989 100644 --- a/lib/SP/Core/Crypt/CSRF.php +++ b/lib/SP/Core/Crypt/CSRF.php @@ -67,7 +67,7 @@ final class CSRF /** * Check for CSRF token on POST requests */ - public function check() + public function check(): bool { $method = strtoupper($this->request->getMethod()); $with = $this->request->getHeader('X-Requested-With'); @@ -98,7 +98,7 @@ final class CSRF * * @return string */ - private function getKey() + private function getKey(): string { return sha1($this->request->getHeader('User-Agent') . $this->request->getClientAddress()); } diff --git a/lib/SP/Core/Crypt/Cookie.php b/lib/SP/Core/Crypt/Cookie.php index eb79e1df..93fdbb38 100644 --- a/lib/SP/Core/Crypt/Cookie.php +++ b/lib/SP/Core/Crypt/Cookie.php @@ -49,7 +49,7 @@ abstract class Cookie * @param string $cookieName * @param Request $request */ - protected function __construct($cookieName, Request $request) + protected function __construct(string $cookieName, Request $request) { $this->cookieName = $cookieName; $this->request = $request; @@ -63,7 +63,7 @@ abstract class Cookie * * @return string */ - public final function sign($data, $cypher) + public final function sign(string $data, string $cypher): string { $data = base64_encode($data); @@ -78,7 +78,7 @@ abstract class Cookie * * @return bool|string */ - public final function getCookieData($data, $cypher) + public final function getCookieData(string $data, string $cypher) { if (strpos($data, ';') === false) { return false; @@ -102,11 +102,11 @@ abstract class Cookie /** * Sets cookie data * - * @param $data + * @param string $data * * @return bool */ - protected function setCookie($data) + protected function setCookie(string $data): bool { // Do not try to set cookies when testing if (APP_MODULE === 'tests') { diff --git a/lib/SP/Core/Crypt/Crypt.php b/lib/SP/Core/Crypt/Crypt.php index fb223cd4..218fda70 100644 --- a/lib/SP/Core/Crypt/Crypt.php +++ b/lib/SP/Core/Crypt/Crypt.php @@ -41,12 +41,12 @@ final class Crypt * * @param string $data * @param string|Key $securedKey - * @param string $password + * @param null $password * * @return string * @throws CryptoException */ - public static function encrypt($data, $securedKey, $password = null) + public static function encrypt(string $data, $securedKey, $password = null) { try { if ($securedKey instanceof Key) { @@ -73,7 +73,7 @@ final class Crypt * @return string|Key * @throws CryptoException */ - public static function unlockSecuredKey($key, $password, $useAscii = true) + public static function unlockSecuredKey(string $key, string $password, $useAscii = true) { try { if ($useAscii) { @@ -93,12 +93,12 @@ final class Crypt * * @param string $data * @param string|Key|KeyProtectedByPassword $securedKey - * @param string $password + * @param null $password * * @return string * @throws CryptoException */ - public static function decrypt($data, $securedKey, $password = null) + public static function decrypt(string $data, $securedKey, $password = null) { try { if ($securedKey instanceof Key) { @@ -129,7 +129,7 @@ final class Crypt * @return string|KeyProtectedByPassword * @throws CryptoException */ - public static function makeSecuredKey($password, $useAscii = true) + public static function makeSecuredKey(string $password, $useAscii = true) { try { if ($useAscii) { diff --git a/lib/SP/Core/Crypt/CryptPKI.php b/lib/SP/Core/Crypt/CryptPKI.php index 8939516b..b3d51835 100644 --- a/lib/SP/Core/Crypt/CryptPKI.php +++ b/lib/SP/Core/Crypt/CryptPKI.php @@ -119,7 +119,7 @@ final class CryptPKI * @return string * @throws FileException */ - public function encryptRSA($data) + public function encryptRSA(string $data): string { $this->rsa->setEncryptionMode(RSA::ENCRYPTION_PKCS1); $this->rsa->loadKey($this->getPublicKey(), RSA::PUBLIC_FORMAT_PKCS1); @@ -133,7 +133,7 @@ final class CryptPKI * @return string * @throws FileException */ - public function getPublicKey() + public function getPublicKey(): string { return $this->publicKeyFile ->checkFileExists() @@ -145,10 +145,10 @@ final class CryptPKI * * @param string $data los datos a desencriptar * - * @return string + * @return string|false * @throws FileException */ - public function decryptRSA($data) + public function decryptRSA(string $data) { $this->rsa->setEncryptionMode(RSA::ENCRYPTION_PKCS1); $this->rsa->loadKey($this->getPrivateKey(), RSA::PRIVATE_FORMAT_PKCS1); @@ -162,7 +162,7 @@ final class CryptPKI * @return string * @throws FileException */ - public function getPrivateKey() + public function getPrivateKey(): string { return $this->privateKeyFile ->checkFileExists() diff --git a/lib/SP/Core/Crypt/Hash.php b/lib/SP/Core/Crypt/Hash.php index 51e28525..2d615715 100644 --- a/lib/SP/Core/Crypt/Hash.php +++ b/lib/SP/Core/Crypt/Hash.php @@ -44,7 +44,7 @@ final class Hash * * @return bool */ - public static function checkHashKey($key, $hash) + public static function checkHashKey(string $key, string $hash): bool { return password_verify(self::getKey($key), $hash); } @@ -57,7 +57,7 @@ final class Hash * * @return string */ - private static function getKey(&$key, $isCheck = true) + private static function getKey(string &$key, $isCheck = true): string { if (mb_strlen($key) > self::MAX_KEY_LENGTH) { $key = hash('sha256', $key); @@ -77,7 +77,7 @@ final class Hash * * @return string con el hash de la clave */ - public static function hashKey($key) + public static function hashKey(string $key): string { return password_hash(self::getKey($key, false), PASSWORD_BCRYPT); } @@ -91,7 +91,7 @@ final class Hash * * @return bool */ - public static function checkMessage($message, $key, $hash) + public static function checkMessage($message, $key, $hash): bool { return hash_equals($hash, self::signMessage($message, $key)); } @@ -104,7 +104,7 @@ final class Hash * * @return string */ - public static function signMessage($message, $key) + public static function signMessage($message, $key): string { return hash_hmac('sha256', $message, $key); } diff --git a/lib/SP/Core/Crypt/SecureKeyCookie.php b/lib/SP/Core/Crypt/SecureKeyCookie.php index 91756ce5..9003f4e1 100644 --- a/lib/SP/Core/Crypt/SecureKeyCookie.php +++ b/lib/SP/Core/Crypt/SecureKeyCookie.php @@ -56,7 +56,7 @@ final class SecureKeyCookie extends Cookie * * @return SecureKeyCookie */ - public static function factory(Request $request) + public static function factory(Request $request): SecureKeyCookie { $self = new self(self::COOKIE_NAME, $request); $self->cypher = $self->getCypher(); @@ -69,7 +69,7 @@ final class SecureKeyCookie extends Cookie * * @return string */ - public function getCypher() + public function getCypher(): string { return sha1($this->request->getHeader('User-Agent') . $this->request->getClientAddress()); } @@ -144,7 +144,7 @@ final class SecureKeyCookie extends Cookie * @throws CryptoException * @throws EnvironmentIsBrokenException */ - public function generateSecuredData() + public function generateSecuredData(): Vault { $this->securedKey = Key::createNewRandomKey(); @@ -155,7 +155,7 @@ final class SecureKeyCookie extends Cookie /** * @return Key */ - public function getSecuredKey() + public function getSecuredKey(): Key { return $this->securedKey; } diff --git a/lib/SP/Core/Crypt/Session.php b/lib/SP/Core/Crypt/Session.php index 4263d966..eaef3734 100644 --- a/lib/SP/Core/Crypt/Session.php +++ b/lib/SP/Core/Crypt/Session.php @@ -42,7 +42,7 @@ final class Session * @return string * @throws CryptoException */ - public static function getSessionKey(SessionContext $sessionContext) + public static function getSessionKey(SessionContext $sessionContext): string { return $sessionContext->getVault()->getData(self::getKey($sessionContext)); } @@ -52,7 +52,7 @@ final class Session * * @return string */ - private static function getKey(SessionContext $sessionContext) + private static function getKey(SessionContext $sessionContext): string { return session_id() . $sessionContext->getSidStartTime(); } diff --git a/lib/SP/Core/Crypt/UUIDCookie.php b/lib/SP/Core/Crypt/UUIDCookie.php index 1457d385..d3865196 100644 --- a/lib/SP/Core/Crypt/UUIDCookie.php +++ b/lib/SP/Core/Crypt/UUIDCookie.php @@ -43,7 +43,7 @@ class UUIDCookie extends Cookie * * @return UUIDCookie */ - public static function factory(Request $request) + public static function factory(Request $request): UUIDCookie { return new self(self::COOKIE_NAME, $request); } @@ -55,7 +55,7 @@ class UUIDCookie extends Cookie * * @return string|false */ - public function createCookie($signKey) + public function createCookie(string $signKey) { $uuid = uniqid('', true); @@ -73,7 +73,7 @@ class UUIDCookie extends Cookie * * @return false|string */ - public function loadCookie($signKey) + public function loadCookie(string $signKey) { $data = $this->getCookie(); diff --git a/lib/SP/Core/Crypt/Vault.php b/lib/SP/Core/Crypt/Vault.php index 16a7fb22..54134a33 100644 --- a/lib/SP/Core/Crypt/Vault.php +++ b/lib/SP/Core/Crypt/Vault.php @@ -53,9 +53,9 @@ final class Vault /** * @return static */ - public static function getInstance() + public static function getInstance(): Vault { - return new static(); + return new Vault(); } /** @@ -67,7 +67,7 @@ final class Vault * @return Vault * @throws CryptoException */ - public function reKey($newSeed, $oldSeed) + public function reKey(string $newSeed, string $oldSeed): Vault { $this->timeUpdated = time(); $sessionMPass = $this->getData($oldSeed); @@ -85,7 +85,7 @@ final class Vault * @return string * @throws CryptoException */ - public function getData($key) + public function getData(string $key): string { return Crypt::decrypt($this->data, $this->key, $key); } @@ -99,7 +99,7 @@ final class Vault * @return $this * @throws CryptoException */ - public function saveData($data, $key) + public function saveData($data, string $key): Vault { if ($this->timeSet === 0) { $this->timeSet = time(); @@ -114,7 +114,7 @@ final class Vault /** * @return int */ - public function getTimeSet() + public function getTimeSet(): int { return $this->timeSet; } @@ -122,7 +122,7 @@ final class Vault /** * @return int */ - public function getTimeUpdated() + public function getTimeUpdated(): int { return $this->timeUpdated; } @@ -130,7 +130,7 @@ final class Vault /** * Serializaes the current object */ - public function getSerialized() + public function getSerialized(): string { return serialize($this); } diff --git a/lib/SP/Core/DataCollection.php b/lib/SP/Core/DataCollection.php index 7c097988..4d21535a 100644 --- a/lib/SP/Core/DataCollection.php +++ b/lib/SP/Core/DataCollection.php @@ -84,7 +84,7 @@ abstract class DataCollection implements IteratorAggregate, ArrayAccess, Countab * * @return boolean */ - public function exists($key) + public function exists(string $key): bool { // Don't use "isset", since it returns false for null values return array_key_exists($key, $this->attributes); @@ -117,7 +117,7 @@ abstract class DataCollection implements IteratorAggregate, ArrayAccess, Countab * * @return mixed */ - public function get($key, $default_val = null) + public function get(string $key, $default_val = null) { if (isset($this->attributes[$key])) { return $this->attributes[$key]; @@ -154,7 +154,7 @@ abstract class DataCollection implements IteratorAggregate, ArrayAccess, Countab * * @return DataCollection */ - public function set($key, $value) + public function set(string $key, $value): DataCollection { $this->attributes[$key] = $value; @@ -185,7 +185,7 @@ abstract class DataCollection implements IteratorAggregate, ArrayAccess, Countab * * @return void */ - public function remove($key) + public function remove(string $key) { unset($this->attributes[$key]); } @@ -212,7 +212,7 @@ abstract class DataCollection implements IteratorAggregate, ArrayAccess, Countab * * @return DataCollection */ - public function clear() + public function clear(): DataCollection { return $this->replace(); } @@ -224,7 +224,7 @@ abstract class DataCollection implements IteratorAggregate, ArrayAccess, Countab * * @return DataCollection */ - public function replace(array $attributes = array()) + public function replace(array $attributes = array()): DataCollection { $this->attributes = $attributes; @@ -236,7 +236,7 @@ abstract class DataCollection implements IteratorAggregate, ArrayAccess, Countab * * @return boolean */ - public function isEmpty() + public function isEmpty(): bool { return empty($this->attributes); } @@ -251,7 +251,6 @@ abstract class DataCollection implements IteratorAggregate, ArrayAccess, Countab * * @return mixed * @see get() - * */ public function __get($key) { @@ -269,7 +268,6 @@ abstract class DataCollection implements IteratorAggregate, ArrayAccess, Countab * * @return void * @see set() - * */ public function __set($key, $value) { @@ -286,7 +284,6 @@ abstract class DataCollection implements IteratorAggregate, ArrayAccess, Countab * * @return boolean * @see exists() - * */ public function __isset($key) { diff --git a/lib/SP/Core/Events/Event.php b/lib/SP/Core/Events/Event.php index b5f20610..010d8fe8 100644 --- a/lib/SP/Core/Events/Event.php +++ b/lib/SP/Core/Events/Event.php @@ -46,12 +46,11 @@ final class Event /** * Event constructor. * - * @param object $source - * @param EventMessage $eventMessage + * @param object $source + * @param EventMessage|null $eventMessage * - * @throws InvalidArgumentException */ - public function __construct($source, EventMessage $eventMessage = null) + public function __construct(object $source, EventMessage $eventMessage = null) { if (!is_object($source)) { throw new InvalidArgumentException(__u('An object is needed')); @@ -67,7 +66,7 @@ final class Event * @return mixed * @throws InvalidClassException */ - public function getSource($type = null) + public function getSource($type = null): object { if ($type !== null && ($source = get_class($this->source)) !== $type diff --git a/lib/SP/Core/Events/EventDispatcherBase.php b/lib/SP/Core/Events/EventDispatcherBase.php index c043fde8..6f341fcc 100644 --- a/lib/SP/Core/Events/EventDispatcherBase.php +++ b/lib/SP/Core/Events/EventDispatcherBase.php @@ -105,23 +105,23 @@ abstract class EventDispatcherBase implements EventDispatcherInterface /** * Notificar un evento * - * @param string $eventType + * @param string $eventName * @param Event $event */ - public function notifyEvent($eventType, Event $event) + public function notifyEvent(string $eventName, Event $event) { foreach ($this->observers as $observer) { if (method_exists($observer, 'getEventsString')) { $events = $observer->getEventsString(); if (!empty($events) - && ($events === '*' || preg_match('/' . $events . '/i', $eventType)) + && ($events === '*' || preg_match('/' . $events . '/i', $eventName)) ) { // FIXME: update receivers Event - $observer->updateEvent($eventType, $event); + $observer->updateEvent($eventName, $event); } } else { - $observer->updateEvent($eventType, $event); + $observer->updateEvent($eventName, $event); } } } diff --git a/lib/SP/Core/Events/EventDispatcherInterface.php b/lib/SP/Core/Events/EventDispatcherInterface.php index a3cf7cc7..d84fac33 100644 --- a/lib/SP/Core/Events/EventDispatcherInterface.php +++ b/lib/SP/Core/Events/EventDispatcherInterface.php @@ -36,8 +36,8 @@ interface EventDispatcherInterface extends SplSubject /** * Notificar a los observadores y establecer el estado * - * @param string $event Nombre del evento - * @param Event $object Objeto del evento + * @param string $eventName Nombre del evento + * @param Event $event Objeto del evento */ - public function notifyEvent($event, Event $object); + public function notifyEvent(string $eventName, Event $event); } \ No newline at end of file diff --git a/lib/SP/Core/Events/EventMessage.php b/lib/SP/Core/Events/EventMessage.php index 17b9df4f..cf11f116 100644 --- a/lib/SP/Core/Events/EventMessage.php +++ b/lib/SP/Core/Events/EventMessage.php @@ -79,13 +79,13 @@ final class EventMessage implements MessageInterface * Establece los detalles de la acción realizada * * @param $key string - * @param $value string + * @param $value string|null * * @return $this */ - public function addDetail($key, $value) + public function addDetail(string $key, ?string $value): EventMessage { - if ($value === '' || $key === '') { + if (empty($value) || empty($key)) { return $this; } @@ -103,7 +103,7 @@ final class EventMessage implements MessageInterface * * @return string */ - private function formatString($string) + private function formatString(string $string): string { return strip_tags($string); } @@ -115,7 +115,7 @@ final class EventMessage implements MessageInterface * * @return $this */ - public function addDescription($description = '') + public function addDescription($description = ''): EventMessage { $this->description[] = $this->formatString($description); @@ -131,7 +131,7 @@ final class EventMessage implements MessageInterface * * @return string */ - public function composeText($delimiter = PHP_EOL) + public function composeText(string $delimiter = PHP_EOL): string { if ($this->descriptionCounter === 0 && $this->detailsCounter === 0) { return ''; @@ -153,7 +153,7 @@ final class EventMessage implements MessageInterface * * @return string */ - public function getDescription(FormatterInterface $formatter, $translate = false) + public function getDescription(FormatterInterface $formatter, $translate = false): string { if ($this->descriptionCounter === 0) { return ''; @@ -170,7 +170,7 @@ final class EventMessage implements MessageInterface * * @return string */ - public function getDetails(FormatterInterface $formatter, bool $translate = false) + public function getDetails(FormatterInterface $formatter, bool $translate = false): string { if ($this->detailsCounter === 0) { return ''; @@ -192,9 +192,9 @@ final class EventMessage implements MessageInterface /** * Componer un mensaje en formato HTML * - * @return mixed + * @return string */ - public function composeHtml() + public function composeHtml(): string { $formatter = new HtmlFormatter(); @@ -209,7 +209,7 @@ final class EventMessage implements MessageInterface /** * @return int */ - public function getDescriptionCounter() + public function getDescriptionCounter(): int { return $this->descriptionCounter; } @@ -217,7 +217,7 @@ final class EventMessage implements MessageInterface /** * @return int */ - public function getDetailsCounter() + public function getDetailsCounter(): int { return $this->detailsCounter; } @@ -225,18 +225,18 @@ final class EventMessage implements MessageInterface /** * @return array */ - public function getExtra() + public function getExtra(): array { return $this->extra; } /** - * @param $type - * @param array $data + * @param string $type + * @param array $data * * @return EventMessage */ - public function setExtra($type, array $data) + public function setExtra(string $type, array $data): EventMessage { if (isset($this->extra[$type])) { $this->extra[$type] = array_merge($this->extra[$type], $data); @@ -255,7 +255,7 @@ final class EventMessage implements MessageInterface * * @return EventMessage */ - public function addExtra($type, $data) + public function addExtra(string $type, $data): EventMessage { if (isset($this->extra[$type]) && in_array($data, $this->extra[$type]) diff --git a/lib/SP/Core/Events/EventReceiver.php b/lib/SP/Core/Events/EventReceiver.php index e055d7e6..5f8c3c33 100644 --- a/lib/SP/Core/Events/EventReceiver.php +++ b/lib/SP/Core/Events/EventReceiver.php @@ -39,19 +39,19 @@ interface EventReceiver extends SplObserver * @param string $eventType Nombre del evento * @param Event $event Objeto del evento */ - public function updateEvent($eventType, Event $event); + public function updateEvent(string $eventType, Event $event); /** * Devuelve los eventos que implementa el observador * * @return array */ - public function getEvents(); + public function getEvents(): array; /** * Devuelve los eventos que implementa el observador en formato cadena * - * @return string + * @return string|null */ - public function getEventsString(); + public function getEventsString(): ?string; } \ No newline at end of file diff --git a/lib/SP/Core/Language.php b/lib/SP/Core/Language.php index 17ced1dc..5716e651 100644 --- a/lib/SP/Core/Language.php +++ b/lib/SP/Core/Language.php @@ -115,7 +115,7 @@ final class Language * * @return array */ - public static function getAvailableLanguages() + public static function getAvailableLanguages(): array { return self::$langs; } @@ -146,7 +146,7 @@ final class Language * * @return string */ - private function getUserLang() + private function getUserLang(): string { $userData = $this->context->getUserData(); @@ -157,7 +157,7 @@ final class Language * Establece el lenguaje de la aplicación. * Esta función establece el lenguaje según esté definido en la configuración o en el navegador. */ - private function getGlobalLang() + private function getGlobalLang(): string { return $this->configData->getSiteLang() ?: $this->getBrowserLang(); } @@ -167,7 +167,7 @@ final class Language * * @return string */ - private function getBrowserLang() + private function getBrowserLang(): string { $lang = $this->request->getHeader('Accept-Language'); @@ -179,7 +179,7 @@ final class Language * * @param string $lang El lenguaje a utilizar */ - public static function setLocales($lang) + public static function setLocales(string $lang) { $lang .= '.utf8'; @@ -233,7 +233,7 @@ final class Language * * @return bool */ - private function checkLangFile($lang) + private function checkLangFile(string $lang) { return file_exists(LOCALES_PATH . DIRECTORY_SEPARATOR . $lang); } diff --git a/lib/SP/Core/Messages/HtmlFormatter.php b/lib/SP/Core/Messages/HtmlFormatter.php index 016fdfb3..77a567d7 100644 --- a/lib/SP/Core/Messages/HtmlFormatter.php +++ b/lib/SP/Core/Messages/HtmlFormatter.php @@ -66,7 +66,7 @@ final class HtmlFormatter implements FormatterInterface * * @return string */ - private function buildLink(string $text) + private function buildLink(string $text): string { if (preg_match('#^https?://.*$#', $text, $matches)) { return sprintf('%s', $matches[0], Html::truncate($matches[0], 30)); diff --git a/lib/SP/Core/Messages/LogMessage.php b/lib/SP/Core/Messages/LogMessage.php index e8e82f44..83eebc24 100644 --- a/lib/SP/Core/Messages/LogMessage.php +++ b/lib/SP/Core/Messages/LogMessage.php @@ -56,7 +56,7 @@ final class LogMessage extends MessageBase * * @return $this */ - public function addDetails($key, $value) + public function addDetails(string $key, string $value) { if ($value === '' || $key === '') { return $this; @@ -75,7 +75,7 @@ final class LogMessage extends MessageBase * * @return string */ - private function formatString($string) + private function formatString(string $string): string { return strip_tags($string); } @@ -87,7 +87,7 @@ final class LogMessage extends MessageBase * * @return $this */ - public function addDescription($description = '') + public function addDescription(string $description = ''): LogMessage { $this->description[] = $this->formatString($description); @@ -112,7 +112,7 @@ final class LogMessage extends MessageBase * * @return string */ - public function composeText($delimiter = PHP_EOL) + public function composeText(string $delimiter = PHP_EOL): string { $formatter = new TextFormatter(); @@ -130,7 +130,7 @@ final class LogMessage extends MessageBase * * @return string */ - public function getAction($translate = false) + public function getAction(bool $translate = false): string { return $translate ? __($this->action) : $this->action; } @@ -142,7 +142,7 @@ final class LogMessage extends MessageBase * * @return $this */ - public function setAction($action) + public function setAction(string $action): LogMessage { $this->action = $this->formatString($action); @@ -186,9 +186,9 @@ final class LogMessage extends MessageBase /** * Componer un mensaje en formato HTML * - * @return mixed + * @return string */ - public function composeHtml() + public function composeHtml(): string { $formatter = new HtmlFormatter(); @@ -216,7 +216,7 @@ final class LogMessage extends MessageBase /** * Restablecer la variable de detalles */ - public function resetDetails() + public function resetDetails(): LogMessage { $this->details = []; $this->detailsCounter = 0; diff --git a/lib/SP/Core/Messages/MailMessage.php b/lib/SP/Core/Messages/MailMessage.php index ce66e3e9..2056ed95 100644 --- a/lib/SP/Core/Messages/MailMessage.php +++ b/lib/SP/Core/Messages/MailMessage.php @@ -44,7 +44,7 @@ final class MailMessage extends MessageBase implements MessageInterface * * @return string */ - public function composeHtml() + public function composeHtml(): string { $formatter = new HtmlFormatter(); @@ -75,7 +75,7 @@ final class MailMessage extends MessageBase implements MessageInterface * * @return string */ - public function composeText($delimiter = PHP_EOL) + public function composeText(string $delimiter = PHP_EOL): string { $formatter = new TextFormatter($delimiter); diff --git a/lib/SP/Core/Messages/MessageBase.php b/lib/SP/Core/Messages/MessageBase.php index faf1e058..d42f3894 100644 --- a/lib/SP/Core/Messages/MessageBase.php +++ b/lib/SP/Core/Messages/MessageBase.php @@ -97,7 +97,7 @@ abstract class MessageBase implements MessageInterface * * @return MessageBase */ - public function addDescription($description) + public function addDescription(string $description) { $this->description[] = $description; diff --git a/lib/SP/Core/Messages/MessageInterface.php b/lib/SP/Core/Messages/MessageInterface.php index 69101bc8..166fa073 100644 --- a/lib/SP/Core/Messages/MessageInterface.php +++ b/lib/SP/Core/Messages/MessageInterface.php @@ -38,12 +38,12 @@ interface MessageInterface * * @return string */ - public function composeText($delimiter = PHP_EOL); + public function composeText(string $delimiter = PHP_EOL): string; /** * Componer un mensaje en formato HTML * - * @return mixed + * @return string */ - public function composeHtml(); + public function composeHtml(): string; } \ No newline at end of file diff --git a/lib/SP/Core/Messages/NotificationMessage.php b/lib/SP/Core/Messages/NotificationMessage.php index a11d5469..46915d25 100644 --- a/lib/SP/Core/Messages/NotificationMessage.php +++ b/lib/SP/Core/Messages/NotificationMessage.php @@ -36,7 +36,7 @@ final class NotificationMessage extends MessageBase * * @return string */ - public function composeHtml() + public function composeHtml(): string { $formatter = new HtmlFormatter(); @@ -77,7 +77,7 @@ final class NotificationMessage extends MessageBase * * @return string */ - public function composeText($delimiter = PHP_EOL) + public function composeText(string $delimiter = PHP_EOL): string { $parts = []; diff --git a/lib/SP/Core/Messages/TaskMessage.php b/lib/SP/Core/Messages/TaskMessage.php index 94fdb47d..4964888f 100644 --- a/lib/SP/Core/Messages/TaskMessage.php +++ b/lib/SP/Core/Messages/TaskMessage.php @@ -64,7 +64,7 @@ final class TaskMessage implements MessageInterface, JsonSerializable * @param string $taskId * @param string $task */ - public function __construct($taskId, $task) + public function __construct(string $taskId, string $task) { $this->taskId = $taskId; $this->task = $task; @@ -83,7 +83,7 @@ final class TaskMessage implements MessageInterface, JsonSerializable * * @return TaskMessage */ - public function setTask($task) + public function setTask(string $task): TaskMessage { $this->task = $task; @@ -91,9 +91,9 @@ final class TaskMessage implements MessageInterface, JsonSerializable } /** - * @return string + * @return string|null */ - public function getMessage() + public function getMessage(): ?string { return $this->message; } @@ -103,7 +103,7 @@ final class TaskMessage implements MessageInterface, JsonSerializable * * @return TaskMessage */ - public function setMessage($message) + public function setMessage(string $message) { $this->message = $message; @@ -113,7 +113,7 @@ final class TaskMessage implements MessageInterface, JsonSerializable /** * @return int */ - public function getTime() + public function getTime(): int { return $this->time; } @@ -123,7 +123,7 @@ final class TaskMessage implements MessageInterface, JsonSerializable * * @return TaskMessage */ - public function setTime($time) + public function setTime(int $time): TaskMessage { $this->time = $time; @@ -133,7 +133,7 @@ final class TaskMessage implements MessageInterface, JsonSerializable /** * @return int */ - public function getProgress() + public function getProgress(): int { return $this->progress; } @@ -143,7 +143,7 @@ final class TaskMessage implements MessageInterface, JsonSerializable * * @return TaskMessage */ - public function setProgress($progress) + public function setProgress(int $progress): TaskMessage { $this->progress = $progress; @@ -153,7 +153,7 @@ final class TaskMessage implements MessageInterface, JsonSerializable /** * @return int */ - public function getEnd() + public function getEnd(): int { return $this->end; } @@ -163,7 +163,7 @@ final class TaskMessage implements MessageInterface, JsonSerializable * * @return TaskMessage */ - public function setEnd($end) + public function setEnd(int $end): TaskMessage { $this->end = $end; @@ -177,7 +177,7 @@ final class TaskMessage implements MessageInterface, JsonSerializable * * @return string */ - public function composeText($delimiter = ';') + public function composeText(string $delimiter = ';'): string { return implode($delimiter, [ 'taskId' => $this->taskId, @@ -192,18 +192,11 @@ final class TaskMessage implements MessageInterface, JsonSerializable /** * Componer un mensaje en formato HTML * - * @return mixed + * @return string */ - public function composeHtml() + public function composeHtml(): string { - return [ - 'taskId' => $this->taskId, - 'task' => $this->task, - 'message' => $this->message, - 'time' => $this->time, - 'progress' => $this->progress, - 'end' => $this->end - ]; + return $this->composeText(); } /** @@ -230,7 +223,7 @@ final class TaskMessage implements MessageInterface, JsonSerializable /** * @return string */ - public function getTaskId() + public function getTaskId(): string { return $this->taskId; } @@ -240,7 +233,7 @@ final class TaskMessage implements MessageInterface, JsonSerializable * * @return TaskMessage */ - public function setTaskId($taskId) + public function setTaskId(string $taskId) { $this->taskId = $taskId; diff --git a/lib/SP/Core/ModuleBase.php b/lib/SP/Core/ModuleBase.php index 0d29a0fc..313a049d 100644 --- a/lib/SP/Core/ModuleBase.php +++ b/lib/SP/Core/ModuleBase.php @@ -88,10 +88,8 @@ abstract class ModuleBase /** * @param string $controller - * - * @return mixed */ - abstract public function initialize($controller); + abstract public function initialize(string $controller); /** * Comprobar si el modo mantenimiento está activado @@ -101,7 +99,7 @@ abstract class ModuleBase * * @return bool */ - public function checkMaintenanceMode(ContextInterface $context) + public function checkMaintenanceMode(ContextInterface $context): bool { if ($this->configData->isMaintenance()) { Bootstrap::$LOCK = Util::getAppLock(); diff --git a/lib/SP/Core/PhpExtensionChecker.php b/lib/SP/Core/PhpExtensionChecker.php index 57761dd4..eb8d9edc 100644 --- a/lib/SP/Core/PhpExtensionChecker.php +++ b/lib/SP/Core/PhpExtensionChecker.php @@ -93,7 +93,7 @@ final class PhpExtensionChecker * @return bool * @throws CheckException */ - public function checkCurlAvailable($exception = false) + public function checkCurlAvailable(bool $exception = false): bool { return $this->checkIsAvailable('curl', $exception); } @@ -107,7 +107,7 @@ final class PhpExtensionChecker * @return bool * @throws CheckException */ - public function checkIsAvailable(string $extension, $exception = false) + public function checkIsAvailable(string $extension, bool $exception = false): bool { $result = in_array(strtolower($extension), $this->available); @@ -126,7 +126,7 @@ final class PhpExtensionChecker * @return bool * @throws CheckException */ - public function checkLdapAvailable($exception = false) + public function checkLdapAvailable(bool $exception = false): bool { return $this->checkIsAvailable('ldap', $exception); } @@ -139,7 +139,7 @@ final class PhpExtensionChecker * @return bool * @throws CheckException */ - public function checkSimpleXmlAvailable($exception = false) + public function checkSimpleXmlAvailable(bool $exception = false): bool { return $this->checkIsAvailable('simplexml', $exception); } @@ -152,7 +152,7 @@ final class PhpExtensionChecker * @return bool * @throws CheckException */ - public function checkXmlAvailable($exception = false) + public function checkXmlAvailable(bool $exception = false): bool { return $this->checkIsAvailable('xml', $exception); } @@ -165,7 +165,7 @@ final class PhpExtensionChecker * @return bool * @throws CheckException */ - public function checkPharAvailable($exception = false) + public function checkPharAvailable(bool $exception = false): bool { return $this->checkIsAvailable('phar', $exception); } @@ -178,7 +178,7 @@ final class PhpExtensionChecker * @return bool * @throws CheckException */ - public function checkJsonAvailable($exception = false) + public function checkJsonAvailable(bool $exception = false): bool { return $this->checkIsAvailable('json', $exception); } @@ -191,7 +191,7 @@ final class PhpExtensionChecker * @return bool * @throws CheckException */ - public function checkPdoAvailable($exception = false) + public function checkPdoAvailable(bool $exception = false): bool { return $this->checkIsAvailable('pdo', $exception); } @@ -204,7 +204,7 @@ final class PhpExtensionChecker * @return bool * @throws CheckException */ - public function checkGettextAvailable($exception = false) + public function checkGettextAvailable(bool $exception = false): bool { return $this->checkIsAvailable('gettext', $exception); } @@ -217,7 +217,7 @@ final class PhpExtensionChecker * @return bool * @throws CheckException */ - public function checkOpenSslAvailable($exception = false) + public function checkOpenSslAvailable(bool $exception = false): bool { return $this->checkIsAvailable('openssl', $exception); } @@ -230,7 +230,7 @@ final class PhpExtensionChecker * @return bool * @throws CheckException */ - public function checkGdAvailable($exception = false) + public function checkGdAvailable(bool $exception = false): bool { return $this->checkIsAvailable('gd', $exception); } @@ -243,7 +243,7 @@ final class PhpExtensionChecker * @return bool * @throws CheckException */ - public function checkMbstringAvailable($exception = false) + public function checkMbstringAvailable(bool $exception = false): bool { return $this->checkIsAvailable('mbstring', $exception); } @@ -269,7 +269,7 @@ final class PhpExtensionChecker * * @return array */ - public function getMissing() + public function getMissing(): array { return array_filter(self::EXTENSIONS, function ($k) { return !in_array($k, $this->available); diff --git a/lib/SP/Core/UI/Theme.php b/lib/SP/Core/UI/Theme.php index e5c7e553..db62e268 100644 --- a/lib/SP/Core/UI/Theme.php +++ b/lib/SP/Core/UI/Theme.php @@ -96,7 +96,12 @@ final class Theme implements ThemeInterface * @param ContextInterface $context * @param FileCacheInterface $fileCache */ - public function __construct($module, Config $config, ContextInterface $context, FileCacheInterface $fileCache) + public function __construct( + string $module, + Config $config, + ContextInterface $context, + FileCacheInterface $fileCache + ) { $this->configData = $config->getConfigData(); $this->context = $context; @@ -131,9 +136,9 @@ final class Theme implements ThemeInterface /** * Obtener el tema visual del usuario * - * @return string + * @return string|null */ - protected function getUserTheme() + protected function getUserTheme(): ?string { return $this->context->isLoggedIn() ? $this->context->getUserData()->getPreferences()->getTheme() : null; } @@ -141,7 +146,7 @@ final class Theme implements ThemeInterface /** * Devolver el tema visual de sysPass desde la configuración */ - protected function getGlobalTheme() + protected function getGlobalTheme(): string { return $this->configData->getSiteTheme(); } @@ -152,7 +157,7 @@ final class Theme implements ThemeInterface * @return ThemeIcons * @throws InvalidClassException */ - private function initIcons() + private function initIcons(): ThemeIcons { try { if ($this->context->getAppStatus() !== SessionContext::APP_STATUS_RELOADED @@ -200,7 +205,7 @@ final class Theme implements ThemeInterface * * @return array Con la información del tema */ - public function getThemesAvailable() + public function getThemesAvailable(): array { $themesAvailable = []; @@ -234,12 +239,16 @@ final class Theme implements ThemeInterface * 'css' => array * ) */ - public function getThemeInfo() + public function getThemeInfo(): array { $themeFile = $this->themePathFull . DIRECTORY_SEPARATOR . 'index.php'; if (file_exists($themeFile)) { - return include $themeFile; + $themeInfo = include $themeFile; + + if (is_array($themeInfo)) { + return $themeInfo; + } } return []; @@ -248,7 +257,7 @@ final class Theme implements ThemeInterface /** * @return string */ - public function getThemeUri() + public function getThemeUri(): string { return $this->themeUri; } @@ -256,7 +265,7 @@ final class Theme implements ThemeInterface /** * @return string */ - public function getThemePath() + public function getThemePath(): string { return $this->themePath; } @@ -264,7 +273,7 @@ final class Theme implements ThemeInterface /** * @return string */ - public function getThemeName() + public function getThemeName(): string { return $this->themeName; } @@ -272,7 +281,7 @@ final class Theme implements ThemeInterface /** * @return ThemeIcons */ - public function getIcons() + public function getIcons(): ThemeIcons { return clone $this->icons; } @@ -280,7 +289,7 @@ final class Theme implements ThemeInterface /** * @return string */ - public function getViewsPath() + public function getViewsPath(): string { return $this->viewsPath; } diff --git a/lib/SP/Core/UI/ThemeInterface.php b/lib/SP/Core/UI/ThemeInterface.php index 292d8294..cf356365 100644 --- a/lib/SP/Core/UI/ThemeInterface.php +++ b/lib/SP/Core/UI/ThemeInterface.php @@ -43,7 +43,7 @@ interface ThemeInterface * * @return array Con la información del tema */ - public function getThemesAvailable(); + public function getThemesAvailable(): array; /** * Obtener la información del tema desde el archivo de información @@ -56,30 +56,30 @@ interface ThemeInterface * 'css' => array * ) */ - public function getThemeInfo(); + public function getThemeInfo(): array; /** * @return string */ - public function getThemeUri(); + public function getThemeUri(): string; /** * @return string */ - public function getThemePath(); + public function getThemePath(): string; /** * @return string */ - public function getThemeName(); + public function getThemeName(): string; /** * @return ThemeIcons */ - public function getIcons(); + public function getIcons(): ThemeIcons; /** * @return string */ - public function getViewsPath(); + public function getViewsPath(): string; } \ No newline at end of file diff --git a/lib/SP/DataModel/ItemSearchData.php b/lib/SP/DataModel/ItemSearchData.php index 17dab20b..4c17203b 100644 --- a/lib/SP/DataModel/ItemSearchData.php +++ b/lib/SP/DataModel/ItemSearchData.php @@ -55,33 +55,37 @@ class ItemSearchData public $order = self::ORDER_ASC; /** - * @return string + * @return string|null */ - public function getSeachString() + public function getSeachString(): ?string { return $this->seachString; } /** - * @param string $seachString + * @param string|null $seachString */ - public function setSeachString($seachString) + public function setSeachString(?string $seachString) { - $this->seachString = Filter::safeSearchString($seachString); + if ($seachString) { + $this->seachString = Filter::safeSearchString($seachString); + } else { + $this->seachString = null; + } } /** * @return int */ - public function getLimitStart() + public function getLimitStart(): int { return $this->limitStart; } /** - * @param int $limitStart + * @param int|null $limitStart */ - public function setLimitStart($limitStart) + public function setLimitStart(?int $limitStart) { $this->limitStart = (int)$limitStart; } @@ -89,15 +93,15 @@ class ItemSearchData /** * @return int */ - public function getLimitCount() + public function getLimitCount(): int { return $this->limitCount; } /** - * @param int $limitCount + * @param int|null $limitCount */ - public function setLimitCount($limitCount) + public function setLimitCount(?int $limitCount) { $this->limitCount = (int)$limitCount; } @@ -105,15 +109,15 @@ class ItemSearchData /** * @return string */ - public function getOrder() + public function getOrder(): string { return $this->order; } /** - * @param string $order + * @param string|null $order */ - public function setOrder($order) + public function setOrder(?string $order) { $this->order = $order; } diff --git a/lib/SP/Html/Assets/FontIcon.php b/lib/SP/Html/Assets/FontIcon.php index 42e3a382..3efa048c 100644 --- a/lib/SP/Html/Assets/FontIcon.php +++ b/lib/SP/Html/Assets/FontIcon.php @@ -34,11 +34,11 @@ defined('APP_ROOT') || die(); final class FontIcon extends IconBase { /** - * @param string $icon - * @param string $class - * @param string $title + * @param string $icon + * @param string|null $class + * @param string|null $title */ - public function __construct($icon, $class = null, $title = null) + public function __construct(string $icon, ?string $class = null, ?string $title = null) { $this->setIcon($icon); $this->setClass($class); @@ -50,7 +50,7 @@ final class FontIcon extends IconBase * * @return string */ - public function getClassButton() + public function getClassButton(): string { return str_replace('-text--', '--', $this->getClass()); } diff --git a/lib/SP/Html/Assets/IconBase.php b/lib/SP/Html/Assets/IconBase.php index 65a236e5..75d95d46 100644 --- a/lib/SP/Html/Assets/IconBase.php +++ b/lib/SP/Html/Assets/IconBase.php @@ -56,17 +56,17 @@ abstract class IconBase implements IconInterface /** * @return string */ - public function getTitle() + public function getTitle(): string { return __($this->title); } /** - * @param $title + * @param string|null $title * * @return $this */ - public function setTitle($title) + public function setTitle(?string $title): IconBase { $this->title = $title; @@ -76,19 +76,21 @@ abstract class IconBase implements IconInterface /** * @return string */ - public function getClass() + public function getClass(): string { return implode(' ', $this->class); } /** - * @param $class + * @param string|null $class * * @return $this */ - public function setClass($class) + public function setClass(?string $class): IconBase { - $this->class[] = $class; + if ($class) { + $this->class[] = $class; + } return $this; } @@ -96,17 +98,17 @@ abstract class IconBase implements IconInterface /** * @return string */ - public function getIcon() + public function getIcon(): string { return $this->icon; } /** - * @param $icon + * @param string $icon * * @return $this */ - public function setIcon($icon) + public function setIcon(string $icon): IconBase { $this->icon = $icon; return $this; diff --git a/lib/SP/Html/Assets/IconInterface.php b/lib/SP/Html/Assets/IconInterface.php index 6212c100..a17203f9 100644 --- a/lib/SP/Html/Assets/IconInterface.php +++ b/lib/SP/Html/Assets/IconInterface.php @@ -36,30 +36,30 @@ interface IconInterface /** * @param $title */ - public function setTitle($title); + public function setTitle(string $title); /** * @return string */ - public function getTitle(); + public function getTitle(): string; /** - * @param $class + * @param string $class */ - public function setClass($class); + public function setClass(string $class); /** * @return string */ - public function getClass(); + public function getClass(): string; /** * @return string */ - public function getIcon(); + public function getIcon(): string; /** - * @param $icon + * @param string $icon */ - public function setIcon($icon); + public function setIcon(string $icon); } \ No newline at end of file diff --git a/lib/SP/Html/Assets/ImageIcon.php b/lib/SP/Html/Assets/ImageIcon.php index 1517cae9..1cda2d2f 100644 --- a/lib/SP/Html/Assets/ImageIcon.php +++ b/lib/SP/Html/Assets/ImageIcon.php @@ -35,10 +35,10 @@ final class ImageIcon extends IconBase { /** * @param string $icon - * @param string $class - * @param string $title + * @param null $class + * @param null $title */ - public function __construct($icon, $class = null, $title = null) + public function __construct(string $icon, $class = null, $title = null) { $this->setIcon($icon); $this->setClass($class); diff --git a/lib/SP/Html/DataGrid/Action/DataGridActionBase.php b/lib/SP/Html/DataGrid/Action/DataGridActionBase.php index 17816a3a..fc38d743 100644 --- a/lib/SP/Html/DataGrid/Action/DataGridActionBase.php +++ b/lib/SP/Html/DataGrid/Action/DataGridActionBase.php @@ -63,9 +63,9 @@ abstract class DataGridActionBase implements DataGridActionInterface /** * Action's title ID * - * @var int + * @var string */ - protected $id = 0; + protected $id = ''; /** * The JavaScript function to be triggered on OnClick event * @@ -146,9 +146,9 @@ abstract class DataGridActionBase implements DataGridActionInterface /** * Devolver el método reflexivo que determina si se muestra la acción * - * @return callable + * @return callable|null */ - public function getRuntimeFilter() + public function getRuntimeFilter(): ?callable { return $this->runtimeFilter; } @@ -162,7 +162,7 @@ abstract class DataGridActionBase implements DataGridActionInterface * @return $this * @throws RuntimeException */ - public function setRuntimeFilter($class, $method) + public function setRuntimeFilter(string $class, string $method): DataGridActionInterface { if (method_exists($class, $method)) { $this->runtimeFilter = function ($filter) use ($method) { @@ -177,9 +177,9 @@ abstract class DataGridActionBase implements DataGridActionInterface } /** - * @return string + * @return string|null */ - public function getName() + public function getName(): ?string { return $this->name; } @@ -189,7 +189,7 @@ abstract class DataGridActionBase implements DataGridActionInterface * * @return $this */ - public function setName($name) + public function setName(string $name): DataGridActionInterface { $this->name = $name; @@ -199,17 +199,17 @@ abstract class DataGridActionBase implements DataGridActionInterface /** * @return string */ - public function getId() + public function getId(): string { return $this->id; } /** - * @param int $id + * @param string $id * * @return $this */ - public function setId($id) + public function setId(string $id): DataGridActionBase { $this->id = $id; @@ -217,9 +217,9 @@ abstract class DataGridActionBase implements DataGridActionInterface } /** - * @return string + * @return string|null */ - public function getTitle() + public function getTitle(): ?string { return $this->title; } @@ -229,7 +229,7 @@ abstract class DataGridActionBase implements DataGridActionInterface * * @return $this */ - public function setTitle($title) + public function setTitle(string $title): DataGridActionBase { $this->title = $title; @@ -241,7 +241,7 @@ abstract class DataGridActionBase implements DataGridActionInterface * * @return $this */ - public function setOnClickFunction($function) + public function setOnClickFunction(string $function): DataGridActionBase { $this->onClickFunction = $function; @@ -253,7 +253,7 @@ abstract class DataGridActionBase implements DataGridActionInterface * * @return $this */ - public function setOnClickArgs($args) + public function setOnClickArgs(string $args): DataGridActionBase { if ($this->onClickArgs === null) { $this->onClickArgs = []; @@ -267,7 +267,7 @@ abstract class DataGridActionBase implements DataGridActionInterface /** * @return string */ - public function getOnClick() + public function getOnClick(): ?string { if ($this->onClickArgs !== null) { @@ -283,9 +283,9 @@ abstract class DataGridActionBase implements DataGridActionInterface } /** - * @return IconInterface + * @return IconInterface|null */ - public function getIcon() + public function getIcon(): ?IconInterface { return $this->icon; } @@ -295,7 +295,7 @@ abstract class DataGridActionBase implements DataGridActionInterface * * @return $this */ - public function setIcon($icon) + public function setIcon(IconInterface $icon): DataGridActionBase { $this->icon = $icon; @@ -307,7 +307,7 @@ abstract class DataGridActionBase implements DataGridActionInterface * * @return $this */ - public function setSkip($skip) + public function setSkip(bool $skip): DataGridActionBase { $this->isSkip = $skip; @@ -315,17 +315,17 @@ abstract class DataGridActionBase implements DataGridActionInterface } /** - * @return bool + * @return bool|null */ - public function isSkip() + public function isSkip(): ?bool { return $this->isSkip; } /** - * @return bool + * @return bool|null */ - public function isHelper() + public function isHelper(): ?bool { return $this->isHelper; } @@ -335,7 +335,7 @@ abstract class DataGridActionBase implements DataGridActionInterface * * @return $this */ - public function setIsHelper($helper) + public function setIsHelper(bool $helper): DataGridActionBase { $this->isHelper = $helper; @@ -343,9 +343,9 @@ abstract class DataGridActionBase implements DataGridActionInterface } /** - * @return array + * @return array|null */ - public function getFilterRowSource() + public function getFilterRowSource(): ?array { return $this->filterRowSource; } @@ -358,7 +358,7 @@ abstract class DataGridActionBase implements DataGridActionInterface * * @return $this */ - public function setFilterRowSource($rowSource, $value = 1) + public function setFilterRowSource(string $rowSource, $value = 1): DataGridActionBase { if ($this->filterRowSource === null) { $this->filterRowSource = []; @@ -372,7 +372,7 @@ abstract class DataGridActionBase implements DataGridActionInterface /** * @return int El tipo de acción */ - public function getType() + public function getType(): ?int { return $this->type; } @@ -382,7 +382,7 @@ abstract class DataGridActionBase implements DataGridActionInterface * * @return $this */ - public function setType($type) + public function setType(int $type): DataGridActionBase { $this->type = $type; @@ -392,7 +392,7 @@ abstract class DataGridActionBase implements DataGridActionInterface /** * @return array */ - public function getData() + public function getData(): array { return (array)$this->data; } @@ -402,7 +402,7 @@ abstract class DataGridActionBase implements DataGridActionInterface * * @return $this */ - public function setData(array $data) + public function setData(array $data): DataGridActionInterface { $this->data = $data; @@ -417,7 +417,7 @@ abstract class DataGridActionBase implements DataGridActionInterface * * @return $this */ - public function addData($name, $data) + public function addData(string $name, $data): DataGridActionBase { if ($this->data === null) { $this->data = []; @@ -431,7 +431,7 @@ abstract class DataGridActionBase implements DataGridActionInterface /** * @return array */ - public function getAttributes() + public function getAttributes(): array { return (array)$this->attributes; } @@ -443,7 +443,7 @@ abstract class DataGridActionBase implements DataGridActionInterface * * @return $this */ - public function setAttributes(array $attributes) + public function setAttributes(array $attributes): DataGridActionInterface { $this->attributes = $attributes; @@ -458,7 +458,7 @@ abstract class DataGridActionBase implements DataGridActionInterface * * @return $this */ - public function addAttribute($name, $value) + public function addAttribute(string $name, $value): DataGridActionBase { if ($this->attributes === null) { $this->attributes = []; @@ -472,9 +472,9 @@ abstract class DataGridActionBase implements DataGridActionInterface /** * Returns classes as a string * - * @return string + * @return string|null */ - public function getClassesAsString() + public function getClassesAsString(): ?string { if ($this->classes === null) { return ''; @@ -488,7 +488,7 @@ abstract class DataGridActionBase implements DataGridActionInterface * * @return array */ - public function getClasses() + public function getClasses(): array { return (array)$this->classes; } @@ -510,7 +510,7 @@ abstract class DataGridActionBase implements DataGridActionInterface * * @return $this */ - public function addClass($value) + public function addClass($value): DataGridActionInterface { if ($this->classes === null) { $this->classes = []; @@ -536,7 +536,7 @@ abstract class DataGridActionBase implements DataGridActionInterface * * @return DataGridActionBase */ - public function setIsSelection(bool $isSelection) + public function setIsSelection(bool $isSelection): DataGridActionBase { $this->isSelection = $isSelection; @@ -544,9 +544,9 @@ abstract class DataGridActionBase implements DataGridActionInterface } /** - * @return callable + * @return callable|null */ - public function getRuntimeData() + public function getRuntimeData(): ?callable { return $this->runtimeData; } @@ -558,7 +558,7 @@ abstract class DataGridActionBase implements DataGridActionInterface * * @return $this */ - public function setRuntimeData(callable $function) + public function setRuntimeData(callable $function): DataGridActionBase { $this->runtimeData = $function; diff --git a/lib/SP/Html/DataGrid/Action/DataGridActionInterface.php b/lib/SP/Html/DataGrid/Action/DataGridActionInterface.php index 2cc8b93a..4c54db8c 100644 --- a/lib/SP/Html/DataGrid/Action/DataGridActionInterface.php +++ b/lib/SP/Html/DataGrid/Action/DataGridActionInterface.php @@ -38,103 +38,103 @@ interface DataGridActionInterface /** * @param $name string */ - public function setName($name); + public function setName(string $name); + + /** + * @return string|null + */ + public function getName(): ?string; + + /** + * @param string $id + */ + public function setId(string $id); /** * @return string */ - public function getName(); - - /** - * @param int $id - */ - public function setId($id); - - /** - * @return string - */ - public function getId(); + public function getId(): string; /** * @param $title string */ - public function setTitle($title); + public function setTitle(string $title); /** - * @return string + * @return string|null */ - public function getTitle(); + public function getTitle(): ?string; /** * @param $function string */ - public function setOnClickFunction($function); + public function setOnClickFunction(string $function); /** * @param $args string */ - public function setOnClickArgs($args); + public function setOnClickArgs(string $args); /** - * @return string + * @return string|null */ - public function getOnClick(); + public function getOnClick(): ?string; /** * @param $icon IconInterface */ - public function setIcon($icon); + public function setIcon(IconInterface $icon); /** - * @return IconInterface + * @return IconInterface|null */ - public function getIcon(); + public function getIcon(): ?IconInterface; /** * @param $skip bool */ - public function setSkip($skip); + public function setSkip(bool $skip); /** - * @return bool + * @return bool|null */ - public function isSkip(); + public function isSkip(): ?bool; /** * @param bool $helper */ - public function setIsHelper($helper); + public function setIsHelper(bool $helper); /** - * @return bool + * @return bool|null */ - public function isHelper(); + public function isHelper(): ?bool; /** * @param string $rowSource * @param mixed $value Valor a filtrar */ - public function setFilterRowSource($rowSource, $value = 1); + public function setFilterRowSource(string $rowSource, $value = 1); /** - * @return array + * @return array|null */ - public function getFilterRowSource(); + public function getFilterRowSource(): ?array; /** * @param int $type El tipo de acción definido en DataGridActionType */ - public function setType($type); + public function setType(int $type); /** - * @return int El tipo de acción + * @return int|null El tipo de acción */ - public function getType(); + public function getType(): ?int; /** * @return array */ - public function getData(); + public function getData(): array; /** * Establecer atributos de datos @@ -143,7 +143,7 @@ interface DataGridActionInterface * * @return $this */ - public function setData(array $data); + public function setData(array $data): DataGridActionInterface; /** * Añadir nuevo atributo de datos @@ -151,12 +151,12 @@ interface DataGridActionInterface * @param string $name El nombe del atributo * @param mixed $data Los datos del atributo */ - public function addData($name, $data); + public function addData(string $name, $data); /** * @return array */ - public function getAttributes(); + public function getAttributes(): array; /** * Establecer atributos @@ -165,7 +165,7 @@ interface DataGridActionInterface * * @return $this */ - public function setAttributes(array $attributes); + public function setAttributes(array $attributes): DataGridActionInterface; /** * Añadir nuevo atributo @@ -173,14 +173,14 @@ interface DataGridActionInterface * @param string $name El nombe del atributo * @param mixed $value */ - public function addAttribute($name, $value); + public function addAttribute(string $name, $value); /** * Devolver el método reflexivo que determina si se muestra la acción * - * @return callable + * @return callable|null */ - public function getRuntimeFilter(); + public function getRuntimeFilter(): ?callable; /** * Establecer el método reflexivo que determina si se muestra la acción @@ -190,21 +190,21 @@ interface DataGridActionInterface * * @return $this */ - public function setRuntimeFilter($class, $method); + public function setRuntimeFilter(string $class, string $method): DataGridActionInterface; /** * Returns classes as a string * - * @return string + * @return string|null */ - public function getClassesAsString(); + public function getClassesAsString(): ?string; /** * Returns classes * * @return array */ - public function getClasses(); + public function getClasses(): array; /** * Set classes @@ -220,19 +220,19 @@ interface DataGridActionInterface * * @return $this */ - public function addClass($value); + public function addClass($value): DataGridActionInterface; /** * Returns if the action is used for selecting multiple items * - * @return bool + * @return bool|null */ public function isSelection(): bool; /** * Returns the runtime function to pass in the row dato to the action * - * @return callable + * @return callable|null */ - public function getRuntimeData(); + public function getRuntimeData(): ?callable; } \ No newline at end of file diff --git a/lib/SP/Html/DataGrid/Action/DataGridActionSearch.php b/lib/SP/Html/DataGrid/Action/DataGridActionSearch.php index f37ae8a5..a5b4b50e 100644 --- a/lib/SP/Html/DataGrid/Action/DataGridActionSearch.php +++ b/lib/SP/Html/DataGrid/Action/DataGridActionSearch.php @@ -60,7 +60,7 @@ final class DataGridActionSearch extends DataGridActionBase /** * @return string */ - public function getOnSubmit() + public function getOnSubmit(): string { $args = []; @@ -74,7 +74,7 @@ final class DataGridActionSearch extends DataGridActionBase /** * @param string $onSubmitFunction */ - public function setOnSubmitFunction($onSubmitFunction) + public function setOnSubmitFunction(string $onSubmitFunction) { $this->onSubmitFunction = $onSubmitFunction; } @@ -82,7 +82,7 @@ final class DataGridActionSearch extends DataGridActionBase /** * @param array $args */ - public function setOnSubmitArgs($args) + public function setOnSubmitArgs(array $args) { $this->onSubmitArgs[] = $args; } diff --git a/lib/SP/Html/DataGrid/DataGrid.php b/lib/SP/Html/DataGrid/DataGrid.php index a71fa618..fa14cc19 100644 --- a/lib/SP/Html/DataGrid/DataGrid.php +++ b/lib/SP/Html/DataGrid/DataGrid.php @@ -43,7 +43,7 @@ final class DataGrid extends DataGridBase /** * @return string */ - public function getTitle() + public function getTitle(): string { return $this->title; } @@ -53,7 +53,7 @@ final class DataGrid extends DataGridBase * * @return DataGrid */ - public function setTitle($title) + public function setTitle(string $title): DataGrid { $this->title = $title; diff --git a/lib/SP/Html/DataGrid/DataGridBase.php b/lib/SP/Html/DataGrid/DataGridBase.php index 7b0aaa88..1766c167 100644 --- a/lib/SP/Html/DataGrid/DataGridBase.php +++ b/lib/SP/Html/DataGrid/DataGridBase.php @@ -167,7 +167,7 @@ abstract class DataGridBase implements DataGridInterface /** * @return string */ - public function getId() + public function getId(): string { return $this->id; } @@ -177,7 +177,7 @@ abstract class DataGridBase implements DataGridInterface * * @return $this */ - public function setId($id) + public function setId(string $id): DataGridBase { $this->id = $id; @@ -187,7 +187,7 @@ abstract class DataGridBase implements DataGridInterface /** * @return DataGridHeader|DataGridHeaderSort|DataGridHeaderInterface */ - public function getHeader() + public function getHeader(): DataGridHeaderInterface { return $this->header; } @@ -197,7 +197,7 @@ abstract class DataGridBase implements DataGridInterface * * @return $this */ - public function setHeader(DataGridHeaderInterface $header) + public function setHeader(DataGridHeaderInterface $header): DataGridBase { $this->header = $header; @@ -217,7 +217,7 @@ abstract class DataGridBase implements DataGridInterface * * @return $this */ - public function setData(DataGridDataInterface $data) + public function setData(DataGridDataInterface $data): DataGridBase { $this->data = $data; @@ -230,7 +230,7 @@ abstract class DataGridBase implements DataGridInterface * * @return $this */ - public function addDataAction(DataGridActionInterface $action, $isMenu = false) + public function addDataAction(DataGridActionInterface $action, $isMenu = false): DataGridInterface { if ($isMenu === false) { $this->actions[] = $action; @@ -252,7 +252,7 @@ abstract class DataGridBase implements DataGridInterface /** * @return DataGridActionInterface[] */ - public function getDataActions() + public function getDataActions(): array { return $this->actions; } @@ -260,7 +260,7 @@ abstract class DataGridBase implements DataGridInterface /** * @return $this */ - public function getGrid() + public function getGrid(): DataGridInterface { return $this; } @@ -269,14 +269,13 @@ abstract class DataGridBase implements DataGridInterface * Establecer la plantilla utilizada para la cabecera * * @param string $template El nombre de la plantilla a utilizar - * @param string $base Directorio base para la plantilla * * @return $this */ - public function setDataHeaderTemplate($template, $base = null) + public function setDataHeaderTemplate(string $template): DataGridBase { try { - $this->headerTemplate = $this->checkTemplate($template, $base); + $this->headerTemplate = $this->checkTemplate($template); } catch (FileNotFoundException $e) { processException($e); } @@ -287,13 +286,13 @@ abstract class DataGridBase implements DataGridInterface /** * Comprobar si existe una plantilla y devolver la ruta completa * - * @param $template - * @param null $base + * @param string $template + * @param string|null $base * * @return string * @throws FileNotFoundException */ - protected function checkTemplate($template, $base = null) + protected function checkTemplate(string $template, ?string $base = null): string { $template = null === $base ? $template . '.inc' : $base . DIRECTORY_SEPARATOR . $template . '.inc'; $file = $this->theme->getViewsPath() . DIRECTORY_SEPARATOR . $template; @@ -310,7 +309,7 @@ abstract class DataGridBase implements DataGridInterface * * @return string */ - public function getDataHeaderTemplate() + public function getDataHeaderTemplate(): string { return $this->headerTemplate; } @@ -322,7 +321,7 @@ abstract class DataGridBase implements DataGridInterface * * @return $this */ - public function setDataActionsTemplate($template) + public function setDataActionsTemplate(string $template): DataGridBase { try { $this->actionsTemplate = $this->checkTemplate($template); @@ -336,9 +335,9 @@ abstract class DataGridBase implements DataGridInterface /** * Devolver la plantilla utilizada para las acciones * - * @return string + * @return string|null */ - public function getDataActionsTemplate() + public function getDataActionsTemplate(): ?string { return $this->actionsTemplate; } @@ -346,12 +345,12 @@ abstract class DataGridBase implements DataGridInterface /** * Establecer la plantilla utilizada para el paginador * - * @param string $template El nombre de la plantilla a utilizar - * @param string $base Directorio base para la plantilla + * @param string $template El nombre de la plantilla a utilizar + * @param string|null $base * * @return $this */ - public function setDataPagerTemplate($template, $base = null) + public function setDataPagerTemplate(string $template, ?string $base = null): DataGridBase { try { $this->pagerTemplate = $this->checkTemplate($template, $base); @@ -365,20 +364,20 @@ abstract class DataGridBase implements DataGridInterface /** * Devolver la plantilla utilizada para el paginador * - * @return string + * @return string|null */ - public function getDataPagerTemplate() + public function getDataPagerTemplate(): ?string { return $this->pagerTemplate; } /** - * @param string $template El nombre de la plantilla a utilizar - * @param string $base Directorio base para la plantilla + * @param string $template El nombre de la plantilla a utilizar + * @param string|null $base * * @return mixed */ - public function setDataRowTemplate($template, $base = null) + public function setDataRowTemplate(string $template, ?string $base = null) { try { $this->rowsTemplate = $this->checkTemplate($template, $base); @@ -390,9 +389,9 @@ abstract class DataGridBase implements DataGridInterface } /** - * @return string + * @return string|null */ - public function getDataRowTemplate() + public function getDataRowTemplate(): ?string { return $this->rowsTemplate; } @@ -400,9 +399,9 @@ abstract class DataGridBase implements DataGridInterface /** * Devolver el paginador * - * @return DataGridPagerInterface + * @return DataGridPagerInterface|null */ - public function getPager() + public function getPager(): ?DataGridPagerInterface { return $this->pager; } @@ -414,7 +413,7 @@ abstract class DataGridBase implements DataGridInterface * * @return $this */ - public function setPager(DataGridPagerInterface $pager) + public function setPager(DataGridPagerInterface $pager): DataGridBase { $this->pager = $pager; @@ -424,7 +423,7 @@ abstract class DataGridBase implements DataGridInterface /** * Actualizar los datos del paginador */ - public function updatePager() + public function updatePager(): DataGridInterface { if ($this->pager instanceof DataGridPagerInterface) { $this->pager->setTotalRows($this->data->getDataCount()); @@ -436,17 +435,17 @@ abstract class DataGridBase implements DataGridInterface /** * @return int */ - public function getTime() + public function getTime(): int { return abs($this->time); } /** - * @param int $time + * @param int|float $time * * @return $this */ - public function setTime($time) + public function setTime($time): DataGridInterface { $this->time = $time; @@ -458,7 +457,7 @@ abstract class DataGridBase implements DataGridInterface * * @return DataGridActionInterface[] */ - public function getDataActionsMenu() + public function getDataActionsMenu(): array { return $this->actionsMenu; } @@ -470,7 +469,7 @@ abstract class DataGridBase implements DataGridInterface * * @return DataGridActionInterface[] */ - public function getDataActionsFiltered($filter) + public function getDataActionsFiltered($filter): array { $actions = []; @@ -490,7 +489,7 @@ abstract class DataGridBase implements DataGridInterface * * @return DataGridActionInterface[] */ - public function getDataActionsMenuFiltered($filter) + public function getDataActionsMenuFiltered($filter): array { $actions = []; @@ -504,9 +503,9 @@ abstract class DataGridBase implements DataGridInterface } /** - * @return string + * @return string|null */ - public function getDataTableTemplate() + public function getDataTableTemplate(): ?string { return $this->tableTemplate; } @@ -531,7 +530,7 @@ abstract class DataGridBase implements DataGridInterface /** * @return int */ - public function getDataActionsMenuCount() + public function getDataActionsMenuCount(): int { return $this->actionsMenuCount; } @@ -539,7 +538,7 @@ abstract class DataGridBase implements DataGridInterface /** * @return int */ - public function getDataActionsCount() + public function getDataActionsCount(): int { return $this->actionsCount; } diff --git a/lib/SP/Html/DataGrid/DataGridDataBase.php b/lib/SP/Html/DataGrid/DataGridDataBase.php index b1078598..ffda1125 100644 --- a/lib/SP/Html/DataGrid/DataGridDataBase.php +++ b/lib/SP/Html/DataGrid/DataGridDataBase.php @@ -68,31 +68,36 @@ abstract class DataGridDataBase implements DataGridDataInterface /** * @return array */ - public function getDataRowSourcesWithIcon() + public function getDataRowSourcesWithIcon(): array { return $this->sourcesWithIcon; } /** - * @param string $source - * @param bool $isMethod - * @param callable $filter - * @param bool $truncate + * @param string $source + * @param bool $isMethod + * @param callable|null $filter + * @param bool $truncate */ - public function addDataRowSource($source, $isMethod = false, callable $filter = null, $truncate = true) + public function addDataRowSource( + string $source, + ?bool $isMethod = false, + ?callable $filter = null, + ?bool $truncate = true + ) { $this->sources[] = [ 'name' => $source, - 'isMethod' => $isMethod, + 'isMethod' => (bool)$isMethod, 'filter' => $filter, - 'truncate' => $truncate + 'truncate' => (bool)$truncate ]; } /** * @param $id string */ - public function setDataRowSourceId($id) + public function setDataRowSourceId(string $id) { $this->sourceId = $id; } @@ -100,7 +105,7 @@ abstract class DataGridDataBase implements DataGridDataInterface /** * @return array */ - public function getDataRowSources() + public function getDataRowSources(): array { return $this->sources; } @@ -108,7 +113,7 @@ abstract class DataGridDataBase implements DataGridDataInterface /** * @return string */ - public function getDataRowSourceId() + public function getDataRowSourceId(): string { return $this->sourceId; } @@ -116,7 +121,7 @@ abstract class DataGridDataBase implements DataGridDataInterface /** * @return array */ - public function getData() + public function getData(): array { return $this->data; } @@ -135,7 +140,11 @@ abstract class DataGridDataBase implements DataGridDataInterface * @param IconInterface $icon * @param mixed $value Valor para mostrar el icono */ - public function addDataRowSourceWithIcon($source, IconInterface $icon, $value = 1) + public function addDataRowSourceWithIcon( + string $source, + IconInterface $icon, + int $value = 1 + ) { $this->sourcesWithIcon[] = [ 'field' => $source, @@ -149,7 +158,7 @@ abstract class DataGridDataBase implements DataGridDataInterface * * @return int */ - public function getDataCount() + public function getDataCount(): int { return $this->dataCount; } diff --git a/lib/SP/Html/DataGrid/DataGridDataInterface.php b/lib/SP/Html/DataGrid/DataGridDataInterface.php index befba98e..d6431d52 100644 --- a/lib/SP/Html/DataGrid/DataGridDataInterface.php +++ b/lib/SP/Html/DataGrid/DataGridDataInterface.php @@ -44,28 +44,33 @@ interface DataGridDataInterface * @param callable|null $filter * @param bool $truncate */ - public function addDataRowSource($source, $isMethod = false, callable $filter = null, $truncate = true); + public function addDataRowSource( + string $source, + bool $isMethod = false, + callable $filter = null, + bool $truncate = true + ); /** * Devolver los orígenes de datos de la consulta * * @return array */ - public function getDataRowSources(); + public function getDataRowSources(): array; /** * Establecer el origen de datos utilizado como Id de los elementos * * @param $id string */ - public function setDataRowSourceId($id); + public function setDataRowSourceId(string $id); /** * Devolver el origen de datos utilizado como Id de los elementos * * @return string */ - public function getDataRowSourceId(); + public function getDataRowSourceId(): string; /** * Establecer los datos de la consulta @@ -79,7 +84,7 @@ interface DataGridDataInterface * * @return array */ - public function getData(); + public function getData(): array; /** * Establecer los orígenes de datos que se muestran con iconos @@ -88,19 +93,23 @@ interface DataGridDataInterface * @param $icon IconInterface * @param mixed $value Valor para mostrar el icono */ - public function addDataRowSourceWithIcon($source, IconInterface $icon, $value = 1); + public function addDataRowSourceWithIcon( + string $source, + IconInterface $icon, + int $value = 1 + ); /** * Devolver los orígenes de datos que se muestran con iconos * * @return array */ - public function getDataRowSourcesWithIcon(); + public function getDataRowSourcesWithIcon(): array; /** * Devolver el número de elementos obtenidos * * @return int */ - public function getDataCount(); + public function getDataCount(): int; } \ No newline at end of file diff --git a/lib/SP/Html/DataGrid/DataGridInterface.php b/lib/SP/Html/DataGrid/DataGridInterface.php index 18d7b5a2..0e4faa11 100644 --- a/lib/SP/Html/DataGrid/DataGridInterface.php +++ b/lib/SP/Html/DataGrid/DataGridInterface.php @@ -41,12 +41,12 @@ interface DataGridInterface /** * @param $id string */ - public function setId($id); + public function setId(string $id); /** * @return string */ - public function getId(); + public function getId(): string; /** * @param DataGridHeaderInterface $header @@ -56,7 +56,7 @@ interface DataGridInterface /** * @return DataGridHeaderInterface */ - public function getHeader(); + public function getHeader(): DataGridHeaderInterface; /** * @param DataGridDataInterface $data @@ -74,12 +74,12 @@ interface DataGridInterface * * @return $this */ - public function addDataAction(DataGridActionInterface $action, $isMenu = false); + public function addDataAction(DataGridActionInterface $action, $isMenu = false): DataGridInterface; /** - * @return DataGridActionInterface + * @return DataGridActionInterface[] */ - public function getDataActions(); + public function getDataActions(): array; /** * @return mixed @@ -96,9 +96,9 @@ interface DataGridInterface /** * Devolver el paginador * - * @return DataGridPagerInterface + * @return DataGridPagerInterface|null */ - public function getPager(); + public function getPager(): ?DataGridPagerInterface; /** * @param ActionsInterface $action @@ -110,63 +110,63 @@ interface DataGridInterface * * @param string $template El nombre de la plantilla a utilizar */ - public function setDataHeaderTemplate($template); + public function setDataHeaderTemplate(string $template); /** * Devolver la plantilla utilizada para la cabecera * * @return string */ - public function getDataHeaderTemplate(); + public function getDataHeaderTemplate(): string; /** * Establecer la plantilla utilizada para las acciones * * @param string $template El nombre de la plantilla a utilizar */ - public function setDataActionsTemplate($template); + public function setDataActionsTemplate(string $template); /** * Devolver la plantilla utilizada para las acciones * - * @return string + * @return string|null */ - public function getDataActionsTemplate(); + public function getDataActionsTemplate(): ?string; /** * Establecer la plantilla utilizada para el paginador * * @param string $template El nombre de la plantilla a utilizar */ - public function setDataPagerTemplate($template); + public function setDataPagerTemplate(string $template); /** * Devolver la plantilla utilizada para el paginador * - * @return string + * @return string|null */ - public function getDataPagerTemplate(); + public function getDataPagerTemplate(): ?string; /** * Establcer la plantilla utilizada para los datos de la consulta * * @param string $template El nombre de la plantilla a utilizar */ - public function setDataRowTemplate($template); + public function setDataRowTemplate(string $template); /** * Devolver la plantilla utilizada para los datos de la consulta * - * @return string + * @return string|null */ - public function getDataRowTemplate(); + public function getDataRowTemplate(): ?string; /** * Devuelve el tiempo total de carga del DataGrid * * @return int */ - public function getTime(); + public function getTime(): int; /** * Establece el tiempo total de carga del DataGrid @@ -180,7 +180,7 @@ interface DataGridInterface * * @return DataGridActionInterface[] */ - public function getDataActionsMenu(); + public function getDataActionsMenu(): array; /** * Devolver las acciones filtradas @@ -189,7 +189,7 @@ interface DataGridInterface * * @return DataGridActionInterface[] */ - public function getDataActionsFiltered($filter); + public function getDataActionsFiltered($filter): array; /** * Devolver las acciones de menu filtradas @@ -198,12 +198,12 @@ interface DataGridInterface * * @return DataGridActionInterface[] */ - public function getDataActionsMenuFiltered($filter); + public function getDataActionsMenuFiltered($filter): array; /** * Actualizar los datos del paginador * * @return static */ - public function updatePager(); + public function updatePager(): DataGridInterface; } \ No newline at end of file diff --git a/lib/SP/Html/DataGrid/DataGridSort.php b/lib/SP/Html/DataGrid/DataGridSort.php index dd7272f7..89265d68 100644 --- a/lib/SP/Html/DataGrid/DataGridSort.php +++ b/lib/SP/Html/DataGrid/DataGridSort.php @@ -50,7 +50,7 @@ final class DataGridSort implements DataGridSortInterface /** * @var array */ - private $class = array(); + private $class = []; /** * @var IconInterface */ @@ -63,7 +63,7 @@ final class DataGridSort implements DataGridSortInterface /** * @return int */ - public function getSortKey() + public function getSortKey(): int { return $this->sortKey; } @@ -73,7 +73,7 @@ final class DataGridSort implements DataGridSortInterface * * @return $this */ - public function setSortKey($key) + public function setSortKey(int $key) { $this->sortKey = $key; @@ -83,7 +83,7 @@ final class DataGridSort implements DataGridSortInterface /** * @return string */ - public function getTitle() + public function getTitle(): string { return $this->title; } @@ -93,7 +93,7 @@ final class DataGridSort implements DataGridSortInterface * * @return $this */ - public function setTitle($title) + public function setTitle(string $title): DataGridSort { $this->title = $title; @@ -103,7 +103,7 @@ final class DataGridSort implements DataGridSortInterface /** * @return string */ - public function getName() + public function getName(): string { return $this->name; } @@ -113,7 +113,7 @@ final class DataGridSort implements DataGridSortInterface * * @return $this */ - public function setName($name) + public function setName(string $name): DataGridSort { $this->name = $name; @@ -123,7 +123,7 @@ final class DataGridSort implements DataGridSortInterface /** * @return string */ - public function getClass() + public function getClass(): string { return implode(' ', $this->class); } @@ -133,7 +133,7 @@ final class DataGridSort implements DataGridSortInterface * * @return $this */ - public function setClass($class) + public function setClass(string $class): DataGridSort { $this->class[] = $class; @@ -143,7 +143,7 @@ final class DataGridSort implements DataGridSortInterface /** * @return IconInterface */ - public function getIconUp() + public function getIconUp(): ?IconInterface { return $this->iconUp; } @@ -153,7 +153,7 @@ final class DataGridSort implements DataGridSortInterface * * @return $this */ - public function setIconUp(IconInterface $icon) + public function setIconUp(IconInterface $icon): DataGridSort { $this->iconUp = $icon; @@ -163,7 +163,7 @@ final class DataGridSort implements DataGridSortInterface /** * @return IconInterface */ - public function getIconDown() + public function getIconDown(): ?IconInterface { return $this->iconDown; } @@ -173,7 +173,7 @@ final class DataGridSort implements DataGridSortInterface * * @return $this */ - public function setIconDown(IconInterface $icon) + public function setIconDown(IconInterface $icon): DataGridSort { $this->iconDown = $icon; diff --git a/lib/SP/Html/DataGrid/DataGridSortInterface.php b/lib/SP/Html/DataGrid/DataGridSortInterface.php index 11af1bc3..7fcad9f0 100644 --- a/lib/SP/Html/DataGrid/DataGridSortInterface.php +++ b/lib/SP/Html/DataGrid/DataGridSortInterface.php @@ -39,47 +39,47 @@ interface DataGridSortInterface /** * @return int */ - public function getSortKey(); + public function getSortKey(): int; /** * @param $key int */ - public function setSortKey($key); + public function setSortKey(int $key); /** * @return string */ - public function getTitle(); + public function getTitle(): string; /** * @param $title string */ - public function setTitle($title); + public function setTitle(string $title); /** * @return string */ - public function getName(); + public function getName(): string; /** * @param $name string */ - public function setName($name); + public function setName(string $name); /** * @return string */ - public function getClass(); + public function getClass(): string; /** * @param $class string */ - public function setClass($class); + public function setClass(string $class); /** - * @return IconInterface + * @return IconInterface|null */ - public function getIconUp(); + public function getIconUp(): ?IconInterface; /** * @param IconInterface $icon @@ -87,9 +87,9 @@ interface DataGridSortInterface public function setIconUp(IconInterface $icon); /** - * @return IconInterface + * @return IconInterface|null */ - public function getIconDown(); + public function getIconDown(): ?IconInterface; /** * @param IconInterface $icon diff --git a/lib/SP/Html/DataGrid/DataGridTab.php b/lib/SP/Html/DataGrid/DataGridTab.php index 62f9ea08..62cedb37 100644 --- a/lib/SP/Html/DataGrid/DataGridTab.php +++ b/lib/SP/Html/DataGrid/DataGridTab.php @@ -43,7 +43,7 @@ final class DataGridTab extends DataGridBase /** * @return string */ - public function getTitle() + public function getTitle(): string { return $this->title; } @@ -53,7 +53,7 @@ final class DataGridTab extends DataGridBase * * @return DataGridTab */ - public function setTitle($title) + public function setTitle(string $title): DataGridTab { $this->title = $title; diff --git a/lib/SP/Html/DataGrid/Layout/DataGridHeaderBase.php b/lib/SP/Html/DataGrid/Layout/DataGridHeaderBase.php index 3ff0eb34..83f1ecdd 100644 --- a/lib/SP/Html/DataGrid/Layout/DataGridHeaderBase.php +++ b/lib/SP/Html/DataGrid/Layout/DataGridHeaderBase.php @@ -49,7 +49,7 @@ abstract class DataGridHeaderBase implements DataGridHeaderInterface /** * @param $header string */ - public function addHeader($header) + public function addHeader(string $header) { $this->headers[] = $header; @@ -68,7 +68,7 @@ abstract class DataGridHeaderBase implements DataGridHeaderInterface /** * @return array */ - public function getHeaders() + public function getHeaders(): array { return $this->headers; } diff --git a/lib/SP/Html/DataGrid/Layout/DataGridHeaderInterface.php b/lib/SP/Html/DataGrid/Layout/DataGridHeaderInterface.php index ffe24a6f..5e4957c1 100644 --- a/lib/SP/Html/DataGrid/Layout/DataGridHeaderInterface.php +++ b/lib/SP/Html/DataGrid/Layout/DataGridHeaderInterface.php @@ -36,10 +36,10 @@ interface DataGridHeaderInterface /** * @param $header string */ - public function addHeader($header); + public function addHeader(string $header); /** * @return array */ - public function getHeaders(); + public function getHeaders(): array; } \ No newline at end of file diff --git a/lib/SP/Html/DataGrid/Layout/DataGridHeaderSort.php b/lib/SP/Html/DataGrid/Layout/DataGridHeaderSort.php index 6cac5320..b59e93aa 100644 --- a/lib/SP/Html/DataGrid/Layout/DataGridHeaderSort.php +++ b/lib/SP/Html/DataGrid/Layout/DataGridHeaderSort.php @@ -50,7 +50,7 @@ final class DataGridHeaderSort extends DataGridHeaderBase /** * @return DataGridSortInterface[] */ - public function getSortFields() + public function getSortFields(): array { return $this->sortFields; } @@ -58,15 +58,15 @@ final class DataGridHeaderSort extends DataGridHeaderBase /** * @return DataGridActionInterface[] */ - public function getActions() + public function getActions(): array { return $this->actions; } /** - * @param DataGridActionInterface[] $action + * @param DataGridActionInterface $action */ - public function addAction($action) + public function addAction(DataGridActionInterface $action) { if (null === $this->actions) { $this->actions = new SplObjectStorage(); @@ -80,7 +80,7 @@ final class DataGridHeaderSort extends DataGridHeaderBase * * @return $this */ - public function addSortField($field) + public function addSortField(DataGridSortInterface $field): DataGridHeaderSort { if (null === $this->sortFields) { $this->sortFields = new SplObjectStorage(); diff --git a/lib/SP/Html/Html.php b/lib/SP/Html/Html.php index d1bed6ab..6ea3ba2e 100644 --- a/lib/SP/Html/Html.php +++ b/lib/SP/Html/Html.php @@ -34,7 +34,7 @@ final class Html /** * Limpia los datos recibidos de un formulario. * - * @param string $data con los datos a limpiar + * @param mixed $data con los datos a limpiar * * @return false|string con los datos limpiados */ @@ -102,7 +102,11 @@ final class Html * * @link http://www.pjgalbraith.com/truncating-text-html-with-php/ */ - public static function truncate($text, $limit, $ellipsis = '...') + public static function truncate( + string $text, + int $limit, + string $ellipsis = '...' + ): string { if (mb_strlen($text) > $limit) { return trim(mb_substr($text, 0, $limit)) . $ellipsis; @@ -137,7 +141,7 @@ final class Html * * @return string */ - public static function strongText($text) + public static function strongText(string $text): string { return '' . $text . ''; } @@ -145,14 +149,19 @@ final class Html /** * Devolver un link HTML. * - * @param string $text con la cadena de texto - * @param string $link con el destino del enlace - * @param string $title con el título del enlace - * @param string $attribs con atributos del enlace + * @param string $text con la cadena de texto + * @param string|null $link con el destino del enlace + * @param string|null $title con el título del enlace + * @param string $attribs con atributos del enlace * * @return string */ - public static function anchorText($text, $link = null, $title = null, $attribs = '') + public static function anchorText( + string $text, + ?string $link = null, + ?string $title = null, + string $attribs = '' + ): string { $alink = $link !== null ? $link : $text; $atitle = $title !== null ? $title : $text; diff --git a/lib/SP/Html/Minify.php b/lib/SP/Html/Minify.php index 2aabf0a9..4e0b0a44 100644 --- a/lib/SP/Html/Minify.php +++ b/lib/SP/Html/Minify.php @@ -84,7 +84,7 @@ final class Minify * * @return $this */ - public function setBase($path, $checkPath = false) + public function setBase(string $path, $checkPath = false): Minify { $this->base = $checkPath === true ? Request::getSecureAppPath($path) : $path; @@ -176,7 +176,7 @@ final class Minify * * @return string Con el hash */ - private function getEtag() + private function getEtag(): string { $md5Sum = ''; @@ -194,7 +194,7 @@ final class Minify * * @return string */ - private function jsCompress($buffer) + private function jsCompress(string $buffer): string { $regexReplace = [ '#/\*[^*]*\*+([^/][^*]*\*+)*/#', @@ -208,12 +208,12 @@ final class Minify } /** - * @param $files - * @param bool $minify + * @param string $files + * @param bool $minify * * @return Minify */ - public function addFilesFromString($files, $minify = true) + public function addFilesFromString(string $files, bool $minify = true): Minify { if (strrpos($files, ',')) { $files = explode(',', $files); @@ -231,13 +231,17 @@ final class Minify /** * Añadir un archivo * - * @param string $file - * @param bool $minify Si es necesario reducir - * @param string $base + * @param string $file + * @param bool $minify Si es necesario reducir + * @param string|null $base * * @return $this */ - public function addFile($file, $minify = true, $base = null) + public function addFile( + string $file, + bool $minify = true, + ?string $base = null + ): Minify { if ($base === null) { $base = $this->base; @@ -268,7 +272,7 @@ final class Minify * * @return bool */ - private function needsMinify($file) + private function needsMinify(string $file): bool { return !preg_match('/\.min|pack\.css|js/', $file); } @@ -279,7 +283,7 @@ final class Minify * * @return Minify */ - public function addFiles(array $files, $minify = true) + public function addFiles(array $files, bool $minify = true): Minify { foreach ($files as $filename) { $this->processFile($filename, $minify); @@ -289,10 +293,10 @@ final class Minify } /** - * @param $file - * @param bool $minify + * @param string $file + * @param bool $minify */ - protected function processFile($file, $minify = true) + protected function processFile(string $file, bool $minify = true) { $filePath = $this->base . DIRECTORY_SEPARATOR . $file; @@ -312,11 +316,11 @@ final class Minify /** * Añadir un recurso desde URL * - * @param $url + * @param string $url * * @return $this */ - public function addUrl($url) + public function addUrl(string $url): Minify { $this->files[] = array( 'type' => 'url', @@ -336,7 +340,7 @@ final class Minify * * @return $this */ - public function setType($type) + public function setType(int $type): Minify { $this->type = (int)$type; diff --git a/lib/SP/Http/Address.php b/lib/SP/Http/Address.php index 0c06c767..852046dd 100644 --- a/lib/SP/Http/Address.php +++ b/lib/SP/Http/Address.php @@ -60,7 +60,7 @@ final class Address * @return string * @throws InvalidArgumentException */ - public static function fromBinary(string $address) + public static function fromBinary(string $address): string { $stringAddress = @inet_ntop($address); @@ -81,7 +81,7 @@ final class Address * @return array * @throws InvalidArgumentException */ - public static function parse4(string $address) + public static function parse4(string $address): array { if (preg_match(self::PATTERN_IP_ADDRESS, $address, $matches)) { return $matches; @@ -118,9 +118,9 @@ final class Address * * @param int $bits * - * @return int + * @return string */ - public static function cidrToDec(int $bits) + public static function cidrToDec(int $bits): string { return long2ip(-1 << (32 - $bits)); } diff --git a/lib/SP/Http/Client.php b/lib/SP/Http/Client.php index 8eefd52b..c170b5e0 100644 --- a/lib/SP/Http/Client.php +++ b/lib/SP/Http/Client.php @@ -38,7 +38,7 @@ final class Client * * @return array */ - public static function getOptions(ConfigData $configData) + public static function getOptions(ConfigData $configData): array { $options = [ 'timeout' => 10, diff --git a/lib/SP/Http/Json.php b/lib/SP/Http/Json.php index a7e95aec..9f3e6d9b 100644 --- a/lib/SP/Http/Json.php +++ b/lib/SP/Http/Json.php @@ -24,6 +24,8 @@ namespace SP\Http; +use DI\DependencyException; +use DI\NotFoundException; use Klein\Klein; use Klein\Response; use SP\Bootstrap; @@ -62,15 +64,17 @@ final class Json * * @return Json */ - public static function factory(Response $response) + public static function factory(Response $response): Json { return new self($response); } /** * @return Json + * @throws DependencyException + * @throws NotFoundException */ - public static function fromDic() + public static function fromDic(): Json { return new self(Bootstrap::getContainer()->get(Klein::class)->response()); } @@ -80,9 +84,9 @@ final class Json * * @param $data mixed * - * @return mixed + * @return string */ - public static function safeJson(&$data) + public static function safeJson(&$data): string { if (is_array($data) || is_object($data)) { array_walk_recursive($data, @@ -130,7 +134,7 @@ final class Json * * @return bool */ - public function returnRawJson(string $data) + public function returnRawJson(string $data): bool { return $this->response ->header('Content-type', 'application/json; charset=utf-8') @@ -146,7 +150,7 @@ final class Json * * @return bool */ - public function returnJson(JsonResponse $jsonResponse) + public function returnJson(JsonResponse $jsonResponse): bool { $this->response->header('Content-type', 'application/json; charset=utf-8'); @@ -171,7 +175,7 @@ final class Json * @return string La cadena en formato JSON * @throws SPException */ - public static function getJson($data, $flags = 0) + public static function getJson($data, int $flags = 0): string { $json = json_encode($data, JSON_PARTIAL_OUTPUT_ON_ERROR | $flags); diff --git a/lib/SP/Http/JsonResponse.php b/lib/SP/Http/JsonResponse.php index 4457b78f..d2d4eee9 100644 --- a/lib/SP/Http/JsonResponse.php +++ b/lib/SP/Http/JsonResponse.php @@ -74,9 +74,9 @@ final class JsonResponse implements JsonSerializable /** * JsonResponse constructor. * - * @param string $description + * @param string|null $description */ - public function __construct(string $description = null) + public function __construct(?string $description = null) { $this->description = $description; } @@ -84,7 +84,7 @@ final class JsonResponse implements JsonSerializable /** * @return int */ - public function getStatus() + public function getStatus(): int { return $this->status; } @@ -94,7 +94,7 @@ final class JsonResponse implements JsonSerializable * * @return JsonResponse */ - public function setStatus($status) + public function setStatus(int $status): JsonResponse { $this->status = (int)$status; @@ -104,7 +104,7 @@ final class JsonResponse implements JsonSerializable /** * @return string */ - public function getDescription() + public function getDescription(): ?string { return $this->description; } @@ -114,7 +114,7 @@ final class JsonResponse implements JsonSerializable * * @return JsonResponse */ - public function setDescription($description) + public function setDescription(string $description): JsonResponse { $this->description = __($description); @@ -124,7 +124,7 @@ final class JsonResponse implements JsonSerializable /** * @return string */ - public function getAction() + public function getAction(): string { return $this->action; } @@ -134,7 +134,7 @@ final class JsonResponse implements JsonSerializable * * @return JsonResponse */ - public function setAction($action) + public function setAction(string $action): JsonResponse { $this->action = $action; @@ -144,7 +144,7 @@ final class JsonResponse implements JsonSerializable /** * @return array */ - public function getData() + public function getData(): array { return $this->data; } @@ -154,7 +154,7 @@ final class JsonResponse implements JsonSerializable * * @return JsonResponse */ - public function setData($data) + public function setData($data): JsonResponse { $this->data = $data; @@ -164,7 +164,7 @@ final class JsonResponse implements JsonSerializable /** * @return array */ - public function getMessages() + public function getMessages(): array { return $this->messages; } @@ -174,7 +174,7 @@ final class JsonResponse implements JsonSerializable * * @return JsonResponse */ - public function setMessages(array $messages) + public function setMessages(array $messages): JsonResponse { $this->messages = array_map('__', $messages); @@ -184,7 +184,7 @@ final class JsonResponse implements JsonSerializable /** * @return string */ - public function getContainer() + public function getContainer(): string { return $this->container; } @@ -194,7 +194,7 @@ final class JsonResponse implements JsonSerializable * * @return JsonResponse */ - public function setContainer($container) + public function setContainer(string $container): JsonResponse { $this->container = $container; @@ -204,7 +204,7 @@ final class JsonResponse implements JsonSerializable /** * @return string */ - public function getCsrf() + public function getCsrf(): string { return $this->csrf; } @@ -214,7 +214,7 @@ final class JsonResponse implements JsonSerializable * * @return JsonResponse */ - public function setCsrf($csrf) + public function setCsrf(string $csrf): JsonResponse { $this->csrf = $csrf; @@ -222,22 +222,22 @@ final class JsonResponse implements JsonSerializable } /** - * @param $message + * @param string $message * * @return JsonResponse */ - public function addMessage($message) + public function addMessage(string $message): JsonResponse { $this->messages[] = __($message); return $this; } /** - * @param $param + * @param mixed $param * * @return $this */ - public function addParam($param) + public function addParam($param): JsonResponse { if (is_numeric($param)) { $param = (int)$param; @@ -266,7 +266,7 @@ final class JsonResponse implements JsonSerializable * * @return array */ - public function getJsonArray() + public function getJsonArray(): array { $out = []; @@ -282,7 +282,7 @@ final class JsonResponse implements JsonSerializable * * @return JsonResponse */ - public function clear() + public function clear(): JsonResponse { $this->status = 0; $this->action = ''; diff --git a/lib/SP/Http/Message.php b/lib/SP/Http/Message.php index 927df150..94f40394 100644 --- a/lib/SP/Http/Message.php +++ b/lib/SP/Http/Message.php @@ -51,7 +51,7 @@ final class Message /** * @return int */ - public function getType() + public function getType(): int { return $this->type; } @@ -59,15 +59,15 @@ final class Message /** * @param int $type */ - public function setType($type) + public function setType(int $type) { $this->type = $type; } /** - * @return string + * @return string|null */ - public function getDescription() + public function getDescription(): ?string { return $this->description; } @@ -75,15 +75,15 @@ final class Message /** * @param string $description */ - public function setDescription($description) + public function setDescription(string $description) { $this->description = $description; } /** - * @return string + * @return string|null */ - public function getHint() + public function getHint(): ?string { return $this->hint; } @@ -91,7 +91,7 @@ final class Message /** * @param string $hint */ - public function setHint($hint) + public function setHint(string $hint) { $this->hint = $hint; } diff --git a/lib/SP/Http/Request.php b/lib/SP/Http/Request.php index 3a034001..4ae82d4d 100644 --- a/lib/SP/Http/Request.php +++ b/lib/SP/Http/Request.php @@ -82,7 +82,7 @@ final class Request /** * @return DataCollection */ - private function getParamsByMethod() + private function getParamsByMethod(): DataCollection { if ($this->request->method('GET')) { $this->method = 'GET'; @@ -105,12 +105,12 @@ final class Request /** * Devuelve un nombre de archivo seguro * - * @param string $file - * @param string $base + * @param string $file + * @param string|null $base * * @return string */ - public static function getSecureAppFile(string $file, string $base = null) + public static function getSecureAppFile(string $file, ?string $base = null): string { return basename(self::getSecureAppPath($file, $base)); } @@ -118,12 +118,12 @@ final class Request /** * Devolver una ruta segura para * - * @param string $path - * @param string $base + * @param string $path + * @param string|null $base * * @return string */ - public static function getSecureAppPath(string $path, string $base = null) + public static function getSecureAppPath(string $path, ?string $base = null): string { if ($base === null) { $base = APP_ROOT; @@ -165,7 +165,7 @@ final class Request /** * @return string[]|null */ - public function getForwardedFor() + public function getForwardedFor(): ?array { // eg: Forwarded: by=; for=; host=; proto= $forwarded = $this->headers->get('HTTP_FORWARDED'); @@ -201,7 +201,7 @@ final class Request * * @return bool */ - public function checkReload() + public function checkReload(): bool { return $this->headers->get('Cache-Control') === 'max-age=0'; } @@ -212,7 +212,7 @@ final class Request * * @return string|null */ - public function analyzeEmail(string $param, string $default = null) + public function analyzeEmail(string $param, ?string $default = null): ?string { if (!$this->params->exists($param)) { return $default; @@ -228,7 +228,7 @@ final class Request * * @return string */ - public function analyzeEncrypted(string $param) + public function analyzeEncrypted(string $param): string { $encryptedData = $this->analyzeString($param); @@ -257,12 +257,12 @@ final class Request } /** - * @param $param - * @param $default + * @param string $param + * @param string|null $default * * @return string|null */ - public function analyzeString(string $param, string $default = null) + public function analyzeString(string $param, ?string $default = null): ?string { if (!$this->params->exists($param)) { return $default; @@ -272,12 +272,12 @@ final class Request } /** - * @param $param - * @param $default + * @param string $param + * @param string|null $default * * @return string|null */ - public function analyzeUnsafeString(string $param, string $default = null) + public function analyzeUnsafeString(string $param, ?string $default = null): ?string { if (!$this->params->exists($param)) { return $default; @@ -317,7 +317,7 @@ final class Request * * @return bool */ - public function isJson() + public function isJson(): bool { return strpos($this->headers->get('Accept'), 'application/json') !== false; } @@ -327,7 +327,7 @@ final class Request * * @return bool */ - public function isAjax() + public function isAjax(): bool { return $this->headers->get('X-Requested-With') === 'XMLHttpRequest' || $this->analyzeInt('isAjax', 0) === 1; @@ -339,7 +339,7 @@ final class Request * * @return int */ - public function analyzeInt(string $param, int $default = null): ?int + public function analyzeInt(string $param, ?int $default = null): ?int { if (!$this->params->exists($param)) { return $default; @@ -353,7 +353,7 @@ final class Request * * @return array|null */ - public function getFile(string $file) + public function getFile(string $file): ?array { return $this->request->files()->get($file); } @@ -364,7 +364,7 @@ final class Request * * @return bool */ - public function analyzeBool(string $param, bool $default = null): bool + public function analyzeBool(string $param, ?bool $default = null): bool { if (!$this->params->exists($param)) { return (bool)$default; @@ -374,12 +374,12 @@ final class Request } /** - * @param string $key - * @param string $param Checks the signature only for the given param + * @param string $key + * @param string|null $param Checks the signature only for the given param * * @throws SPException */ - public function verifySignature(string $key, string $param = null) + public function verifySignature(string $key, ?string $param = null) { $result = false; $hash = $this->params->get('h'); @@ -445,7 +445,7 @@ final class Request * @see https://tools.ietf.org/html/rfc7239#section-7.5 * @return array|null */ - public function getForwardedData() + public function getForwardedData(): ?array { $forwarded = $this->getHeader('HTTP_FORWARDED'); @@ -484,7 +484,7 @@ final class Request * * @return array|null */ - public function getXForwardedData() + public function getXForwardedData(): ?array { $forwardedHost = $this->getHeader('HTTP_X_FORWARDED_HOST'); $forwardedProto = $this->getHeader('HTTP_X_FORWARDED_PROTO'); diff --git a/lib/SP/Http/Uri.php b/lib/SP/Http/Uri.php index d9606ffb..896d4680 100644 --- a/lib/SP/Http/Uri.php +++ b/lib/SP/Http/Uri.php @@ -53,12 +53,12 @@ final class Uri } /** - * @param $key - * @param $value + * @param string $key + * @param string $value * * @return string */ - private static function mapParts($key, $value) + private static function mapParts(string $key, string $value): string { if (strpos($key, '_') === 0) { $key = substr($key, 1); @@ -69,11 +69,11 @@ final class Uri /** * @param string $param Param's name. If an '_' is set at the beginning, it will be a protected param - * @param string $value + * @param string|int $value * * @return Uri */ - public function addParam(string $param, $value) + public function addParam(string $param, $value): Uri { $this->params[$param] = (string)$value; @@ -105,7 +105,7 @@ final class Uri * * Only clears unprotected params (without '_' at the beginning of the param's name) */ - public function resetParams() + public function resetParams(): Uri { $this->params = array_filter($this->params, function ($key) { return strpos($key, '_') === 0; diff --git a/lib/SP/Http/XMLRPCResponseParse.php b/lib/SP/Http/XMLRPCResponseParse.php index eebc5d0c..eb0adeff 100644 --- a/lib/SP/Http/XMLRPCResponseParse.php +++ b/lib/SP/Http/XMLRPCResponseParse.php @@ -58,7 +58,7 @@ abstract class XMLRPCResponseParse * * @throws InvalidArgumentException */ - public function __construct($xml) + public function __construct(string $xml) { try { $this->xml = $xml; @@ -81,7 +81,7 @@ abstract class XMLRPCResponseParse * * @return array */ - public function getError() + public function getError(): array { return $this->parseNodes($this->root->getElementsByTagName('fault')); } @@ -94,7 +94,7 @@ abstract class XMLRPCResponseParse * * @return array */ - private function parseNodes(DOMNodeList $nodes) + private function parseNodes(DOMNodeList $nodes): array { if ($nodes->length > 0) { foreach ($nodes as $node) { @@ -129,7 +129,7 @@ abstract class XMLRPCResponseParse * * @return array */ - private function parseStruct(DOMElement $xmlStruct) + private function parseStruct(DOMElement $xmlStruct): array { $dataStruct = []; $nStruct = 0; @@ -185,7 +185,7 @@ abstract class XMLRPCResponseParse * * @return array */ - private function parseArray(DOMElement $xmlArray) + private function parseArray(DOMElement $xmlArray): array { $arrayData = []; @@ -214,7 +214,7 @@ abstract class XMLRPCResponseParse * * @return array */ - private function parseValues(DOMElement $xmlValues) + private function parseValues(DOMElement $xmlValues): array { $valuesData = []; @@ -240,7 +240,7 @@ abstract class XMLRPCResponseParse * * @return array */ - private function parseFault(DOMElement $xmlFault) + private function parseFault(DOMElement $xmlFault): array { $faultData = []; @@ -263,7 +263,7 @@ abstract class XMLRPCResponseParse /** * Obtener los datos de la respuesta */ - public function parseParams() + public function parseParams(): array { $this->parseNodes($this->root->getElementsByTagName('params')); @@ -275,7 +275,7 @@ abstract class XMLRPCResponseParse * * @return string */ - public function getXml() + public function getXml(): string { return $this->xml; } diff --git a/lib/SP/Mvc/Controller/ControllerTrait.php b/lib/SP/Mvc/Controller/ControllerTrait.php index 3e52b327..6e80e6b6 100644 --- a/lib/SP/Mvc/Controller/ControllerTrait.php +++ b/lib/SP/Mvc/Controller/ControllerTrait.php @@ -25,6 +25,8 @@ namespace SP\Mvc\Controller; use Closure; +use DI\DependencyException; +use DI\NotFoundException; use SP\Bootstrap; use SP\Config\ConfigData; use SP\Core\Exceptions\SPException; @@ -46,7 +48,7 @@ trait ControllerTrait /** * @return string */ - protected function getControllerName() + protected function getControllerName(): string { $class = static::class; @@ -59,6 +61,9 @@ trait ControllerTrait * @param Request $request * @param ConfigData $configData * @param Closure $onRedirect + * + * @throws DependencyException + * @throws NotFoundException */ protected function sessionLogout(Request $request, ConfigData $configData, Closure $onRedirect) { @@ -111,7 +116,7 @@ trait ControllerTrait * @throws SPException * @deprecated */ - protected function checkSecurityToken($previousToken, Request $request) + protected function checkSecurityToken(string $previousToken, Request $request) { if ($request->analyzeString('h') !== null && $request->analyzeString('from') === null diff --git a/lib/SP/Mvc/Controller/ItemTrait.php b/lib/SP/Mvc/Controller/ItemTrait.php index 5c43cb9a..ae77b464 100644 --- a/lib/SP/Mvc/Controller/ItemTrait.php +++ b/lib/SP/Mvc/Controller/ItemTrait.php @@ -25,6 +25,8 @@ namespace SP\Mvc\Controller; use Defuse\Crypto\Exception\CryptoException; +use DI\DependencyException; +use DI\NotFoundException; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use SP\Bootstrap; @@ -56,10 +58,12 @@ trait ItemTrait * @return array * @throws ConstraintException * @throws QueryException - * @throws ServiceException * @throws SPException + * @throws ServiceException + * @throws DependencyException + * @throws NotFoundException */ - protected function getCustomFieldsForItem($moduleId, $itemId) + protected function getCustomFieldsForItem(int $moduleId, $itemId): array { $customFieldService = Bootstrap::getContainer()->get(CustomFieldService::class); $customFields = []; @@ -105,13 +109,15 @@ trait ItemTrait * @param int|int[] $itemId * @param Request $request * - * @throws SPException * @throws ConstraintException - * @throws QueryException + * @throws DependencyException * @throws NoSuchItemException + * @throws NotFoundException + * @throws QueryException + * @throws SPException * @throws ServiceException */ - protected function addCustomFieldsForItem($moduleId, $itemId, Request $request) + protected function addCustomFieldsForItem(int $moduleId, $itemId, Request $request) { $customFields = $request->analyzeArray('customfield', function ($values) { return array_map(function ($value) { @@ -148,7 +154,7 @@ trait ItemTrait * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ - protected function deleteCustomFieldsForItem($moduleId, $itemId) + protected function deleteCustomFieldsForItem(int $moduleId, $itemId) { $customFieldService = Bootstrap::getContainer()->get(CustomFieldService::class); @@ -166,11 +172,13 @@ trait ItemTrait * @param int|int[] $itemId * @param Request $request * - * @throws SPException * @throws ConstraintException + * @throws DependencyException + * @throws NotFoundException * @throws QueryException + * @throws SPException */ - protected function updateCustomFieldsForItem($moduleId, $itemId, Request $request) + protected function updateCustomFieldsForItem(int $moduleId, $itemId, Request $request) { $customFields = $request->analyzeArray('customfield', function ($values) { return array_map(function ($value) { @@ -207,7 +215,7 @@ trait ItemTrait * * @return ItemSearchData */ - protected function getSearchData($limitCount, Request $request) + protected function getSearchData($limitCount, Request $request): ItemSearchData { $itemSearchData = new ItemSearchData(); $itemSearchData->setSeachString($request->analyzeString('search')); diff --git a/lib/SP/Mvc/Controller/Validators/PasswordValidator.php b/lib/SP/Mvc/Controller/Validators/PasswordValidator.php index 2b07f6ab..2a40b63d 100644 --- a/lib/SP/Mvc/Controller/Validators/PasswordValidator.php +++ b/lib/SP/Mvc/Controller/Validators/PasswordValidator.php @@ -54,7 +54,7 @@ final class PasswordValidator implements ValidatorInterface * * @return PasswordValidator */ - public static function factory(Password $password) + public static function factory(Password $password): PasswordValidator { return new self($password); } diff --git a/lib/SP/Mvc/Controller/Validators/Validator.php b/lib/SP/Mvc/Controller/Validators/Validator.php index b2df5a60..6162ee0e 100644 --- a/lib/SP/Mvc/Controller/Validators/Validator.php +++ b/lib/SP/Mvc/Controller/Validators/Validator.php @@ -36,7 +36,7 @@ final class Validator * * @return bool */ - public static function hasLetters(string $string) + public static function hasLetters(string $string): bool { return preg_match('#[a-z]+#i', $string) === 1; } @@ -46,7 +46,7 @@ final class Validator * * @return bool */ - public static function hasNumbers(string $string) + public static function hasNumbers(string $string): bool { return preg_match('#[\d]+#', $string) === 1; } @@ -56,7 +56,7 @@ final class Validator * * @return bool */ - public static function hasUpper(string $string) + public static function hasUpper(string $string): bool { return preg_match('#[A-Z]+#', $string) === 1; } @@ -66,7 +66,7 @@ final class Validator * * @return bool */ - public static function hasLower(string $string) + public static function hasLower(string $string): bool { return preg_match('#[a-z]+#', $string) === 1; } @@ -76,7 +76,7 @@ final class Validator * * @return bool */ - public static function hasSymbols(string $string) + public static function hasSymbols(string $string): bool { return preg_match('#[$-/:-?{-~!"^_`\[\]]+#', $string) === 1; } @@ -87,7 +87,7 @@ final class Validator * * @return bool */ - public static function matchRegex(string $string, string $regex) + public static function matchRegex(string $string, string $regex): bool { return preg_match('#' . str_replace('#', '\#', $regex) . '#', $string) === 1; } @@ -97,8 +97,8 @@ final class Validator * * @return bool */ - public static function isRegex(string $regex) + public static function isRegex(string $regex): bool { - return @preg_match('#' . str_replace('#', '\#', $regex) . '#', null); + return @preg_match('#' . str_replace('#', '\#', $regex) . '#', null) !== false; } } \ No newline at end of file diff --git a/lib/SP/Mvc/Model/QueryCondition.php b/lib/SP/Mvc/Model/QueryCondition.php index f88f8e92..a2cfee6b 100644 --- a/lib/SP/Mvc/Model/QueryCondition.php +++ b/lib/SP/Mvc/Model/QueryCondition.php @@ -46,12 +46,12 @@ final class QueryCondition protected $param = []; /** - * @param string $query - * @param array $params + * @param string $query + * @param array|null $params * * @return QueryCondition */ - public function addFilter($query, array $params = null) + public function addFilter(string $query, ?array $params = null): QueryCondition { $this->query[] = "($query)"; @@ -67,7 +67,7 @@ final class QueryCondition * * @return string|null */ - public function getFilters($type = self::CONDITION_AND) + public function getFilters(string $type = self::CONDITION_AND): ?string { if ($type !== self::CONDITION_AND && $type !== self::CONDITION_OR) { throw new RuntimeException(__u('Invalid filter type')); @@ -79,7 +79,7 @@ final class QueryCondition /** * @return bool */ - public function hasFilters() + public function hasFilters(): bool { return !empty($this->query); } @@ -87,7 +87,7 @@ final class QueryCondition /** * @return array */ - public function getParams() + public function getParams(): array { return $this->param; } @@ -95,7 +95,7 @@ final class QueryCondition /** * @return int */ - public function getFiltersCount() + public function getFiltersCount(): int { return count($this->query); } diff --git a/lib/SP/Mvc/View/Template.php b/lib/SP/Mvc/View/Template.php index d9e5ae0f..ff45d4be 100644 --- a/lib/SP/Mvc/View/Template.php +++ b/lib/SP/Mvc/View/Template.php @@ -83,12 +83,12 @@ final class Template /** * Añadir una nueva plantilla al array de plantillas de la clase * - * @param string $name Con el nombre del archivo de plantilla - * @param string $base Directorio base para la plantilla + * @param string $name Con el nombre del archivo de plantilla + * @param string|null $base Directorio base para la plantilla * * @return bool */ - public function addContentTemplate($name, $base = null) + public function addContentTemplate(string $name, ?string $base = null) { try { $template = $this->checkTemplate($name, $base); @@ -103,14 +103,14 @@ final class Template /** * Comprobar si un archivo de plantilla existe y se puede leer * - * @param string $template Con el nombre del archivo - * @param string $base Directorio base para la plantilla + * @param string $template Con el nombre del archivo + * @param string|null $base Directorio base para la plantilla * * @return string La ruta al archivo de la plantilla * * @throws FileNotFoundException */ - private function checkTemplate($template, $base = null) + private function checkTemplate(string $template, ?string $base = null): string { $base = null !== $base ? $base : (null !== $this->base ? $this->base : null); @@ -141,7 +141,7 @@ final class Template * @param string $file Con el nombre del archivo * @param string $name Nombre de la plantilla */ - private function setContentTemplate($file, $name) + private function setContentTemplate(string $file, string $name) { $this->contentTemplates[$name] = $file; } @@ -149,11 +149,11 @@ final class Template /** * Removes a template from the stack * - * @param $name + * @param string $name * * @return Template */ - public function removeTemplate($name) + public function removeTemplate(string $name): Template { unset($this->templates[$name]); @@ -163,11 +163,11 @@ final class Template /** * Removes a template from the stack * - * @param $name + * @param string $name * * @return Template */ - public function removeContentTemplate($name) + public function removeContentTemplate(string $name): Template { unset($this->contentTemplates[$name]); @@ -183,7 +183,7 @@ final class Template * * @return mixed|string */ - public function replaceTemplate($src, $dst, $base) + public function replaceTemplate(string $src, string $dst, string $base) { try { if (isset($this->contentTemplates[$dst])) { @@ -199,9 +199,9 @@ final class Template /** * Add partial template * - * @param $partial + * @param string $partial */ - public function addPartial($partial) + public function addPartial(string $partial) { $this->addTemplate($partial, self::PARTIALS_DIR); } @@ -209,12 +209,12 @@ final class Template /** * Añadir una nueva plantilla al array de plantillas de la clase * - * @param string $name Con el nombre del archivo de plantilla - * @param string $base Directorio base para la plantilla + * @param string $name Con el nombre del archivo de plantilla + * @param string|null $base Directorio base para la plantilla * * @return bool */ - public function addTemplate($name, $base = null) + public function addTemplate(string $name, ?string $base = null) { try { $template = $this->checkTemplate($name, $base); @@ -232,7 +232,7 @@ final class Template * @param string $file Con el nombre del archivo * @param string $name Nombre de la plantilla */ - private function setTemplate($file, $name) + private function setTemplate(string $file, string $name) { $this->templates[$name] = $file; } @@ -244,7 +244,7 @@ final class Template * * @return bool */ - public function includePartial($file) + public function includePartial(string $file) { return $this->includeTemplate($file, self::PARTIALS_DIR); } @@ -252,12 +252,12 @@ final class Template /** * Añadir una nueva plantilla dentro de una plantilla * - * @param string $file Con el nombre del archivo de plantilla - * @param string $base Directorio base para la plantilla + * @param string $file Con el nombre del archivo de plantilla + * @param string|null $base Directorio base para la plantilla * * @return bool */ - public function includeTemplate($file, $base = null) + public function includeTemplate(string $file, ?string $base = null) { try { return $this->checkTemplate($file, $base); @@ -273,7 +273,7 @@ final class Template * * @return null */ - public function __get($name) + public function __get(string $name) { return $this->get($name); } @@ -285,7 +285,7 @@ final class Template * @param string $name Nombre del atributo * @param string $value Valor del atributo */ - public function __set($name, $value) + public function __set(string $name, string $value) { $this->vars->set($name, $value); } @@ -293,11 +293,11 @@ final class Template /** * Returns a variable value * - * @param $name + * @param string $name * * @return mixed */ - public function get($name) + public function get(string $name) { if (!$this->vars->exists($name)) { logger(sprintf(__('Unable to retrieve "%s" variable'), $name), 'ERROR'); @@ -317,7 +317,7 @@ final class Template * * @return bool */ - public function __isset($name) + public function __isset(string $name): bool { return $this->vars->exists($name); } @@ -330,7 +330,7 @@ final class Template * * @return $this */ - public function __unset($name) + public function __unset(string $name): Template { if (!$this->vars->exists($name)) { logger(sprintf(__('Unable to unset "%s" variable'), $name)); @@ -351,7 +351,7 @@ final class Template * @return string Con el contenido del buffer de salida * @throws FileNotFoundException */ - public function render() + public function render(): string { if (empty($this->templates)) { throw new FileNotFoundException(__('Template does not contain files')); @@ -393,12 +393,12 @@ final class Template /** * Anexar el valor de la variable al array de la misma en el array de variables * - * @param $name string nombre de la variable - * @param $value mixed valor de la variable - * @param $index string índice del array - * @param null $scope string ámbito de la variable + * @param string $name nombre de la variable + * @param mixed $value valor de la variable + * @param string|null $scope string ámbito de la variable + * @param int|null $index string índice del array */ - public function append($name, $value, $scope = null, $index = null) + public function append(string $name, $value, ?string $scope = null, int $index = null) { if (null !== $scope) { $name = $scope . '_' . $name; @@ -418,7 +418,7 @@ final class Template /** * Reset de las plantillas añadidas */ - public function resetTemplates() + public function resetTemplates(): Template { $this->templates = []; @@ -428,7 +428,7 @@ final class Template /** * Reset de las plantillas añadidas */ - public function resetContentTemplates() + public function resetContentTemplates(): Template { $this->contentTemplates = []; @@ -446,7 +446,7 @@ final class Template /** * @return string */ - public function getBase() + public function getBase(): string { return $this->base; } @@ -454,7 +454,7 @@ final class Template /** * @param string $base */ - public function setBase($base) + public function setBase(string $base) { $this->base = $base; } @@ -462,7 +462,7 @@ final class Template /** * @return ThemeInterface */ - public function getTheme() + public function getTheme(): ThemeInterface { return $this->theme; } @@ -478,7 +478,7 @@ final class Template /** * @return array */ - public function getContentTemplates() + public function getContentTemplates(): array { return $this->contentTemplates; } @@ -486,7 +486,7 @@ final class Template /** * @return bool */ - public function hashContentTemplates() + public function hasContentTemplates(): bool { return count($this->contentTemplates) > 0; } @@ -494,7 +494,7 @@ final class Template /** * @return array */ - public function getTemplates() + public function getTemplates(): array { return $this->templates; } @@ -504,7 +504,7 @@ final class Template * * @return $this */ - public function upgrade() + public function upgrade(): Template { if (count($this->templates) > 0) { $this->contentTemplates = $this->templates; @@ -520,11 +520,11 @@ final class Template /** * Crear la variable y asignarle un valor en el array de variables * - * @param $name string nombre de la variable - * @param $value mixed valor de la variable - * @param null $scope string ámbito de la variable + * @param string $name nombre de la variable + * @param mixed $value valor de la variable + * @param string|null $scope string ámbito de la variable */ - public function assign($name, $value = '', $scope = null) + public function assign(string $name, $value = '', ?string $scope = null) { if (null !== $scope) { $name = $scope . '_' . $name; @@ -536,7 +536,7 @@ final class Template /** * @return bool */ - public function isUpgraded() + public function isUpgraded(): bool { return $this->upgraded; } diff --git a/lib/SP/Plugin/PluginBase.php b/lib/SP/Plugin/PluginBase.php index 976e98b8..3f6d278e 100644 --- a/lib/SP/Plugin/PluginBase.php +++ b/lib/SP/Plugin/PluginBase.php @@ -84,7 +84,7 @@ abstract class PluginBase implements PluginInterface /** * @return string */ - public function getType() + public function getType(): ?string { return $this->type; } @@ -92,7 +92,7 @@ abstract class PluginBase implements PluginInterface /** * @param string $type */ - public function setType($type) + public function setType(string $type) { $this->type = $type; } @@ -100,7 +100,7 @@ abstract class PluginBase implements PluginInterface /** * @return string */ - public function getThemeDir() + public function getThemeDir(): ?string { return $this->themeDir; } @@ -116,7 +116,7 @@ abstract class PluginBase implements PluginInterface /** * @return int */ - public function getEnabled() + public function getEnabled(): int { return (int)$this->enabled; } @@ -124,7 +124,7 @@ abstract class PluginBase implements PluginInterface /** * @param int $enabled */ - public function setEnabled($enabled) + public function setEnabled(int $enabled) { $this->enabled = (int)$enabled; } @@ -165,7 +165,7 @@ abstract class PluginBase implements PluginInterface /** * @return string */ - public function getBase() + public function getBase(): ?string { return $this->base; } diff --git a/lib/SP/Plugin/PluginInterface.php b/lib/SP/Plugin/PluginInterface.php index ac936b7a..097bfc0f 100644 --- a/lib/SP/Plugin/PluginInterface.php +++ b/lib/SP/Plugin/PluginInterface.php @@ -34,54 +34,54 @@ interface PluginInterface extends PluginEventReceiver /** * Devuelve el tipo de plugin * - * @return string + * @return string|null */ - public function getType(); + public function getType(): ?string; /** * Devuelve el directorio base del plugin * - * @return string + * @return string|null */ - public function getBase(); + public function getBase(): ?string; /** * Devuelve el directorio del tema usado * - * @return mixed + * @return string|null */ - public function getThemeDir(); + public function getThemeDir(): ?string; /** * Devuelve el autor del plugin * - * @return string + * @return string|null */ - public function getAuthor(); + public function getAuthor(): ?string; /** * Devuelve la versión del plugin * - * @return array + * @return array|null */ - public function getVersion(); + public function getVersion(): ?array; /** * Devuelve la versión compatible de sysPass * - * @return array + * @return array|null */ - public function getCompatibleVersion(); + public function getCompatibleVersion(): ?array; /** * Devuelve el nombre del plugin * - * @return string + * @return string|null */ - public function getName(); + public function getName(): ?string; /** - * @return mixed + * @return mixed|null */ public function getData(); @@ -98,7 +98,7 @@ interface PluginInterface extends PluginEventReceiver /** * @param int $enabled */ - public function setEnabled($enabled); + public function setEnabled(int $enabled); /** * @param string $version diff --git a/lib/SP/Plugin/PluginManager.php b/lib/SP/Plugin/PluginManager.php index 5c19101e..50953ed3 100644 --- a/lib/SP/Plugin/PluginManager.php +++ b/lib/SP/Plugin/PluginManager.php @@ -107,7 +107,7 @@ final class PluginManager * * @return array */ - public static function getPlugins() + public static function getPlugins(): array { if (is_dir(PLUGINS_PATH)) { $dir = dir(PLUGINS_PATH); @@ -134,7 +134,7 @@ final class PluginManager return $plugins; } - return []; + return []; } /** @@ -145,7 +145,7 @@ final class PluginManager * * @return PluginInterface */ - public function getPlugin($name, bool $initialize = false) + public function getPlugin(string $name, bool $initialize = false): ?PluginInterface { if (isset(self::$pluginsAvailable[$name])) { $plugin = $this->loadPluginClass( @@ -172,7 +172,7 @@ final class PluginManager * * @return PluginInterface */ - private function loadPluginClass(string $name, string $namespace) + private function loadPluginClass(string $name, string $namespace): ?PluginInterface { $pluginName = ucfirst($name); @@ -224,7 +224,7 @@ final class PluginManager * @throws NoSuchItemException * @throws QueryException */ - public function checkCompatibility(PluginInterface $plugin) + public function checkCompatibility(PluginInterface $plugin): bool { $pluginVersion = implode('.', $plugin->getCompatibleVersion()); $appVersion = implode('.', array_slice(Installer::VERSION, 0, 2)); @@ -248,7 +248,7 @@ final class PluginManager * * @return bool */ - private function initPlugin(PluginInterface $plugin) + private function initPlugin(PluginInterface $plugin): bool { try { $pluginModel = $this->pluginService->getByName($plugin->getName()); @@ -455,7 +455,7 @@ final class PluginManager * @throws ConstraintException * @throws QueryException */ - public function getEnabledPlugins() + public function getEnabledPlugins(): ?array { if ($this->enabledPlugins !== null) { return $this->enabledPlugins; @@ -475,7 +475,7 @@ final class PluginManager * * @return PluginInterface[] */ - public function getLoadedPlugins() + public function getLoadedPlugins(): array { return $this->loadedPlugins; } @@ -485,7 +485,7 @@ final class PluginManager * * @return string[] */ - public function getDisabledPlugins() + public function getDisabledPlugins(): array { return $this->disabledPlugins; } diff --git a/lib/SP/Plugin/PluginOperation.php b/lib/SP/Plugin/PluginOperation.php index 145a27ed..b70220b2 100644 --- a/lib/SP/Plugin/PluginOperation.php +++ b/lib/SP/Plugin/PluginOperation.php @@ -72,7 +72,7 @@ final class PluginOperation * @throws QueryException * @throws ServiceException */ - public function create(int $itemId, $data) + public function create(int $itemId, $data): int { $itemData = new PluginDataModel(); $itemData->setName($this->pluginName); @@ -93,7 +93,7 @@ final class PluginOperation * @throws QueryException * @throws ServiceException */ - public function update(int $itemId, $data) + public function update(int $itemId, $data): int { $itemData = new PluginDataModel(); $itemData->setName($this->pluginName); diff --git a/lib/SP/Providers/Acl/AclHandler.php b/lib/SP/Providers/Acl/AclHandler.php index 01597161..d7cb9c4a 100644 --- a/lib/SP/Providers/Acl/AclHandler.php +++ b/lib/SP/Providers/Acl/AclHandler.php @@ -67,7 +67,7 @@ final class AclHandler extends Provider implements EventReceiver * * @return array */ - public function getEvents() + public function getEvents(): array { return self::EVENTS; } @@ -77,7 +77,7 @@ final class AclHandler extends Provider implements EventReceiver * * @return string */ - public function getEventsString() + public function getEventsString(): string { return $this->events; } @@ -105,7 +105,7 @@ final class AclHandler extends Provider implements EventReceiver * @param string $eventType Nombre del evento * @param Event $event Objeto del evento */ - public function updateEvent($eventType, Event $event) + public function updateEvent(string $eventType, Event $event) { switch ($eventType) { case 'edit.userProfile': diff --git a/lib/SP/Providers/Auth/AuthDataBase.php b/lib/SP/Providers/Auth/AuthDataBase.php index 2238b4d0..fe24c17a 100644 --- a/lib/SP/Providers/Auth/AuthDataBase.php +++ b/lib/SP/Providers/Auth/AuthDataBase.php @@ -61,9 +61,9 @@ abstract class AuthDataBase protected $failed = false; /** - * @return string + * @return string|null */ - public function getName() + public function getName(): ?string { return $this->name; } @@ -71,15 +71,15 @@ abstract class AuthDataBase /** * @param string $name */ - public function setName($name) + public function setName(string $name) { $this->name = $name; } /** - * @return string + * @return string|null */ - public function getEmail() + public function getEmail(): ?string { return $this->email; } @@ -87,15 +87,15 @@ abstract class AuthDataBase /** * @param string $email */ - public function setEmail($email) + public function setEmail(string $email) { $this->email = $email; } /** - * @return int + * @return int|null */ - public function getAuthenticated() + public function getAuthenticated(): ?int { return $this->authenticated; } @@ -105,7 +105,7 @@ abstract class AuthDataBase * * @return $this */ - public function setAuthenticated($authenticated = null) + public function setAuthenticated(?bool $authenticated = null): AuthDataBase { $this->authenticated = $authenticated !== null ? (bool)$authenticated : null; @@ -113,9 +113,9 @@ abstract class AuthDataBase } /** - * @return string + * @return string|null */ - public function getServer() + public function getServer(): ?string { return $this->server; } @@ -123,7 +123,7 @@ abstract class AuthDataBase /** * @param string $server */ - public function setServer($server) + public function setServer(string $server) { $this->server = $server; } @@ -131,7 +131,7 @@ abstract class AuthDataBase /** * @return int */ - public function getStatusCode() + public function getStatusCode(): int { return (int)$this->statusCode; } @@ -139,7 +139,7 @@ abstract class AuthDataBase /** * @param int $statusCode */ - public function setStatusCode($statusCode) + public function setStatusCode(int $statusCode) { $this->statusCode = (int)$statusCode; } @@ -149,7 +149,7 @@ abstract class AuthDataBase * * @return bool */ - public function isAuthoritative() + public function isAuthoritative(): bool { return (bool)$this->authoritative; } @@ -159,15 +159,15 @@ abstract class AuthDataBase * * @param bool $authoritative */ - public function setAuthoritative($authoritative) + public function setAuthoritative(bool $authoritative) { $this->authoritative = (bool)$authoritative; } /** - * @return bool + * @return bool|null */ - public function isFailed() + public function isFailed(): ?bool { return $this->failed; } @@ -175,7 +175,7 @@ abstract class AuthDataBase /** * @param bool $failed */ - public function setFailed($failed) + public function setFailed(bool $failed) { $this->failed = $failed; } diff --git a/lib/SP/Providers/Auth/AuthInterface.php b/lib/SP/Providers/Auth/AuthInterface.php index b61386b7..598b9a55 100644 --- a/lib/SP/Providers/Auth/AuthInterface.php +++ b/lib/SP/Providers/Auth/AuthInterface.php @@ -47,5 +47,5 @@ interface AuthInterface * * @return boolean */ - public function isAuthGranted(); + public function isAuthGranted(): bool; } \ No newline at end of file diff --git a/lib/SP/Providers/Auth/AuthResult.php b/lib/SP/Providers/Auth/AuthResult.php index 9f279b40..9032a1a2 100644 --- a/lib/SP/Providers/Auth/AuthResult.php +++ b/lib/SP/Providers/Auth/AuthResult.php @@ -53,17 +53,17 @@ final class AuthResult } /** - * @return string + * @return string|null */ - public function getAuthName() + public function getAuthName(): ?string { return $this->authName; } /** - * @return AuthDataBase + * @return AuthDataBase|null */ - public function getData() + public function getData(): ?AuthDataBase { return $this->data; } diff --git a/lib/SP/Providers/Auth/Browser/Browser.php b/lib/SP/Providers/Auth/Browser/Browser.php index 1f76b100..15952633 100644 --- a/lib/SP/Providers/Auth/Browser/Browser.php +++ b/lib/SP/Providers/Auth/Browser/Browser.php @@ -96,9 +96,9 @@ final class Browser implements AuthInterface /** * Indica si es requerida para acceder a la aplicación * - * @return boolean + * @return bool */ - public function isAuthGranted() + public function isAuthGranted(): bool { return $this->configData->isAuthBasicAutoLoginEnabled(); } @@ -110,7 +110,7 @@ final class Browser implements AuthInterface * * @return bool|null */ - public function checkServerAuthUser($login) + public function checkServerAuthUser(string $login): ?bool { $domain = $this->configData->getAuthBasicDomain(); $authUser = $this->getServerAuthUser(); @@ -127,7 +127,7 @@ final class Browser implements AuthInterface * * @return string */ - public function getServerAuthUser() + public function getServerAuthUser(): ?string { $authUser = $this->request->getServer('PHP_AUTH_USER'); @@ -149,7 +149,7 @@ final class Browser implements AuthInterface * * @return string|null */ - protected function getAuthPass() + protected function getAuthPass(): ?string { $authPass = $this->request->getServer('PHP_AUTH_PW'); diff --git a/lib/SP/Providers/Auth/Database/Database.php b/lib/SP/Providers/Auth/Database/Database.php index 207d9c00..83cd1174 100644 --- a/lib/SP/Providers/Auth/Database/Database.php +++ b/lib/SP/Providers/Auth/Database/Database.php @@ -90,7 +90,7 @@ final class Database implements AuthInterface * * @return boolean */ - public function isAuthGranted() + public function isAuthGranted(): bool { return true; } @@ -103,15 +103,19 @@ final class Database implements AuthInterface * * @return bool */ - protected function authUser() + protected function authUser(): bool { try { $userLoginResponse = UserService::mapUserLoginResponse($this->userService->getByLogin($this->userLoginData->getLoginUser())); $this->userLoginData->setUserLoginResponse($userLoginResponse); - if ($userLoginResponse->getIsMigrate() && $this->checkMigrateUser($userLoginResponse)) { - return $this->userPassService->migrateUserPassById($userLoginResponse->getId(), $this->userLoginData->getLoginPass()); + if ($userLoginResponse->getIsMigrate() + && $this->checkMigrateUser($userLoginResponse) + ) { + $this->userPassService->migrateUserPassById($userLoginResponse->getId(), $this->userLoginData->getLoginPass()); + + return true; } return Hash::checkHashKey($this->userLoginData->getLoginPass(), $userLoginResponse->getPass()); @@ -127,7 +131,7 @@ final class Database implements AuthInterface * * @return bool */ - protected function checkMigrateUser(UserLoginResponse $userLoginResponse) + protected function checkMigrateUser(UserLoginResponse $userLoginResponse): bool { return ($userLoginResponse->getPass() === sha1($userLoginResponse->getHashSalt() . $this->userLoginData->getLoginPass()) || $userLoginResponse->getPass() === md5($this->userLoginData->getLoginPass()) diff --git a/lib/SP/Providers/Auth/Ldap/Ldap.php b/lib/SP/Providers/Auth/Ldap/Ldap.php index 31548527..0177fddc 100644 --- a/lib/SP/Providers/Auth/Ldap/Ldap.php +++ b/lib/SP/Providers/Auth/Ldap/Ldap.php @@ -127,12 +127,12 @@ abstract class Ldap implements LdapInterface } /** - * @param string $bindDn - * @param string $bindPass + * @param string|null $bindDn + * @param string|null $bindPass * * @return bool */ - public function bind(string $bindDn = null, string $bindPass = null): bool + public function bind(?string $bindDn = null, ?string $bindPass = null): bool { return $this->ldapConnection->bind($bindDn, $bindPass); } diff --git a/lib/SP/Providers/Auth/Ldap/LdapActions.php b/lib/SP/Providers/Auth/Ldap/LdapActions.php index 8ff4b7b9..c7436f66 100644 --- a/lib/SP/Providers/Auth/Ldap/LdapActions.php +++ b/lib/SP/Providers/Auth/Ldap/LdapActions.php @@ -105,7 +105,7 @@ final class LdapActions * @return array Groups' DN * @throws LdapException */ - public function searchGroupsDn(string $groupFilter) + public function searchGroupsDn(string $groupFilter): array { $filter = '(&(cn=' . ldap_escape($this->getGroupFromParams(), null, LDAP_ESCAPE_FILTER) @@ -156,13 +156,17 @@ final class LdapActions /** * Devolver los resultados de una paginación * - * @param string $filter Filtro a utilizar - * @param array $attributes Atributos a devolver - * @param string $searchBase + * @param string $filter Filtro a utilizar + * @param array|null $attributes Atributos a devolver + * @param string|null $searchBase * * @return bool|array */ - protected function getResults($filter, array $attributes = null, $searchBase = null) + protected function getResults( + string $filter, + ?array $attributes = null, + ?string $searchBase = null + ) { $cookie = ''; $results = []; @@ -216,7 +220,7 @@ final class LdapActions * @return AttributeCollection * @throws LdapException */ - public function getAttributes(string $filter) + public function getAttributes(string $filter): AttributeCollection { $searchResults = $this->getObjects($filter); @@ -264,14 +268,18 @@ final class LdapActions /** * Obtener los objetos según el filtro indicado * - * @param string $filter - * @param array $attributes - * @param string $searchBase + * @param string $filter + * @param array $attributes + * @param string|null $searchBase * * @return array * @throws LdapException */ - public function getObjects($filter, array $attributes = self::USER_ATTRIBUTES, $searchBase = null) + public function getObjects( + string $filter, + array $attributes = self::USER_ATTRIBUTES, + ?string $searchBase = null + ) { $searchResults = $this->getResults($filter, $attributes, $searchBase); diff --git a/lib/SP/Providers/Auth/Ldap/LdapAuth.php b/lib/SP/Providers/Auth/Ldap/LdapAuth.php index 7b99986f..af4191cb 100644 --- a/lib/SP/Providers/Auth/Ldap/LdapAuth.php +++ b/lib/SP/Providers/Auth/Ldap/LdapAuth.php @@ -85,7 +85,7 @@ final class LdapAuth implements AuthInterface /** * @return LdapAuthData */ - public function getLdapAuthData() + public function getLdapAuthData(): ?LdapAuthData { return $this->ldapAuthData; } @@ -93,7 +93,7 @@ final class LdapAuth implements AuthInterface /** * @return string */ - public function getUserLogin() + public function getUserLogin(): ?string { return $this->userLogin; } @@ -101,7 +101,7 @@ final class LdapAuth implements AuthInterface /** * @param string $userLogin */ - public function setUserLogin($userLogin) + public function setUserLogin(string $userLogin) { $this->userLogin = strtolower($userLogin); } @@ -142,7 +142,7 @@ final class LdapAuth implements AuthInterface * * @return boolean */ - public function isAuthGranted() + public function isAuthGranted(): bool { return !$this->configData->isLdapDatabaseEnabled(); } @@ -155,7 +155,7 @@ final class LdapAuth implements AuthInterface * @return LdapAuthData con los atributos disponibles y sus valores * @throws LdapException */ - public function getAttributes(string $userLogin) + public function getAttributes(string $userLogin): LdapAuthData { $attributes = $this->ldap->getLdapActions() ->getAttributes($this->ldap->getUserDnFilter($userLogin)); @@ -172,8 +172,11 @@ final class LdapAuth implements AuthInterface $mail = $attributes->get('mail'); + if ($mail !== null) { + $this->ldapAuthData->setEmail(is_array($mail) ? $mail[0] : $mail); + } + $this->ldapAuthData->setDn($attributes->get('dn')); - $this->ldapAuthData->setEmail(is_array($mail) ? $mail[0] : $mail); $this->ldapAuthData->setExpire($attributes->get('expire')); $this->ldapAuthData->setInGroup( diff --git a/lib/SP/Providers/Auth/Ldap/LdapAuthData.php b/lib/SP/Providers/Auth/Ldap/LdapAuthData.php index 9138e9d0..c7fb2850 100644 --- a/lib/SP/Providers/Auth/Ldap/LdapAuthData.php +++ b/lib/SP/Providers/Auth/Ldap/LdapAuthData.php @@ -53,7 +53,7 @@ final class LdapAuthData extends AuthDataBase /** * @return string */ - public function getDn() + public function getDn(): ?string { return $this->dn; } @@ -61,7 +61,7 @@ final class LdapAuthData extends AuthDataBase /** * @param string $dn */ - public function setDn($dn) + public function setDn(string $dn) { $this->dn = $dn; } @@ -69,7 +69,7 @@ final class LdapAuthData extends AuthDataBase /** * @return int */ - public function getExpire() + public function getExpire(): int { return (int)$this->expire; } @@ -85,7 +85,7 @@ final class LdapAuthData extends AuthDataBase /** * @return boolean */ - public function isInGroup() + public function isInGroup(): bool { return $this->inGroup; } @@ -93,7 +93,7 @@ final class LdapAuthData extends AuthDataBase /** * @param boolean $inGroup */ - public function setInGroup($inGroup) + public function setInGroup(bool $inGroup) { $this->inGroup = $inGroup; } @@ -101,7 +101,7 @@ final class LdapAuthData extends AuthDataBase /** * @return string */ - public function getGroupDn() + public function getGroupDn(): ?string { return $this->groupDn; } @@ -109,7 +109,7 @@ final class LdapAuthData extends AuthDataBase /** * @param string $groupDn */ - public function setGroupDn($groupDn) + public function setGroupDn(string $groupDn) { $this->groupDn = $groupDn; } diff --git a/lib/SP/Providers/Auth/Ldap/LdapConnection.php b/lib/SP/Providers/Auth/Ldap/LdapConnection.php index d56dcab1..3e6602ee 100644 --- a/lib/SP/Providers/Auth/Ldap/LdapConnection.php +++ b/lib/SP/Providers/Auth/Ldap/LdapConnection.php @@ -77,7 +77,11 @@ final class LdapConnection implements LdapConnectionInterface * @param EventDispatcher $eventDispatcher * @param bool $debug */ - public function __construct(LdapParams $ldapParams, EventDispatcher $eventDispatcher, $debug = false) + public function __construct( + LdapParams $ldapParams, + EventDispatcher $eventDispatcher, + bool $debug = false + ) { $this->ldapParams = $ldapParams; $this->eventDispatcher = $eventDispatcher; @@ -163,7 +167,7 @@ final class LdapConnection implements LdapConnectionInterface * * @throws LdapException */ - public function checkParams() + public function checkParams(): bool { if (empty($this->ldapParams->getSearchBase()) || empty($this->getServer()) @@ -175,6 +179,8 @@ final class LdapConnection implements LdapConnectionInterface throw new LdapException(__u('LDAP parameters are not set')); } + + return true; } /** @@ -190,16 +196,13 @@ final class LdapConnection implements LdapConnectionInterface * * @return LdapConnection */ - public function setServer(string $server) + public function setServer(string $server): LdapConnectionInterface { $this->server = $server; return $this; } - /** - * @inheritDoc - */ public function getServerUri(): string { $server = $this->getServer(); @@ -246,11 +249,11 @@ final class LdapConnection implements LdapConnectionInterface /** * Registrar error de LDAP y devolver el mensaje de error * - * @param $ldapHandler + * @param resource $ldapHandler * * @return string */ - public static function getLdapErrorMessage($ldapHandler) + public static function getLdapErrorMessage($ldapHandler): string { return sprintf('%s (%d)', ldap_error($ldapHandler), ldap_errno($ldapHandler)); } @@ -258,8 +261,8 @@ final class LdapConnection implements LdapConnectionInterface /** * Realizar la autentificación con el servidor de LDAP. * - * @param string $bindDn con el DN del usuario - * @param string $bindPass con la clave del usuario + * @param string|null $bindDn con el DN del usuario + * @param string|null $bindPass con la clave del usuario * * @return bool * @throws LdapException @@ -291,7 +294,7 @@ final class LdapConnection implements LdapConnectionInterface /** * @return int */ - public function getErrorCode() + public function getErrorCode(): int { if (is_resource($this->ldapHandler)) { return ldap_errno($this->ldapHandler); diff --git a/lib/SP/Providers/Auth/Ldap/LdapConnectionInterface.php b/lib/SP/Providers/Auth/Ldap/LdapConnectionInterface.php index dff90e05..a2406c69 100644 --- a/lib/SP/Providers/Auth/Ldap/LdapConnectionInterface.php +++ b/lib/SP/Providers/Auth/Ldap/LdapConnectionInterface.php @@ -41,7 +41,7 @@ interface LdapConnectionInterface * * @return bool */ - public function checkParams(); + public function checkParams(): bool; /** * @return resource @@ -58,12 +58,12 @@ interface LdapConnectionInterface public function connect(): bool; /** - * @param string $bindDn - * @param string $bindPass + * @param string|null $bindDn + * @param string|null $bindPass * * @return bool */ - public function bind(string $bindDn = null, string $bindPass = null): bool; + public function bind(?string $bindDn = null, ?string $bindPass = null): bool; /** * @return bool @@ -85,5 +85,5 @@ interface LdapConnectionInterface * * @return LdapConnectionInterface */ - public function setServer(string $server); + public function setServer(string $server): LdapConnectionInterface; } \ No newline at end of file diff --git a/lib/SP/Providers/Auth/Ldap/LdapInterface.php b/lib/SP/Providers/Auth/Ldap/LdapInterface.php index 92fbda68..1093f50f 100644 --- a/lib/SP/Providers/Auth/Ldap/LdapInterface.php +++ b/lib/SP/Providers/Auth/Ldap/LdapInterface.php @@ -53,11 +53,11 @@ interface LdapInterface /** * Return the filter to check the group membership from group's attributes * - * @param string $userDn + * @param string|null $userDn * * @return string */ - public function getGroupMembershipDirectFilter(string $userDn = null): string; + public function getGroupMembershipDirectFilter(?string $userDn = null): string; /** * Buscar al usuario en un grupo. @@ -85,12 +85,12 @@ interface LdapInterface public function connect(); /** - * @param string $bindDn - * @param string $bindPass + * @param string|null $bindDn + * @param string|null $bindPass * * @return bool */ - public function bind(string $bindDn = null, string $bindPass = null): bool; + public function bind(?string $bindDn = null, ?string $bindPass = null): bool; /** * @return LdapActions diff --git a/lib/SP/Providers/Auth/Ldap/LdapMsAds.php b/lib/SP/Providers/Auth/Ldap/LdapMsAds.php index 1e602c18..d999243f 100644 --- a/lib/SP/Providers/Auth/Ldap/LdapMsAds.php +++ b/lib/SP/Providers/Auth/Ldap/LdapMsAds.php @@ -73,7 +73,7 @@ final class LdapMsAds extends Ldap /** * @return string */ - private function getUserObjectFilter() + private function getUserObjectFilter(): string { if (empty($this->ldapParams->getFilterUserObject())) { return self::DEFAULT_FILTER_USER_OBJECT; @@ -176,7 +176,7 @@ final class LdapMsAds extends Ldap * @inheritDoc * @throws LdapException */ - public function getGroupMembershipDirectFilter(string $userDn = null): string + public function getGroupMembershipDirectFilter(?string $userDn = null): string { if (empty($this->ldapParams->getFilterGroupAttributes())) { $attributes = self::DEFAULT_FILTER_GROUP_ATTRIBUTES; diff --git a/lib/SP/Providers/Auth/Ldap/LdapParams.php b/lib/SP/Providers/Auth/Ldap/LdapParams.php index 26ac85bf..7a0b15d5 100644 --- a/lib/SP/Providers/Auth/Ldap/LdapParams.php +++ b/lib/SP/Providers/Auth/Ldap/LdapParams.php @@ -103,9 +103,9 @@ final class LdapParams } /** - * @param string $filterUserObject + * @param string|null $filterUserObject */ - public function setFilterUserObject(string $filterUserObject = null) + public function setFilterUserObject(?string $filterUserObject = null) { if (!empty($filterUserObject)) { $this->filterUserObject = $filterUserObject; @@ -121,9 +121,9 @@ final class LdapParams } /** - * @param string $filterGroupObject + * @param string|null $filterGroupObject */ - public function setFilterGroupObject(string $filterGroupObject = null) + public function setFilterGroupObject(?string $filterGroupObject = null) { if (!empty($filterGroupObject)) { $this->filterGroupObject = $filterGroupObject; @@ -139,9 +139,9 @@ final class LdapParams } /** - * @param array $filterUserAttributes + * @param array|null $filterUserAttributes */ - public function setFilterUserAttributes(array $filterUserAttributes = null) + public function setFilterUserAttributes(?array $filterUserAttributes = null) { $this->filterUserAttributes = $filterUserAttributes; } @@ -155,9 +155,9 @@ final class LdapParams } /** - * @param array $filterGroupAttributes + * @param array|null $filterGroupAttributes */ - public function setFilterGroupAttributes(array $filterGroupAttributes = null) + public function setFilterGroupAttributes(?array $filterGroupAttributes = null) { $this->filterGroupAttributes = $filterGroupAttributes; } @@ -165,7 +165,7 @@ final class LdapParams /** * @return int */ - public function getPort() + public function getPort(): int { return $this->port; } @@ -175,7 +175,7 @@ final class LdapParams * * @return LdapParams */ - public function setPort($port) + public function setPort(int $port): LdapParams { $this->port = $port; @@ -185,7 +185,7 @@ final class LdapParams /** * @return string */ - public function getSearchBase() + public function getSearchBase(): ?string { return $this->searchBase; } @@ -195,7 +195,7 @@ final class LdapParams * * @return LdapParams */ - public function setSearchBase($searchBase) + public function setSearchBase(string $searchBase): LdapParams { $this->searchBase = $searchBase; return $this; @@ -204,7 +204,7 @@ final class LdapParams /** * @return string */ - public function getBindDn() + public function getBindDn(): ?string { return $this->bindDn; } @@ -214,7 +214,7 @@ final class LdapParams * * @return LdapParams */ - public function setBindDn($bindDn) + public function setBindDn(string $bindDn): LdapParams { $this->bindDn = $bindDn; return $this; @@ -223,7 +223,7 @@ final class LdapParams /** * @return string */ - public function getBindPass() + public function getBindPass(): ?string { return $this->bindPass; } @@ -233,7 +233,7 @@ final class LdapParams * * @return LdapParams */ - public function setBindPass($bindPass) + public function setBindPass(string $bindPass): LdapParams { $this->bindPass = $bindPass; return $this; @@ -242,7 +242,7 @@ final class LdapParams /** * @return string */ - public function getGroup() + public function getGroup(): ?string { return $this->group; } @@ -252,16 +252,16 @@ final class LdapParams * * @return LdapParams */ - public function setGroup($group) + public function setGroup(string $group): LdapParams { $this->group = $group; return $this; } /** - * @return string + * @return string|null */ - public function getServer() + public function getServer(): ?string { return $this->server; } @@ -271,7 +271,7 @@ final class LdapParams * * @return LdapParams */ - public function setServer($server) + public function setServer(string $server): LdapParams { $this->server = $server; @@ -281,7 +281,7 @@ final class LdapParams /** * @return int */ - public function getType(): int + public function getType(): ?int { return $this->type; } @@ -291,7 +291,7 @@ final class LdapParams * * @return LdapParams */ - public function setType($type) + public function setType($type): LdapParams { $this->type = (int)$type; @@ -311,7 +311,7 @@ final class LdapParams * * @return LdapParams */ - public function setTlsEnabled(bool $tlsEnabled) + public function setTlsEnabled(bool $tlsEnabled): LdapParams { $this->tlsEnabled = $tlsEnabled; diff --git a/lib/SP/Providers/Auth/Ldap/LdapStd.php b/lib/SP/Providers/Auth/Ldap/LdapStd.php index e878cf37..dffe268d 100644 --- a/lib/SP/Providers/Auth/Ldap/LdapStd.php +++ b/lib/SP/Providers/Auth/Ldap/LdapStd.php @@ -70,7 +70,7 @@ final class LdapStd extends Ldap /** * @return string */ - private function getUserObjectFilter() + private function getUserObjectFilter(): string { if (empty($this->ldapParams->getFilterUserObject())) { return self::DEFAULT_FILTER_USER_OBJECT; @@ -154,7 +154,7 @@ final class LdapStd extends Ldap /** * @inheritDoc */ - public function getGroupMembershipDirectFilter(string $userDn = null): string + public function getGroupMembershipDirectFilter(?string $userDn = null): string { $groupName = ldap_escape($this->getGroupFromParams(), null, LDAP_ESCAPE_FILTER); $member = $userDn !== null ? ldap_escape($userDn, null, LDAP_ESCAPE_FILTER) : '*'; diff --git a/lib/SP/Providers/Auth/Ldap/LdapUtil.php b/lib/SP/Providers/Auth/Ldap/LdapUtil.php index 7c7dd6a7..7274d37c 100644 --- a/lib/SP/Providers/Auth/Ldap/LdapUtil.php +++ b/lib/SP/Providers/Auth/Ldap/LdapUtil.php @@ -38,7 +38,7 @@ final class LdapUtil * * @return string */ - public static function escapeLdapDN($dn) + public static function escapeLdapDN(string $dn): string { $chars = [ '/(,)(?!uid|cn|ou|dc)/i', @@ -56,7 +56,7 @@ final class LdapUtil * * @param string $group * - * @return bool + * @return bool|string */ public static function getGroupName(string $group) { @@ -73,7 +73,7 @@ final class LdapUtil * * @return string */ - public static function getAttributesForFilter(array $attributes, $value): string + public static function getAttributesForFilter(array $attributes, string $value): string { $value = ldap_escape((string)$value, null, LDAP_ESCAPE_FILTER); diff --git a/lib/SP/Providers/Log/DatabaseLogHandler.php b/lib/SP/Providers/Log/DatabaseLogHandler.php index 5af90bb0..95c74a2d 100644 --- a/lib/SP/Providers/Log/DatabaseLogHandler.php +++ b/lib/SP/Providers/Log/DatabaseLogHandler.php @@ -87,7 +87,7 @@ final class DatabaseLogHandler extends Provider implements EventReceiver * * @throws InvalidClassException */ - public function updateEvent($eventType, Event $event) + public function updateEvent(string $eventType, Event $event) { if (strpos($eventType, 'database.') !== false) { return; @@ -132,7 +132,7 @@ final class DatabaseLogHandler extends Provider implements EventReceiver * * @return string */ - public function getEventsString() + public function getEventsString(): ?string { return $this->events; } @@ -142,7 +142,7 @@ final class DatabaseLogHandler extends Provider implements EventReceiver * * @return array */ - public function getEvents() + public function getEvents(): array { return LogInterface::EVENTS; } diff --git a/lib/SP/Providers/Log/FileLogHandler.php b/lib/SP/Providers/Log/FileLogHandler.php index c16c9b2c..5c20e6b0 100644 --- a/lib/SP/Providers/Log/FileLogHandler.php +++ b/lib/SP/Providers/Log/FileLogHandler.php @@ -48,7 +48,7 @@ final class FileLogHandler extends LoggerBase * * @return array */ - public function getEvents() + public function getEvents(): array { return LogInterface::EVENTS; } @@ -58,7 +58,7 @@ final class FileLogHandler extends LoggerBase * * @return string */ - public function getEventsString() + public function getEventsString(): string { return $this->events; } diff --git a/lib/SP/Providers/Log/LoggerBase.php b/lib/SP/Providers/Log/LoggerBase.php index 3bb48159..8e347759 100644 --- a/lib/SP/Providers/Log/LoggerBase.php +++ b/lib/SP/Providers/Log/LoggerBase.php @@ -73,7 +73,7 @@ abstract class LoggerBase extends Provider implements EventReceiver * * @throws InvalidClassException */ - public function updateEvent($eventType, Event $event) + public function updateEvent(string $eventType, Event $event) { $this->language->setAppLocales(); @@ -111,7 +111,11 @@ abstract class LoggerBase extends Provider implements EventReceiver * * @return array */ - final protected function formatContext($message, $address, $user): array + final protected function formatContext( + string $message, + string $address, + string $user + ): array { return [ 'message' => trim($message), diff --git a/lib/SP/Providers/Log/RemoteSyslogHandler.php b/lib/SP/Providers/Log/RemoteSyslogHandler.php index ceec9ae0..9ec1950d 100644 --- a/lib/SP/Providers/Log/RemoteSyslogHandler.php +++ b/lib/SP/Providers/Log/RemoteSyslogHandler.php @@ -45,7 +45,7 @@ final class RemoteSyslogHandler extends LoggerBase * * @return array */ - public function getEvents() + public function getEvents(): array { return LogInterface::EVENTS; } @@ -55,7 +55,7 @@ final class RemoteSyslogHandler extends LoggerBase * * @return string */ - public function getEventsString() + public function getEventsString(): string { return $this->events; } diff --git a/lib/SP/Providers/Log/SyslogHandler.php b/lib/SP/Providers/Log/SyslogHandler.php index e35257e1..971cd677 100644 --- a/lib/SP/Providers/Log/SyslogHandler.php +++ b/lib/SP/Providers/Log/SyslogHandler.php @@ -44,7 +44,7 @@ final class SyslogHandler extends LoggerBase * * @return array */ - public function getEvents() + public function getEvents(): array { return LogInterface::EVENTS; } @@ -54,7 +54,7 @@ final class SyslogHandler extends LoggerBase * * @return string */ - public function getEventsString() + public function getEventsString(): string { return $this->events; } diff --git a/lib/SP/Providers/Mail/MailHandler.php b/lib/SP/Providers/Mail/MailHandler.php index 629f8135..0649a4ca 100644 --- a/lib/SP/Providers/Mail/MailHandler.php +++ b/lib/SP/Providers/Mail/MailHandler.php @@ -86,7 +86,7 @@ final class MailHandler extends Provider implements EventReceiver * * @return array */ - public function getEvents() + public function getEvents(): array { return self::EVENTS; } @@ -96,7 +96,7 @@ final class MailHandler extends Provider implements EventReceiver * * @return string */ - public function getEventsString() + public function getEventsString(): string { return $this->events; } @@ -124,7 +124,7 @@ final class MailHandler extends Provider implements EventReceiver * @param string $eventType Nombre del evento * @param Event $event Objeto del evento */ - public function updateEvent($eventType, Event $event) + public function updateEvent(string $eventType, Event $event) { if (($eventMessage = $event->getEventMessage()) !== null) { try { diff --git a/lib/SP/Providers/Mail/MailProvider.php b/lib/SP/Providers/Mail/MailProvider.php index 3435c4d5..076c7ab7 100644 --- a/lib/SP/Providers/Mail/MailProvider.php +++ b/lib/SP/Providers/Mail/MailProvider.php @@ -103,7 +103,7 @@ final class MailProvider extends Provider /** * @return bool */ - public function isDebug() + public function isDebug(): bool { return $this->debug; } @@ -111,7 +111,7 @@ final class MailProvider extends Provider /** * @param bool $debug */ - public function setDebug($debug) + public function setDebug(bool $debug) { $this->debug = (bool)$debug; } diff --git a/lib/SP/Providers/Notification/NotificationHandler.php b/lib/SP/Providers/Notification/NotificationHandler.php index 0335f486..06ff408e 100644 --- a/lib/SP/Providers/Notification/NotificationHandler.php +++ b/lib/SP/Providers/Notification/NotificationHandler.php @@ -64,7 +64,7 @@ final class NotificationHandler extends Provider implements EventReceiver * * @return array */ - public function getEvents() + public function getEvents(): array { return self::EVENTS; } @@ -74,7 +74,7 @@ final class NotificationHandler extends Provider implements EventReceiver * * @return string */ - public function getEventsString() + public function getEventsString(): string { return $this->events; } @@ -102,7 +102,7 @@ final class NotificationHandler extends Provider implements EventReceiver * @param string $eventType Nombre del evento * @param Event $event Objeto del evento */ - public function updateEvent($eventType, Event $event) + public function updateEvent(string $eventType, Event $event) { switch ($eventType) { case 'request.account': diff --git a/lib/SP/Repositories/Account/AccountHistoryRepository.php b/lib/SP/Repositories/Account/AccountHistoryRepository.php index 1c1b8296..729ce952 100644 --- a/lib/SP/Repositories/Account/AccountHistoryRepository.php +++ b/lib/SP/Repositories/Account/AccountHistoryRepository.php @@ -56,7 +56,7 @@ final class AccountHistoryRepository extends Repository implements RepositoryIte * @throws QueryException * @throws ConstraintException */ - public function getHistoryForAccount($id) + public function getHistoryForAccount($id): QueryResult { $query = /** @lang SQL */ 'SELECT AH.id, @@ -86,7 +86,7 @@ final class AccountHistoryRepository extends Repository implements RepositoryIte * @throws QueryException * @throws ConstraintException */ - public function create($dto) + public function create($dto): int { $queryData = new QueryData(); $query = /** @lang SQL */ @@ -151,7 +151,7 @@ final class AccountHistoryRepository extends Repository implements RepositoryIte * * @param int $id * - * @return bool Los ids de las cuentas eliminadas + * @return int Los ids de las cuentas eliminadas * @throws ConstraintException * @throws QueryException */ diff --git a/lib/SP/Repositories/Notification/NotificationRepository.php b/lib/SP/Repositories/Notification/NotificationRepository.php index 15d5c942..79fec041 100644 --- a/lib/SP/Repositories/Notification/NotificationRepository.php +++ b/lib/SP/Repositories/Notification/NotificationRepository.php @@ -353,7 +353,7 @@ final class NotificationRepository extends Repository implements RepositoryItemI $queryData->setFrom('Notification'); $queryData->setOrder('`date` DESC'); - if ($itemSearchData->getSeachString() !== '') { + if (!empty($itemSearchData->getSeachString())) { $queryData->setWhere('type LIKE ? OR component LIKE ? OR description LIKE ?'); $search = '%' . $itemSearchData->getSeachString() . '%'; @@ -380,7 +380,7 @@ final class NotificationRepository extends Repository implements RepositoryItemI * @throws ConstraintException * @throws QueryException */ - public function searchForUserId(ItemSearchData $itemSearchData, $userId) + public function searchForUserId(ItemSearchData $itemSearchData, int $userId): QueryResult { $queryData = new QueryData(); $queryData->setMapClassName(NotificationData::class); @@ -389,9 +389,10 @@ final class NotificationRepository extends Repository implements RepositoryItemI $queryData->setOrder('`date` DESC'); $queryCondition = new QueryCondition(); - $queryCondition->addFilter('userId = ?', [$userId]); - $queryCondition->addFilter('(userId IS NULL AND onlyAdmin = 0)'); - $queryCondition->addFilter('sticky = 1'); + $queryCondition + ->addFilter('userId = ?', [$userId]) + ->addFilter('(userId IS NULL AND onlyAdmin = 0)') + ->addFilter('sticky = 1'); if ($itemSearchData->getSeachString() !== '') { $queryData->setWhere( @@ -424,7 +425,7 @@ final class NotificationRepository extends Repository implements RepositoryItemI * @throws ConstraintException * @throws QueryException */ - public function searchForAdmin(ItemSearchData $itemSearchData, $userId) + public function searchForAdmin(ItemSearchData $itemSearchData, int $userId) { $queryData = new QueryData(); $queryData->setMapClassName(NotificationData::class); @@ -433,9 +434,10 @@ final class NotificationRepository extends Repository implements RepositoryItemI $queryData->setOrder('`date` DESC'); $queryCondition = new QueryCondition(); - $queryCondition->addFilter('userId = ?', [$userId]); - $queryCondition->addFilter('onlyAdmin = 1'); - $queryCondition->addFilter('sticky = 1'); + $queryCondition + ->addFilter('userId = ?', [$userId]) + ->addFilter('onlyAdmin = 1') + ->addFilter('sticky = 1'); if ($itemSearchData->getSeachString() !== '') { $queryData->setWhere( diff --git a/lib/SP/Services/Account/AccountAcl.php b/lib/SP/Services/Account/AccountAcl.php index 839f5e83..f31f5743 100644 --- a/lib/SP/Services/Account/AccountAcl.php +++ b/lib/SP/Services/Account/AccountAcl.php @@ -159,7 +159,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setUserInGroups(bool $userInGroups) + public function setUserInGroups(bool $userInGroups): AccountAcl { $this->userInGroups = $userInGroups; @@ -179,7 +179,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setUserInUsers(bool $userInUsers) + public function setUserInUsers(bool $userInUsers): AccountAcl { $this->userInUsers = $userInUsers; @@ -199,7 +199,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setResultView(bool $resultView) + public function setResultView(bool $resultView): AccountAcl { $this->resultView = $resultView; @@ -219,7 +219,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setResultEdit(bool $resultEdit) + public function setResultEdit(bool $resultEdit): AccountAcl { $this->resultEdit = $resultEdit; @@ -241,7 +241,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setShowDetails(bool $showDetails) + public function setShowDetails(bool $showDetails): AccountAcl { $this->showDetails = $showDetails; @@ -262,7 +262,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setShowPass(bool $showPass) + public function setShowPass(bool $showPass): AccountAcl { $this->showPass = $showPass; @@ -285,7 +285,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setShowFiles(bool $showFiles) + public function setShowFiles(bool $showFiles): AccountAcl { $this->showFiles = $this->resultView && $showFiles; @@ -310,7 +310,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setShowViewPass(bool $showViewPass) + public function setShowViewPass(bool $showViewPass): AccountAcl { $this->showViewPass = $this->resultView && $showViewPass; @@ -332,7 +332,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setShowSave(bool $showSave) + public function setShowSave(bool $showSave): AccountAcl { $this->showSave = $showSave; @@ -354,7 +354,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setShowEdit(bool $showEdit) + public function setShowEdit(bool $showEdit): AccountAcl { $this->showEdit = $this->resultEdit && $showEdit && !$this->isHistory; @@ -376,7 +376,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setShowEditPass(bool $showEditPass) + public function setShowEditPass(bool $showEditPass): AccountAcl { $this->showEditPass = $this->resultEdit && $showEditPass && !$this->isHistory; @@ -399,7 +399,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setShowDelete(bool $showDelete) + public function setShowDelete(bool $showDelete): AccountAcl { $this->showDelete = $this->resultEdit && $showDelete; @@ -419,7 +419,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setShowRestore(bool $showRestore) + public function setShowRestore(bool $showRestore): AccountAcl { $this->showRestore = $this->resultEdit && $showRestore; @@ -439,7 +439,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setShowLink(bool $showLink) + public function setShowLink(bool $showLink): AccountAcl { $this->showLink = $showLink; @@ -461,7 +461,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setShowHistory(bool $showHistory) + public function setShowHistory(bool $showHistory): AccountAcl { $this->showHistory = $showHistory; @@ -489,7 +489,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setActionId($actionId) + public function setActionId($actionId): AccountAcl { $this->actionId = (int)$actionId; @@ -509,7 +509,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setTime($time) + public function setTime($time): AccountAcl { $this->time = (int)$time; @@ -519,11 +519,11 @@ final class AccountAcl /** * Comprueba los permisos de acceso a una cuenta. * - * @param null $actionId + * @param int $actionId * * @return bool */ - public function checkAccountAccess($actionId) + public function checkAccountAccess(int $actionId): bool { if ($this->compiledAccountAccess === false) { return false; @@ -559,7 +559,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setModified($modified) + public function setModified(bool $modified): AccountAcl { $this->modified = $modified; @@ -579,7 +579,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setShowView(bool $showView) + public function setShowView(bool $showView): AccountAcl { $this->showView = $this->resultView && $showView; @@ -602,7 +602,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setShowCopy(bool $showCopy) + public function setShowCopy(bool $showCopy): AccountAcl { $this->showCopy = $this->resultView && $showCopy; @@ -622,7 +622,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setShowPermission(bool $showPermission) + public function setShowPermission(bool $showPermission): AccountAcl { $this->showPermission = $showPermission; @@ -642,7 +642,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setAccountId($accountId) + public function setAccountId($accountId): AccountAcl { $this->accountId = (int)$accountId; @@ -662,7 +662,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setIsHistory(bool $isHistory) + public function setIsHistory(bool $isHistory): AccountAcl { $this->isHistory = $isHistory; @@ -682,7 +682,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setCompiledShowAccess($compiledShowAccess) + public function setCompiledShowAccess(bool $compiledShowAccess): AccountAcl { $this->compiledShowAccess = (bool)$compiledShowAccess; @@ -702,7 +702,7 @@ final class AccountAcl * * @return AccountAcl */ - public function setCompiledAccountAccess($compiledAccountAccess) + public function setCompiledAccountAccess(bool $compiledAccountAccess): AccountAcl { $this->compiledAccountAccess = (bool)$compiledAccountAccess; diff --git a/lib/SP/Services/Account/AccountAclService.php b/lib/SP/Services/Account/AccountAclService.php index 5a9167b0..bb0a9cc3 100644 --- a/lib/SP/Services/Account/AccountAclService.php +++ b/lib/SP/Services/Account/AccountAclService.php @@ -97,15 +97,15 @@ final class AccountAclService extends Service /** * Obtener la ACL de una cuenta * - * @param int $actionId - * @param AccountAclDto $accountAclDto - * @param bool $isHistory + * @param int $actionId + * @param AccountAclDto|null $accountAclDto + * @param bool $isHistory * * @return AccountAcl * @throws ConstraintException * @throws QueryException */ - public function getAcl($actionId, AccountAclDto $accountAclDto = null, $isHistory = false) + public function getAcl($actionId, ?AccountAclDto $accountAclDto = null, $isHistory = false) { $this->accountAcl = new AccountAcl($actionId, $isHistory); $this->accountAcl->setShowPermission(self::getShowPermission($this->context->getUserData(), $this->context->getUserProfile())); diff --git a/lib/SP/Services/Backup/FileBackupService.php b/lib/SP/Services/Backup/FileBackupService.php index 90eafefb..d29ca87a 100644 --- a/lib/SP/Services/Backup/FileBackupService.php +++ b/lib/SP/Services/Backup/FileBackupService.php @@ -312,8 +312,10 @@ final class FileBackupService extends Service foreach ($row as $value) { if (is_numeric($value)) { $fileHandler->write($value); - } else { + } elseif ($value) { $fileHandler->write($databaseUtil->escape($value)); + } else { + $fileHandler->write(null); } if ($field < $numColumns) { diff --git a/lib/SP/Services/Import/SyspassImport.php b/lib/SP/Services/Import/SyspassImport.php index 1be5d90f..61170221 100644 --- a/lib/SP/Services/Import/SyspassImport.php +++ b/lib/SP/Services/Import/SyspassImport.php @@ -63,7 +63,7 @@ final class SyspassImport extends XmlImportBase implements ImportInterface ->addDescription(__u('sysPass XML Import'))) ); - if ($this->importParams->getImportMasterPwd() !== '') { + if (!empty($this->importParams->getImportMasterPwd())) { $this->mPassValidHash = Hash::checkHashKey( $this->importParams->getImportMasterPwd(), $this->configService->getByParam('masterPwd') diff --git a/lib/SP/Services/User/UserPassService.php b/lib/SP/Services/User/UserPassService.php index 29bfaca2..6fd33172 100644 --- a/lib/SP/Services/User/UserPassService.php +++ b/lib/SP/Services/User/UserPassService.php @@ -255,7 +255,7 @@ final class UserPassService extends Service * @throws QueryException * @throws NoSuchItemException */ - public function migrateUserPassById($id, $userPass) + public function migrateUserPassById($id, string $userPass) { if ($this->userRepository->updatePassById($id, new UpdatePassRequest(Hash::hashKey($userPass))) === 0) { throw new NoSuchItemException(__u('User does not exist')); diff --git a/lib/SP/Storage/Database/DBStorageInterface.php b/lib/SP/Storage/Database/DBStorageInterface.php index ef5e2e5c..f0a202b8 100644 --- a/lib/SP/Storage/Database/DBStorageInterface.php +++ b/lib/SP/Storage/Database/DBStorageInterface.php @@ -38,29 +38,29 @@ interface DBStorageInterface * * @return PDO */ - public function getConnection(); + public function getConnection(): PDO; /** * Obtener una conexión PDO sin seleccionar la BD * * @return PDO */ - public function getConnectionSimple(); + public function getConnectionSimple(): PDO; /** * Devolcer el estado de la BD * * @return int */ - public function getDbStatus(); - - /** - * @return mixed - */ - public function getConnectionUri(); + public function getDbStatus(): int; /** * @return string */ - public function getDatabaseName(); + public function getConnectionUri(): string; + + /** + * @return string|null + */ + public function getDatabaseName(): ?string; } \ No newline at end of file diff --git a/lib/SP/Storage/Database/Database.php b/lib/SP/Storage/Database/Database.php index 88f9fffc..b26d152e 100644 --- a/lib/SP/Storage/Database/Database.php +++ b/lib/SP/Storage/Database/Database.php @@ -81,7 +81,7 @@ final class Database implements DatabaseInterface /** * @return int */ - public function getNumRows() + public function getNumRows(): int { return $this->numRows; } @@ -89,23 +89,23 @@ final class Database implements DatabaseInterface /** * @return int */ - public function getNumFields() + public function getNumFields(): int { return $this->numFields; } /** - * @return array + * @return array|null */ - public function getLastResult() + public function getLastResult(): ?array { return $this->lastResult; } /** - * @return int + * @return int|null */ - public function getLastId() + public function getLastId(): ?int { return $this->lastId; } @@ -113,7 +113,7 @@ final class Database implements DatabaseInterface /** * @return DBStorageInterface */ - public function getDbHandler() + public function getDbHandler(): DBStorageInterface { return $this->dbHandler; } @@ -126,7 +126,7 @@ final class Database implements DatabaseInterface * @throws ConstraintException * @throws QueryException */ - public function doSelect(QueryData $queryData, $fullCount = false) + public function doSelect(QueryData $queryData, $fullCount = false): QueryResult { if ($queryData->getQuery() === '') { throw new QueryException($queryData->getOnErrorMessage(), QueryException::ERROR, __u('Blank query')); @@ -202,7 +202,11 @@ final class Database implements DatabaseInterface * @throws ConstraintException * @throws QueryException */ - private function prepareQueryData(QueryData $queryData, $isCount = false, array $options = []) + private function prepareQueryData( + QueryData $queryData, + bool $isCount = false, + array $options = [] + ): PDOStatement { $query = $queryData->getQuery(); $params = $queryData->getParams(); @@ -265,7 +269,7 @@ final class Database implements DatabaseInterface * * @return array */ - private function getParamsForCount(QueryData $queryData) + private function getParamsForCount(QueryData $queryData): array { $countSelect = substr_count($queryData->getSelect(), '?'); $countFrom = substr_count($queryData->getFrom(), '?'); @@ -294,12 +298,12 @@ final class Database implements DatabaseInterface /** * Obtener el número de filas de una consulta realizada * - * @param $queryData QueryData Los datos de la consulta + * @param QueryData $queryData Los datos de la consulta * * @return int Número de files de la consulta * @throws SPException */ - public function getFullRowCount(QueryData $queryData) + public function getFullRowCount(QueryData $queryData): int { if ($queryData->getQueryCount() === '') { return 0; @@ -317,13 +321,16 @@ final class Database implements DatabaseInterface * * @param QueryData $queryData * @param array $options - * @param bool $buffered Set buffered behavior (useful for big datasets) + * @param bool|null $buffered Set buffered behavior (useful for big datasets) * * @return PDOStatement * @throws ConstraintException - * @throws QueryException + * @throws QueryException|DatabaseException */ - public function doQueryRaw(QueryData $queryData, array $options = [], bool $buffered = null) + public function doQueryRaw( + QueryData $queryData, + array $options = [], + ?bool $buffered = null): PDOStatement { if ($buffered === false && $this->dbHandler instanceof MySQLHandler @@ -333,7 +340,7 @@ final class Database implements DatabaseInterface ->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false); } - return $this->prepareQueryData($queryData, $options); + return $this->prepareQueryData($queryData, false, $options); } /** @@ -341,7 +348,7 @@ final class Database implements DatabaseInterface * * @return bool */ - public function beginTransaction() + public function beginTransaction(): bool { $conn = $this->dbHandler->getConnection(); @@ -364,7 +371,7 @@ final class Database implements DatabaseInterface * * @return bool */ - public function endTransaction() + public function endTransaction(): bool { $conn = $this->dbHandler->getConnection(); @@ -381,7 +388,7 @@ final class Database implements DatabaseInterface * * @return bool */ - public function rollbackTransaction() + public function rollbackTransaction(): bool { $conn = $this->dbHandler->getConnection(); @@ -394,13 +401,14 @@ final class Database implements DatabaseInterface } /** - * @param $table + * @param string $table * * @return array */ - public function getColumnsForTable($table): array + public function getColumnsForTable(string $table): array { - $conn = $this->dbHandler->getConnection()->query("SELECT * FROM $table LIMIT 0"); + $conn = $this->dbHandler->getConnection() + ->query("SELECT * FROM `$table` LIMIT 0"); $columns = []; for ($i = 0; $i < $conn->columnCount(); $i++) { diff --git a/lib/SP/Storage/Database/DatabaseConnectionData.php b/lib/SP/Storage/Database/DatabaseConnectionData.php index 29f045ae..11176c40 100644 --- a/lib/SP/Storage/Database/DatabaseConnectionData.php +++ b/lib/SP/Storage/Database/DatabaseConnectionData.php @@ -92,9 +92,9 @@ final class DatabaseConnectionData } /** - * @return string + * @return string|null */ - public function getDbHost() + public function getDbHost(): ?string { return $this->dbHost; } @@ -104,35 +104,35 @@ final class DatabaseConnectionData * * @return DatabaseConnectionData */ - public function setDbHost($dbHost) + public function setDbHost(string $dbHost): DatabaseConnectionData { $this->dbHost = $dbHost; return $this; } /** - * @return string + * @return string|null */ - public function getDbSocket() + public function getDbSocket(): ?string { return $this->dbSocket; } /** - * @param string $dbSocket + * @param string|null $dbSocket * * @return DatabaseConnectionData */ - public function setDbSocket($dbSocket) + public function setDbSocket(?string $dbSocket): DatabaseConnectionData { $this->dbSocket = $dbSocket; return $this; } /** - * @return int + * @return int|null */ - public function getDbPort() + public function getDbPort(): ?int { return $this->dbPort; } @@ -142,16 +142,16 @@ final class DatabaseConnectionData * * @return DatabaseConnectionData */ - public function setDbPort($dbPort) + public function setDbPort(int $dbPort): DatabaseConnectionData { $this->dbPort = $dbPort; return $this; } /** - * @return string + * @return string|null */ - public function getDbName() + public function getDbName(): ?string { return $this->dbName; } @@ -161,16 +161,16 @@ final class DatabaseConnectionData * * @return DatabaseConnectionData */ - public function setDbName($dbName) + public function setDbName(string $dbName): DatabaseConnectionData { $this->dbName = $dbName; return $this; } /** - * @return string + * @return string|null */ - public function getDbUser() + public function getDbUser(): ?string { return $this->dbUser; } @@ -180,16 +180,16 @@ final class DatabaseConnectionData * * @return DatabaseConnectionData */ - public function setDbUser($dbUser) + public function setDbUser(string $dbUser): DatabaseConnectionData { $this->dbUser = $dbUser; return $this; } /** - * @return string + * @return string|null */ - public function getDbPass() + public function getDbPass(): ?string { return $this->dbPass; } @@ -199,7 +199,7 @@ final class DatabaseConnectionData * * @return DatabaseConnectionData */ - public function setDbPass($dbPass) + public function setDbPass(string $dbPass): DatabaseConnectionData { $this->dbPass = $dbPass; return $this; diff --git a/lib/SP/Storage/Database/DatabaseFileInterface.php b/lib/SP/Storage/Database/DatabaseFileInterface.php index 24a6cfb6..7901b1df 100644 --- a/lib/SP/Storage/Database/DatabaseFileInterface.php +++ b/lib/SP/Storage/Database/DatabaseFileInterface.php @@ -38,5 +38,5 @@ interface DatabaseFileInterface * * @return array */ - public function parse($delimiter = ';'); + public function parse($delimiter = ';'): array; } \ No newline at end of file diff --git a/lib/SP/Storage/Database/DatabaseInterface.php b/lib/SP/Storage/Database/DatabaseInterface.php index 46d98121..1db0c843 100644 --- a/lib/SP/Storage/Database/DatabaseInterface.php +++ b/lib/SP/Storage/Database/DatabaseInterface.php @@ -53,7 +53,7 @@ interface DatabaseInterface * * @return PDOStatement */ - public function doQueryRaw(QueryData $queryData); + public function doQueryRaw(QueryData $queryData): PDOStatement; /** * Returns the total number of records @@ -62,58 +62,58 @@ interface DatabaseInterface * * @return int Records count */ - public function getFullRowCount(QueryData $queryData); + public function getFullRowCount(QueryData $queryData): int; /** * @return DBStorageInterface */ - public function getDbHandler(); + public function getDbHandler(): DBStorageInterface; /** * @return int */ - public function getNumRows(); + public function getNumRows(): int; /** * @return int */ - public function getNumFields(); + public function getNumFields(): int; /** - * @return array + * @return array|null */ - public function getLastResult(); + public function getLastResult(): ?array; /** - * @return int + * @return int|null */ - public function getLastId(); + public function getLastId(): ?int; /** * Iniciar una transacción * * @return bool */ - public function beginTransaction(); + public function beginTransaction(): bool; /** * Finalizar una transacción * * @return bool */ - public function endTransaction(); + public function endTransaction(): bool; /** * Rollback de una transacción * * @return bool */ - public function rollbackTransaction(); + public function rollbackTransaction(): bool; /** - * @param $table + * @param string $table * * @return array */ - public function getColumnsForTable($table): array; + public function getColumnsForTable(string $table): array; } \ No newline at end of file diff --git a/lib/SP/Storage/Database/DatabaseUtil.php b/lib/SP/Storage/Database/DatabaseUtil.php index 2bca7a1c..f690d465 100644 --- a/lib/SP/Storage/Database/DatabaseUtil.php +++ b/lib/SP/Storage/Database/DatabaseUtil.php @@ -87,7 +87,7 @@ final class DatabaseUtil * * @return bool */ - public function checkDatabaseTables($dbName) + public function checkDatabaseTables(string $dbName): bool { try { $tables = implode(',', array_map(function ($value) { @@ -113,7 +113,7 @@ final class DatabaseUtil /** * @return bool */ - public function checkDatabaseConnection() + public function checkDatabaseConnection(): bool { try { $this->DBStorage->getConnection(); @@ -131,7 +131,7 @@ final class DatabaseUtil * * @return array */ - public function getDBinfo() + public function getDBinfo(): array { $dbinfo = []; @@ -164,7 +164,7 @@ final class DatabaseUtil * * @return string con la cadena escapada */ - public function escape($str) + public function escape(string $str): string { try { return $this->DBStorage->getConnection()->quote(trim($str)); diff --git a/lib/SP/Storage/Database/MySQLFileParser.php b/lib/SP/Storage/Database/MySQLFileParser.php index dede6a2a..d172e4fe 100644 --- a/lib/SP/Storage/Database/MySQLFileParser.php +++ b/lib/SP/Storage/Database/MySQLFileParser.php @@ -57,7 +57,7 @@ final class MySQLFileParser implements DatabaseFileInterface * @return array * @throws FileException */ - public function parse($delimiter = ';') + public function parse($delimiter = ';'): array { $queries = []; $query = ''; diff --git a/lib/SP/Storage/Database/MySQLHandler.php b/lib/SP/Storage/Database/MySQLHandler.php index 00ea5eca..f5a9282a 100644 --- a/lib/SP/Storage/Database/MySQLHandler.php +++ b/lib/SP/Storage/Database/MySQLHandler.php @@ -75,7 +75,7 @@ final class MySQLHandler implements DBStorageInterface * * @return int */ - public function getDbStatus() + public function getDbStatus(): int { return $this->dbStatus; } @@ -87,7 +87,7 @@ final class MySQLHandler implements DBStorageInterface * @return PDO * @throws DatabaseException */ - public function getConnection() + public function getConnection(): PDO { if (!$this->db) { if (null === $this->connectionData->getDbUser() @@ -131,7 +131,7 @@ final class MySQLHandler implements DBStorageInterface /** * @return string */ - public function getConnectionUri() + public function getConnectionUri(): string { $dsn = ['charset=utf8']; @@ -158,7 +158,7 @@ final class MySQLHandler implements DBStorageInterface * @return PDO * @throws DatabaseException */ - public function getConnectionSimple() + public function getConnectionSimple(): PDO { if (!$this->db) { if (null === $this->connectionData->getDbHost() && null === $this->connectionData->getDbSocket()) { @@ -188,9 +188,9 @@ final class MySQLHandler implements DBStorageInterface } /** - * @return string + * @return string|null */ - public function getDatabaseName() + public function getDatabaseName(): ?string { return $this->connectionData->getDbName(); } diff --git a/lib/SP/Storage/Database/QueryData.php b/lib/SP/Storage/Database/QueryData.php index 70c3d2f0..686545e7 100644 --- a/lib/SP/Storage/Database/QueryData.php +++ b/lib/SP/Storage/Database/QueryData.php @@ -44,11 +44,7 @@ final class QueryData /** * @var string */ - protected $mapClassName = ''; - /** - * @var DataModelBase - */ - protected $mapClass; + protected $mapClassName; /** * @var bool */ @@ -56,35 +52,31 @@ final class QueryData /** * @var string */ - protected $select = ''; + protected $select; /** * @var string */ - protected $from = ''; + protected $from; /** * @var string */ - protected $where = ''; + protected $where; /** * @var string */ - protected $groupBy = ''; + protected $groupBy; + /** + * @var string|null + */ + protected $order; /** * @var string */ - protected $order = ''; + protected $limit; /** * @var string */ - protected $limit = ''; - /** - * @var string - */ - protected $queryCount = ''; - /** - * @var int - */ - protected $queryNumRows = 0; + protected $queryCount; /** * @var int Código de estado tras realizar la consulta */ @@ -112,7 +104,7 @@ final class QueryData /** * @return array */ - public function getParams() + public function getParams(): array { return $this->params; } @@ -130,7 +122,7 @@ final class QueryData /** * @return string */ - public function getQuery() + public function getQuery(): string { if (empty($this->query)) { return $this->select . ' ' . $this->from . ' ' . $this->where . ' ' . $this->groupBy . ' ' . $this->order . ' ' . $this->limit; @@ -148,9 +140,9 @@ final class QueryData } /** - * @return string + * @return string|null */ - public function getMapClassName() + public function getMapClassName(): ?string { return $this->mapClassName; } @@ -158,7 +150,7 @@ final class QueryData /** * @param string $mapClassName */ - public function setMapClassName($mapClassName) + public function setMapClassName(string $mapClassName) { $this->mapClassName = $mapClassName; } @@ -166,7 +158,7 @@ final class QueryData /** * @return bool */ - public function isUseKeyPair() + public function isUseKeyPair(): bool { return $this->useKeyPair; } @@ -174,15 +166,15 @@ final class QueryData /** * @param boolean $useKeyPair */ - public function setUseKeyPair($useKeyPair) + public function setUseKeyPair(bool $useKeyPair) { - $this->useKeyPair = (bool)$useKeyPair; + $this->useKeyPair = $useKeyPair; } /** - * @return string + * @return string|null */ - public function getSelect() + public function getSelect(): ?string { return $this->select; } @@ -190,15 +182,15 @@ final class QueryData /** * @param string $select */ - public function setSelect($select) + public function setSelect(string $select) { $this->select = 'SELECT ' . $select; } /** - * @return string + * @return string|null */ - public function getOrder() + public function getOrder(): ?string { return $this->order; } @@ -206,7 +198,7 @@ final class QueryData /** * @param string $order */ - public function setOrder($order) + public function setOrder(string $order) { if (!empty($order)) { $this->order = 'ORDER BY ' . $order; @@ -214,9 +206,9 @@ final class QueryData } /** - * @return string + * @return string|null */ - public function getLimit() + public function getLimit(): ?string { return $this->limit; } @@ -225,7 +217,7 @@ final class QueryData * @param string $limit * @param array|null $params */ - public function setLimit($limit, array $params = null) + public function setLimit(string $limit, ?array $params = null) { if (!empty($limit)) { $this->limit = 'LIMIT ' . $limit; @@ -249,7 +241,7 @@ final class QueryData /** * @return string */ - public function getQueryCount() + public function getQueryCount(): string { if (empty($this->queryCount)) { return 'SELECT COUNT(*) ' . $this->from . ' ' . $this->where; @@ -259,9 +251,9 @@ final class QueryData } /** - * @return string + * @return string|null */ - public function getFrom() + public function getFrom(): ?string { return $this->from; } @@ -269,7 +261,7 @@ final class QueryData /** * @param string $from */ - public function setFrom($from) + public function setFrom(string $from) { if (!empty($from)) { $this->from = 'FROM ' . $from; @@ -277,9 +269,9 @@ final class QueryData } /** - * @return string + * @return string|null */ - public function getWhere() + public function getWhere(): ?string { return $this->where; } @@ -298,42 +290,10 @@ final class QueryData } } - /** - * @return int - */ - public function getQueryNumRows() - { - return (int)$this->queryNumRows; - } - - /** - * @param int $queryNumRows - */ - public function setQueryNumRows($queryNumRows) - { - $this->queryNumRows = (int)$queryNumRows; - } - - /** - * @return int - */ - public function getQueryStatus() - { - return $this->queryStatus; - } - - /** - * @param int $queryStatus - */ - public function setQueryStatus($queryStatus) - { - $this->queryStatus = $queryStatus; - } - /** * @return string */ - public function getOnErrorMessage() + public function getOnErrorMessage(): string { return $this->onErrorMessage ?: __u('Error while querying'); } @@ -341,13 +301,13 @@ final class QueryData /** * @param string $onErrorMessage */ - public function setOnErrorMessage($onErrorMessage) + public function setOnErrorMessage(string $onErrorMessage) { $this->onErrorMessage = $onErrorMessage; } /** - * @return string + * @return string|null */ public function getGroupBy() { @@ -357,7 +317,7 @@ final class QueryData /** * @param string $groupBy */ - public function setGroupBy($groupBy) + public function setGroupBy(string $groupBy) { if (!empty($groupBy)) { $this->groupBy = 'GROUP BY ' . $groupBy; diff --git a/lib/SP/Storage/Database/QueryResult.php b/lib/SP/Storage/Database/QueryResult.php index f40d6f3f..35f69091 100644 --- a/lib/SP/Storage/Database/QueryResult.php +++ b/lib/SP/Storage/Database/QueryResult.php @@ -59,9 +59,9 @@ final class QueryResult /** * QueryResult constructor. * - * @param array $data + * @param array|null $data */ - public function __construct(array $data = null) + public function __construct(?array $data = null) { if ($data !== null) { $this->data = $data; @@ -75,7 +75,7 @@ final class QueryResult * * @return QueryResult */ - public static function fromResults(array $data, $totalNumRows = null) + public static function fromResults(array $data, $totalNumRows = null): QueryResult { $result = new self($data); @@ -87,11 +87,9 @@ final class QueryResult } /** - * @param string $class - * * @return mixed|null */ - public function getData(string $class = null) + public function getData() { if ($this->numRows === 1) { return $this->data[0]; @@ -131,7 +129,7 @@ final class QueryResult * * @return QueryResult */ - public function setTotalNumRows(int $totalNumRows) + public function setTotalNumRows(int $totalNumRows): QueryResult { $this->totalNumRows = $totalNumRows; @@ -151,7 +149,7 @@ final class QueryResult * * @return QueryResult */ - public function setStatusCode(int $statusCode) + public function setStatusCode(int $statusCode): QueryResult { $this->statusCode = $statusCode; @@ -171,7 +169,7 @@ final class QueryResult * * @return QueryResult */ - public function setAffectedNumRows(int $affectedNumRows) + public function setAffectedNumRows(int $affectedNumRows): QueryResult { $this->affectedNumRows = $affectedNumRows; @@ -191,7 +189,7 @@ final class QueryResult * * @return QueryResult */ - public function setLastId(int $lastId) + public function setLastId(int $lastId): QueryResult { $this->lastId = $lastId; diff --git a/lib/SP/Storage/File/ArchiveHandler.php b/lib/SP/Storage/File/ArchiveHandler.php index be9b4057..83392410 100644 --- a/lib/SP/Storage/File/ArchiveHandler.php +++ b/lib/SP/Storage/File/ArchiveHandler.php @@ -85,7 +85,7 @@ final class ArchiveHandler * @throws CheckException * @throws FileException */ - public function compressDirectory(string $directory, string $regex = null) + public function compressDirectory(string $directory, ?string $regex = null) { $this->extensionChecker->checkPharAvailable(true); diff --git a/lib/SP/Storage/File/FileCache.php b/lib/SP/Storage/File/FileCache.php index db54af20..49f847bc 100644 --- a/lib/SP/Storage/File/FileCache.php +++ b/lib/SP/Storage/File/FileCache.php @@ -46,7 +46,7 @@ final class FileCache extends FileCacheBase * @return FileCacheInterface * @throws FileException */ - public function save($data) + public function save($data): FileCacheInterface { $this->createPath(); diff --git a/lib/SP/Storage/File/FileCacheBase.php b/lib/SP/Storage/File/FileCacheBase.php index 7328883a..523a1e51 100644 --- a/lib/SP/Storage/File/FileCacheBase.php +++ b/lib/SP/Storage/File/FileCacheBase.php @@ -42,7 +42,7 @@ abstract class FileCacheBase implements FileCacheInterface * * @param string $path */ - public function __construct($path) + public function __construct(string $path) { $this->path = new FileHandler($path); } @@ -52,7 +52,7 @@ abstract class FileCacheBase implements FileCacheInterface * * @return FileCacheBase */ - public static function factory($path) + public static function factory($path): FileCacheBase { return new static($path); } @@ -80,7 +80,7 @@ abstract class FileCacheBase implements FileCacheInterface * @return bool * @throws FileException */ - public function isExpiredDate($date): bool + public function isExpiredDate(int $date): bool { $this->path->checkFileExists(); @@ -103,7 +103,7 @@ abstract class FileCacheBase implements FileCacheInterface * @return FileCacheInterface * @throws FileException */ - public function delete() + public function delete(): FileCacheInterface { $this->path->delete(); diff --git a/lib/SP/Storage/File/FileCacheInterface.php b/lib/SP/Storage/File/FileCacheInterface.php index c2f68211..273fdb0b 100644 --- a/lib/SP/Storage/File/FileCacheInterface.php +++ b/lib/SP/Storage/File/FileCacheInterface.php @@ -43,12 +43,12 @@ interface FileCacheInterface * @return FileCacheInterface * @throws FileException */ - public function save($data); + public function save($data): FileCacheInterface; /** - * @return mixed + * @return FileCacheInterface */ - public function delete(); + public function delete(): FileCacheInterface; /** * Returns whether the file is expired @@ -67,7 +67,7 @@ interface FileCacheInterface * @return bool * @throws FileException */ - public function isExpiredDate($date): bool; + public function isExpiredDate(int $date): bool; /** * @return bool diff --git a/lib/SP/Storage/File/FileCachePacked.php b/lib/SP/Storage/File/FileCachePacked.php index 7078c114..a7c51aa6 100644 --- a/lib/SP/Storage/File/FileCachePacked.php +++ b/lib/SP/Storage/File/FileCachePacked.php @@ -62,7 +62,7 @@ final class FileCachePacked extends FileCacheBase * @return FileCacheInterface * @throws FileException */ - public function save($data) + public function save($data): FileCacheInterface { $this->createPath(); diff --git a/lib/SP/Storage/File/FileHandler.php b/lib/SP/Storage/File/FileHandler.php index a451e23b..05142f63 100644 --- a/lib/SP/Storage/File/FileHandler.php +++ b/lib/SP/Storage/File/FileHandler.php @@ -66,7 +66,7 @@ final class FileHandler * @return FileHandler * @throws FileException */ - public function write($data) + public function write($data): FileHandler { if (!is_resource($this->handle)) { $this->open('wb'); @@ -84,12 +84,12 @@ final class FileHandler * * @param string $mode * - * @param bool $lock + * @param bool|null $lock * * @return resource * @throws FileException */ - public function open($mode = 'r', $lock = false) + public function open(string $mode = 'r', ?bool $lock = false) { $this->handle = @fopen($this->file, $mode); @@ -111,7 +111,7 @@ final class FileHandler * * @throws FileException */ - private function lock($mode = LOCK_EX) + private function lock(int $mode = LOCK_EX) { $this->locked = flock($this->handle, $mode); @@ -159,7 +159,7 @@ final class FileHandler * @return FileHandler * @throws FileException */ - public function save($data) + public function save(string $data): FileHandler { if (file_put_contents($this->file, $data, LOCK_EX) === false) { throw new FileException(sprintf(__('Unable to read/write the file (%s)'), $this->file)); @@ -174,7 +174,7 @@ final class FileHandler * @return string Data read from file * @throws FileException */ - public function read() + public function read(): string { if (!is_resource($this->handle)) { $this->open('rb'); @@ -197,7 +197,7 @@ final class FileHandler * @return FileHandler * @throws FileException */ - public function close() + public function close(): FileHandler { if ($this->locked) { $this->unlock(); @@ -219,12 +219,12 @@ final class FileHandler } /** - * @param callable $chunker - * @param float $rate + * @param callable|null $chunker + * @param float|null $rate * * @throws FileException */ - public function readChunked(callable $chunker = null, float $rate = null) + public function readChunked(callable $chunker = null, ?float $rate = null) { $maxRate = Util::getMaxDownloadChunk() / self::CHUNK_FACTOR; @@ -255,7 +255,7 @@ final class FileHandler * @return FileHandler * @throws FileException */ - public function checkIsWritable() + public function checkIsWritable(): FileHandler { if (!is_writable($this->file) && @touch($this->file) === false) { throw new FileException(sprintf(__('Unable to write in file (%s)'), $this->file)); @@ -270,7 +270,7 @@ final class FileHandler * @return FileHandler * @throws FileException */ - public function checkFileExists() + public function checkFileExists(): FileHandler { if (!file_exists($this->file)) { throw new FileException(sprintf(__('File not found (%s)'), $this->file)); @@ -309,7 +309,7 @@ final class FileHandler * * @return FileHandler */ - public function clearCache() + public function clearCache(): FileHandler { clearstatcache(true, $this->file); @@ -322,7 +322,7 @@ final class FileHandler * @return FileHandler * @throws FileException */ - public function delete() + public function delete(): FileHandler { if (@unlink($this->file) === false) { throw new FileException(sprintf(__('Unable to delete file (%s)'), $this->file)); @@ -350,7 +350,7 @@ final class FileHandler * @return FileHandler * @throws FileException */ - public function checkIsReadable() + public function checkIsReadable(): FileHandler { if (!is_readable($this->file)) { throw new FileException(sprintf(__('Unable to read/write file (%s)'), $this->file)); diff --git a/lib/SP/Storage/File/XmlFileStorageInterface.php b/lib/SP/Storage/File/XmlFileStorageInterface.php index c6b69a60..4dcf0712 100644 --- a/lib/SP/Storage/File/XmlFileStorageInterface.php +++ b/lib/SP/Storage/File/XmlFileStorageInterface.php @@ -37,7 +37,7 @@ interface XmlFileStorageInterface * @return XmlFileStorageInterface * @throws FileException */ - public function load($node = ''); + public function load(string $node = ''): XmlFileStorageInterface; /** * @param mixed $data Data to be saved @@ -46,7 +46,7 @@ interface XmlFileStorageInterface * @return XmlFileStorageInterface * @throws FileException */ - public function save($data, $node = ''); + public function save($data, string $node = ''): XmlFileStorageInterface; /** * @return mixed @@ -61,7 +61,7 @@ interface XmlFileStorageInterface * @return string * @throws FileException */ - public function getPathValue($path); + public function getPathValue(string $path): string; /** * @return FileHandler diff --git a/lib/SP/Storage/File/XmlHandler.php b/lib/SP/Storage/File/XmlHandler.php index 2a9b4355..e9c269d4 100644 --- a/lib/SP/Storage/File/XmlHandler.php +++ b/lib/SP/Storage/File/XmlHandler.php @@ -75,7 +75,7 @@ final class XmlHandler implements XmlFileStorageInterface * @throws FileException * @throws RuntimeException */ - public function load($node = 'root'): XmlFileStorageInterface + public function load(string $node = 'root'): XmlFileStorageInterface { $this->fileHandler->checkIsReadable(); $this->fileHandler->getFileSize(true); @@ -175,7 +175,7 @@ final class XmlHandler implements XmlFileStorageInterface * @throws FileException * @throws RuntimeException */ - public function save($data, $node = 'root'): XmlFileStorageInterface + public function save($data, string $node = 'root'): XmlFileStorageInterface { $this->fileHandler->checkIsWritable(); @@ -314,7 +314,7 @@ final class XmlHandler implements XmlFileStorageInterface * @return string * @throws FileException */ - public function getPathValue($path) + public function getPathValue(string $path):string { $this->fileHandler->checkIsReadable(); $this->fileHandler->getFileSize(true); diff --git a/lib/SP/Util/ArrayUtil.php b/lib/SP/Util/ArrayUtil.php index f6c0772a..02c37509 100644 --- a/lib/SP/Util/ArrayUtil.php +++ b/lib/SP/Util/ArrayUtil.php @@ -37,11 +37,16 @@ final class ArrayUtil * @param array $array * @param string $property Nombre de la propiedad * @param string $value Valor de la propiedad - * @param object $default Valor por defecto + * @param null $default Valor por defecto * * @return false|object */ - public static function searchInObject(array $array, $property, $value, $default = null) + public static function searchInObject( + array $array, + string $property, + string $value, + $default = null + ) { foreach ($array as $object) { if (is_object($object) @@ -64,7 +69,7 @@ final class ArrayUtil * * @return bool */ - public static function checkInObjectArrayMethod(array $objectArray, $method, $value) + public static function checkInObjectArrayMethod(array $objectArray, string $method, $value) { foreach ($objectArray as $object) { if (is_callable([$object, $method]) && $object->$method() === $value) { @@ -84,7 +89,7 @@ final class ArrayUtil * * @return bool */ - public static function checkInObjectArray(array $objectArray, $property, $value) + public static function checkInObjectArray(array $objectArray, string $property, $value) { if (empty($objectArray)) { return false; diff --git a/lib/SP/Util/Checks.php b/lib/SP/Util/Checks.php index d5c439a5..4f49fd5b 100644 --- a/lib/SP/Util/Checks.php +++ b/lib/SP/Util/Checks.php @@ -36,7 +36,7 @@ final class Checks * * @return bool */ - public static function checkIsWindows() + public static function checkIsWindows(): bool { return strpos(PHP_OS, 'WIN') === 0; } @@ -46,9 +46,9 @@ final class Checks * * @return bool */ - public static function checkPhpVersion() + public static function checkPhpVersion(): bool { - return version_compare(PHP_VERSION, '7.2', '>=') + return version_compare(PHP_VERSION, '7.3', '>=') && version_compare(PHP_VERSION, '7.4', '<='); } } diff --git a/lib/SP/Util/Connection.php b/lib/SP/Util/Connection.php index 86cbaec1..fdccfad7 100644 --- a/lib/SP/Util/Connection.php +++ b/lib/SP/Util/Connection.php @@ -62,9 +62,9 @@ final class Connection implements ConnectionInterface /** * @param $host string El host a conectar - * @param $port string El puerto a conectar + * @param $port int El puerto a conectar */ - public function __construct($host, $port) + public function __construct(string $host, int $port) { $this->host = gethostbyname($host); $this->port = $port; @@ -78,12 +78,9 @@ final class Connection implements ConnectionInterface * @return resource * @throws SPException */ - public function getSocket($type) + public function getSocket(int $type) { switch ($type) { - case self::TYPE_TCP: - $this->socket = $this->getTCPSocket(); - break; case self::TYPE_UDP: $this->socket = $this->getUDPSocket(); break; @@ -101,17 +98,6 @@ final class Connection implements ConnectionInterface return $this->socket; } - /** - * Obtener un socket del tipo TCP - * - * @return resource - */ - private function getTCPSocket() - { - return stream_socket_client('tcp://' . $this->host . ':' . $this->port, $this->errorno, $this->errorstr, self::SOCKET_TIMEOUT); -// return @socket_create(AF_INET, SOCK_STREAM, SOL_TCP); - } - /** * Obtener un socket del tipo UDP * @@ -123,12 +109,23 @@ final class Connection implements ConnectionInterface // return @socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); } + /** + * Obtener un socket del tipo TCP + * + * @return resource + */ + private function getTCPSocket() + { + return stream_socket_client('tcp://' . $this->host . ':' . $this->port, $this->errorno, $this->errorstr, self::SOCKET_TIMEOUT); +// return @socket_create(AF_INET, SOCK_STREAM, SOL_TCP); + } + /** * Obtener el último error del socket * * @return string */ - public function getSocketError() + public function getSocketError(): string { return sprintf('%s (%d)', $this->errorstr, $this->errorno); // return socket_strerror(socket_last_error($this->_socket)); @@ -151,7 +148,7 @@ final class Connection implements ConnectionInterface * @return int|bool * @throws SPException */ - public function send($message) + public function send(string $message) { if (!is_resource($this->socket)) { throw new SPException(__u('Socket not initialized'), SPException::WARNING); diff --git a/lib/SP/Util/ConnectionInterface.php b/lib/SP/Util/ConnectionInterface.php index 2f4f58f7..ae73de5e 100644 --- a/lib/SP/Util/ConnectionInterface.php +++ b/lib/SP/Util/ConnectionInterface.php @@ -42,7 +42,7 @@ interface ConnectionInterface * * @return resource */ - public function getSocket($type); + public function getSocket(int $type); /** * Cerrar un socket @@ -56,7 +56,7 @@ interface ConnectionInterface * * @return string */ - public function getSocketError(); + public function getSocketError(): string; /** * Enviar un mensaje al socket @@ -65,5 +65,5 @@ interface ConnectionInterface * * @return mixed */ - public function send($message); + public function send(string $message); } \ No newline at end of file diff --git a/lib/SP/Util/DateUtil.php b/lib/SP/Util/DateUtil.php index a2ac62b1..ba97dd91 100644 --- a/lib/SP/Util/DateUtil.php +++ b/lib/SP/Util/DateUtil.php @@ -34,12 +34,12 @@ final class DateUtil /** * Returns date string from UNIX timestamp * - * @param $date + * @param mixed $date * @param string $format * * @return false|string */ - public static function getDateFromUnix($date, $format = 'Y-m-d H:i') + public static function getDateFromUnix($date, string $format = 'Y-m-d H:i') { return is_numeric($date) ? date($format, $date) : $date; } diff --git a/lib/SP/Util/ErrorUtil.php b/lib/SP/Util/ErrorUtil.php index 8d8688ed..07225788 100644 --- a/lib/SP/Util/ErrorUtil.php +++ b/lib/SP/Util/ErrorUtil.php @@ -80,12 +80,17 @@ final class ErrorUtil /** * Establecer la plantilla de error con el código indicado. * - * @param Template $view - * @param int $type int con el tipo de error - * @param bool $render - * @param null $replace + * @param Template $view + * @param int $type int con el tipo de error + * @param bool $render + * @param string|null $replace */ - public static function showErrorInView(Template $view, $type, $render = true, $replace = null) + public static function showErrorInView( + Template $view, + int $type, + bool $render = true, + ?string $replace = null + ) { self::addErrorTemplate($view, $replace); @@ -118,14 +123,14 @@ final class ErrorUtil if ($replace === null) { $view->resetTemplates(); - if ($view->hashContentTemplates()) { + if ($view->hasContentTemplates()) { $view->resetContentTemplates(); $view->addContentTemplate('error', Template::PARTIALS_DIR); } else { $view->addTemplate('error', Template::PARTIALS_DIR); } } else { - if ($view->hashContentTemplates()) { + if ($view->hasContentTemplates()) { $view->removeContentTemplate($replace); $view->addContentTemplate('error', Template::PARTIALS_DIR); } else { @@ -142,7 +147,7 @@ final class ErrorUtil * * @return mixed */ - protected static function getErrorTypes($type) + protected static function getErrorTypes($type): array { $errorTypes = [ self::ERR_UNAVAILABLE => [ diff --git a/lib/SP/Util/FileUtil.php b/lib/SP/Util/FileUtil.php index 398753fe..d2162957 100644 --- a/lib/SP/Util/FileUtil.php +++ b/lib/SP/Util/FileUtil.php @@ -48,7 +48,7 @@ final class FileUtil * @throws FileNotFoundException * @see https://stackoverflow.com/a/7288067 */ - public static function rmdir_recursive($dir) + public static function rmdir_recursive($dir): bool { if (!is_dir($dir)) { throw new FileNotFoundException('Directory does not exist'); @@ -69,7 +69,7 @@ final class FileUtil * * @return bool */ - public static function isImage(FileData $fileData) + public static function isImage(FileData $fileData): bool { return in_array(strtolower($fileData->getType()), self::IMAGE_MIME, true); } diff --git a/lib/SP/Util/Filter.php b/lib/SP/Util/Filter.php index 17143bdb..1fae5c29 100644 --- a/lib/SP/Util/Filter.php +++ b/lib/SP/Util/Filter.php @@ -40,7 +40,7 @@ final class Filter * * @return mixed */ - public static function safeSearchString($string) + public static function safeSearchString(string $string) { return str_replace(['/', '[', '\\', ']', '%', '{', '}', '*', '$'], '', (string)$string); } @@ -50,7 +50,7 @@ final class Filter * * @return string */ - public static function getEmail($value): string + public static function getEmail(string $value): string { return filter_var(trim($value), FILTER_SANITIZE_EMAIL); } @@ -76,7 +76,7 @@ final class Filter } /** - * @param $value + * @param string|int $value * * @return int */ @@ -86,11 +86,11 @@ final class Filter } /** - * @param $value + * @param string|null $value * * @return string */ - public static function getString($value): string + public static function getString(?string $value): string { return filter_var(trim($value), FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES); } diff --git a/lib/SP/Util/ImageUtil.php b/lib/SP/Util/ImageUtil.php index 7dc4f715..9d5d2451 100644 --- a/lib/SP/Util/ImageUtil.php +++ b/lib/SP/Util/ImageUtil.php @@ -57,7 +57,7 @@ final class ImageUtil * @return bool|string * @throws InvalidImageException */ - public function createThumbnail($image) + public function createThumbnail(string $image) { $im = @imagecreatefromstring($image); @@ -97,7 +97,7 @@ final class ImageUtil * * @return bool|string */ - public function convertText($text) + public function convertText(string $text) { $width = strlen($text) * 10; diff --git a/lib/SP/Util/Link.php b/lib/SP/Util/Link.php index 033ba56d..0268e6fe 100644 --- a/lib/SP/Util/Link.php +++ b/lib/SP/Util/Link.php @@ -46,7 +46,12 @@ final class Link * * @return string */ - public static function getDeepLink(int $itemId, int $actionId, ConfigData $configData, bool $useUI = false) + public static function getDeepLink( + int $itemId, + int $actionId, + ConfigData $configData, + bool $useUI = false + ): string { $route = Acl::getActionRoute($actionId) . '/' . $itemId; diff --git a/lib/SP/Util/PasswordUtil.php b/lib/SP/Util/PasswordUtil.php index df15748a..2ec41041 100644 --- a/lib/SP/Util/PasswordUtil.php +++ b/lib/SP/Util/PasswordUtil.php @@ -46,12 +46,12 @@ final class PasswordUtil /** * Generate a ramdom password * - * @param int $length Password length - * @param int $flags Password chars included and checking strength flags + * @param int $length Password length + * @param int|null $flags Password chars included and checking strength flags * * @return string */ - public static function randomPassword($length = 16, int $flags = null) + public static function randomPassword(int $length = 16, int $flags = null): string { if ($flags === null) { $flags = self::FLAG_PASSWORD_SPECIAL | self::FLAG_PASSWORD_NUMBER | self::FLAG_PASSWORD_STRENGTH; @@ -112,7 +112,7 @@ final class PasswordUtil * * @return array */ - public static function checkStrength(array $pass) + public static function checkStrength(array $pass): array { $charsUpper = strtoupper(self::CHARS); $strength = ['lower' => 0, 'upper' => 0, 'special' => 0, 'number' => 0]; @@ -135,7 +135,7 @@ final class PasswordUtil * @return string * @throws EnvironmentIsBrokenException */ - public static function generateRandomBytes($length = 30) + public static function generateRandomBytes(int $length = 30): string { return Encoding::binToHex(Core::secureRandom($length)); } diff --git a/lib/SP/Util/Util.php b/lib/SP/Util/Util.php index 0a8525c1..a9e9fad6 100644 --- a/lib/SP/Util/Util.php +++ b/lib/SP/Util/Util.php @@ -147,11 +147,11 @@ final class Util * * @param string $dstClass Destination class name * @param string|object $serialized - * @param string $srcClass Old class name for removing from private methods + * @param string|null $srcClass Old class name for removing from private methods * * @return mixed */ - public static function unserialize($dstClass, $serialized, $srcClass = null) + public static function unserialize(string $dstClass, $serialized, ?string $srcClass = null) { if (!is_object($serialized)) { $match = preg_match_all('/O:\d+:"(?P[^"]++)"/', $serialized, $matches); @@ -220,7 +220,7 @@ final class Util * * @throws FileException */ - public static function lockApp($userId, $subject) + public static function lockApp($userId, string $subject) { $data = ['time' => time(), 'userId' => (int)$userId, 'subject' => $subject]; @@ -235,7 +235,7 @@ final class Util * * @return bool */ - public static function unlockApp() + public static function unlockApp(): bool { logger('Application unlocked'); @@ -245,12 +245,13 @@ final class Util /** * Comprueba si la aplicación está bloqueada * - * @return mixed + * @return bool|string */ public static function getAppLock() { try { $file = new FileHandler(LOCK_FILE); + return json_decode($file->readToString()); } catch (FileException $e) { return false; @@ -266,7 +267,7 @@ final class Util * * @return array Con el tiempo estimado y los elementos por segundo */ - public static function getETA($startTime, $numItems, $totalItems) + public static function getETA($startTime, $numItems, $totalItems): array { if ($numItems > 0 && $totalItems > 0) { $runtime = time() - $startTime; @@ -286,7 +287,7 @@ final class Util * * @return array */ - public static function itemsIdAdapter(string $itemsId, $delimiter = ','): array + public static function itemsIdAdapter(string $itemsId, string $delimiter = ','): array { return array_map(function ($value) { return intval($value); diff --git a/lib/SP/Util/VersionUtil.php b/lib/SP/Util/VersionUtil.php index cbb0eaf4..0271034b 100644 --- a/lib/SP/Util/VersionUtil.php +++ b/lib/SP/Util/VersionUtil.php @@ -38,7 +38,7 @@ final class VersionUtil * * @return string */ - public static function getVersionStringNormalized() + public static function getVersionStringNormalized(): string { return implode('', Installer::VERSION) . '.' . Installer::BUILD; } @@ -51,7 +51,7 @@ final class VersionUtil * * @return bool True if $currentVersion is lower than $upgradeableVersion */ - public static function checkVersion($currentVersion, $upgradeableVersion) + public static function checkVersion(string $currentVersion, $upgradeableVersion): bool { if (is_array($upgradeableVersion)) { $upgradeableVersion = array_pop($upgradeableVersion); @@ -84,7 +84,7 @@ final class VersionUtil * * @return string */ - public static function normalizeVersionForCompare($versionIn) + public static function normalizeVersionForCompare($versionIn): string { if (!empty($versionIn)) { if (is_string($versionIn)) { @@ -131,7 +131,7 @@ final class VersionUtil * * @return array con el número de versión */ - public static function getVersionArray($retBuild = false) + public static function getVersionArray($retBuild = false): array { $version = array_values(Installer::VERSION); @@ -149,7 +149,7 @@ final class VersionUtil * * @return array */ - public static function getVersionArrayNormalized() + public static function getVersionArrayNormalized(): array { return [implode('', Installer::VERSION), Installer::BUILD]; } diff --git a/tests/SP/Repositories/NotificationRepositoryTest.php b/tests/SP/Repositories/NotificationRepositoryTest.php index 4dac0033..32fa33b3 100644 --- a/tests/SP/Repositories/NotificationRepositoryTest.php +++ b/tests/SP/Repositories/NotificationRepositoryTest.php @@ -189,13 +189,6 @@ class NotificationRepositoryTest extends DatabaseTestCase $this->assertEquals(2, $data[0]->getId()); $this->assertEquals('Global', $data[0]->getType()); - $itemSearchData->setSeachString(''); - - $result = self::$repository->search($itemSearchData); - - $this->assertEquals(3, $result->getNumRows()); - $this->assertCount(3, $result->getDataAsArray()); - $itemSearchData->setSeachString('Accounts'); $result = self::$repository->search($itemSearchData); @@ -210,6 +203,13 @@ class NotificationRepositoryTest extends DatabaseTestCase $this->assertEquals('Accounts', $data[1]->getComponent()); $this->assertEquals(1529145158, $data[2]->getDate()); $this->assertEquals('Accounts', $data[2]->getComponent()); + + $itemSearchData->setSeachString(null); + + $result = self::$repository->search($itemSearchData); + + $this->assertEquals(3, $result->getNumRows()); + $this->assertCount(3, $result->getDataAsArray()); } /** diff --git a/tests/res/config/config.xml b/tests/res/config/config.xml index 4ae8b484..b3693d96 100644 --- a/tests/res/config/config.xml +++ b/tests/res/config/config.xml @@ -13,8 +13,8 @@ 1 - 1607515367 - db50628d8b3b8881576df1c12e328566232f71db + 1608465113 + 6075dd007ba509336b4861de65598f8a6247a1ab Admin @@ -33,7 +33,7 @@ - dfc07f6c7ca205ffcc8982585a430dd3ca83b494 + dd2e9ad4d908b2d3ae913298530ae7030ca09a4b 1024 1 diff --git a/tests/res/scripts/reset_db.sh b/tests/res/scripts/reset_db.sh index 12b5db22..830fb346 100755 --- a/tests/res/scripts/reset_db.sh +++ b/tests/res/scripts/reset_db.sh @@ -36,6 +36,13 @@ do_import() { fi } +restart_db_container() { + echo "Restarting DB container ..." + + docker restart ${DB_CONTAINER_NAME} + sleep 15 +} + get_db_host() { DB_HOST=$(docker inspect ${DB_CONTAINER_NAME} --format {{.NetworkSettings.Networks.bridge.IPAddress}}) @@ -94,6 +101,8 @@ while getopts ":hs:d:p:C:" OPTIONS; do echo "Database container name: ${DB_CONTAINER_NAME}" + # Avoid memory leaks + restart_db_container get_db_host ;; :)