diff --git a/src/BaseCollection.php b/src/BaseCollection.php index 0bf46f0dcb..f6fa9bbd4d 100644 --- a/src/BaseCollection.php +++ b/src/BaseCollection.php @@ -70,9 +70,11 @@ class BaseCollection extends \ArrayIterator } /** - * @return int + * Getter for total count + * + * @return int Total count */ - public function getTotalCount() + public function getTotalCount(): int { return $this->totalCount; } @@ -85,7 +87,7 @@ class BaseCollection extends \ArrayIterator * @return array * @see array_column() */ - public function column($column, $index_key = null) + public function column(string $column, $index_key = null): array { return array_column($this->getArrayCopy(true), $column, $index_key); } @@ -97,7 +99,7 @@ class BaseCollection extends \ArrayIterator * @return BaseCollection * @see array_map() */ - public function map(callable $callback) + public function map(callable $callback): BaseCollection { return new static(array_map($callback, $this->getArrayCopy()), $this->getTotalCount()); } @@ -110,7 +112,7 @@ class BaseCollection extends \ArrayIterator * @return BaseCollection * @see array_filter() */ - public function filter(callable $callback = null, int $flag = 0) + public function filter(callable $callback = null, int $flag = 0): BaseCollection { return new static(array_filter($this->getArrayCopy(), $callback, $flag)); } diff --git a/src/BaseEntity.php b/src/BaseEntity.php index 8e8938febc..065d100fa3 100644 --- a/src/BaseEntity.php +++ b/src/BaseEntity.php @@ -55,14 +55,14 @@ abstract class BaseEntity extends BaseDataTransferObject } /** - * @param $name + * @param mixed $name * @return bool * @throws HTTPException\InternalServerErrorException */ - public function __isset($name) + public function __isset($name): bool { if (!property_exists($this, $name)) { - throw new HTTPException\InternalServerErrorException('Unknown property ' . $name . ' in Entity ' . static::class); + throw new HTTPException\InternalServerErrorException('Unknown property ' . $name . ' of type ' . gettype($name) . ' in Entity ' . static::class); } return !empty($this->$name); diff --git a/src/BaseModel.php b/src/BaseModel.php index 768e9e9e53..06a61c505a 100644 --- a/src/BaseModel.php +++ b/src/BaseModel.php @@ -110,11 +110,11 @@ abstract class BaseModel extends BaseDataTransferObject * - $model->field (outside of class) * - $this->field (inside of class) * - * @param $name + * @param string $name Name of data to fetch * @return mixed * @throws HTTPException\InternalServerErrorException */ - public function __get($name) + public function __get(string $name) { $this->checkValid(); diff --git a/src/BaseModule.php b/src/BaseModule.php index c03a77e29e..f70662a62f 100644 --- a/src/BaseModule.php +++ b/src/BaseModule.php @@ -331,7 +331,7 @@ abstract class BaseModule implements ICanHandleRequests * Actually, important actions should not be triggered by Links / GET-Requests at all, but sometimes they still are, * so this mechanism brings in some damage control (the attacker would be able to forge a request to a form of this type, but not to forms of other types). */ - public static function getFormSecurityToken($typename = '') + public static function getFormSecurityToken(string $typename = '') { $user = User::getById(DI::app()->getLoggedInUserId(), ['guid', 'prvkey']); $timestamp = time(); @@ -340,7 +340,14 @@ abstract class BaseModule implements ICanHandleRequests return $timestamp . '.' . $sec_hash; } - public static function checkFormSecurityToken($typename = '', $formname = 'form_security_token') + /** + * Checks if form's security (CSRF) token is valid. + * + * @param string $typename ??? + * @param string $formname Name of form/field (???) + * @return bool Whether it is valid + */ + public static function checkFormSecurityToken(string $typename = '', string $formname = 'form_security_token'): bool { $hash = null; @@ -372,12 +379,12 @@ abstract class BaseModule implements ICanHandleRequests return ($sec_hash == $x[1]); } - public static function getFormSecurityStandardErrorMessage() + public static function getFormSecurityStandardErrorMessage(): string { return DI::l10n()->t("The form security token was not correct. This probably happened because the form has been opened for too long \x28>3 hours\x29 before submitting it.") . EOL; } - public static function checkFormSecurityTokenRedirectOnError($err_redirect, $typename = '', $formname = 'form_security_token') + public static function checkFormSecurityTokenRedirectOnError(string $err_redirect, string $typename = '', string $formname = 'form_security_token') { if (!self::checkFormSecurityToken($typename, $formname)) { Logger::notice('checkFormSecurityToken failed: user ' . DI::app()->getLoggedInUserNickname() . ' - form element ' . $typename); @@ -387,7 +394,7 @@ abstract class BaseModule implements ICanHandleRequests } } - public static function checkFormSecurityTokenForbiddenOnError($typename = '', $formname = 'form_security_token') + public static function checkFormSecurityTokenForbiddenOnError(string $typename = '', string $formname = 'form_security_token') { if (!self::checkFormSecurityToken($typename, $formname)) { Logger::notice('checkFormSecurityToken failed: user ' . DI::app()->getLoggedInUserNickname() . ' - form element ' . $typename); diff --git a/src/LegacyModule.php b/src/LegacyModule.php index 22d393ef9e..7d9cf20283 100644 --- a/src/LegacyModule.php +++ b/src/LegacyModule.php @@ -57,7 +57,7 @@ class LegacyModule extends BaseModule * @param string $file_path * @throws \Exception */ - private function setModuleFile($file_path) + private function setModuleFile(string $file_path) { if (!is_readable($file_path)) { throw new \Exception(DI::l10n()->t('Legacy module file not found: %s', $file_path)); @@ -87,7 +87,7 @@ class LegacyModule extends BaseModule * @return string * @throws \Exception */ - private function runModuleFunction(string $function_suffix) + private function runModuleFunction(string $function_suffix): string { $function_name = $this->moduleName . '_' . $function_suffix;