Added more type-hints

This commit is contained in:
Roland Häder 2022-06-23 10:56:37 +02:00
parent 3f74a59f73
commit c6c936a80f
Signed by: roland
GPG Key ID: C82EDE5DDFA0BA77
7 changed files with 46 additions and 53 deletions

View File

@ -36,7 +36,6 @@ class OpenWebAuthToken
* @param int $uid The user ID. * @param int $uid The user ID.
* @param string $token * @param string $token
* @param string $meta * @param string $meta
*
* @return boolean * @return boolean
* @throws \Exception * @throws \Exception
*/ */
@ -80,6 +79,7 @@ class OpenWebAuthToken
* *
* @param string $type Verify type. * @param string $type Verify type.
* @param string $interval SQL compatible time interval * @param string $interval SQL compatible time interval
* @return void
* @throws \Exception * @throws \Exception
*/ */
public static function purge(string $type, string $interval) public static function purge(string $type, string $interval)

View File

@ -162,7 +162,6 @@ class Profile
* Returns a formatted location string from the given profile array * Returns a formatted location string from the given profile array
* *
* @param array $profile Profile array (Generated from the "profile" table) * @param array $profile Profile array (Generated from the "profile" table)
*
* @return string Location string * @return string Location string
*/ */
public static function formatLocation(array $profile): string public static function formatLocation(array $profile): string

View File

@ -34,13 +34,12 @@ class Register
/** /**
* Return the list of pending registrations * Return the list of pending registrations
* *
* @param int $start Start count (Default is 0) * @param int $start Start count (Default is 0)
* @param int $count Count of the items per page (Default is @see Pager::ITEMS_PER_PAGE) * @param int $count Count of the items per page (Default is @see Pager::ITEMS_PER_PAGE)
* * @return array|bool Array on succes, false on failure
* @return array
* @throws \Exception * @throws \Exception
*/ */
public static function getPending($start = 0, $count = Pager::ITEMS_PER_PAGE) public static function getPending(int $start = 0, int $count = Pager::ITEMS_PER_PAGE)
{ {
return DBA::selectToArray('pending-view', [], [], ['limit' => [$start, $count]]); return DBA::selectToArray('pending-view', [], [], ['limit' => [$start, $count]]);
} }
@ -50,8 +49,7 @@ class Register
* *
* @param int $uid The user id * @param int $uid The user id
* *
* @return array The pending user information * @return array|bool Array on succes, false on failure
*
* @throws \Exception * @throws \Exception
*/ */
public static function getPendingForUser(int $uid) public static function getPendingForUser(int $uid)
@ -65,7 +63,7 @@ class Register
* @return int * @return int
* @throws \Exception * @throws \Exception
*/ */
public static function getPendingCount() public static function getPendingCount(): int
{ {
return DBA::count('pending-view', ['self' => true]); return DBA::count('pending-view', ['self' => true]);
} }
@ -74,10 +72,10 @@ class Register
* Returns the register record associated with the provided hash * Returns the register record associated with the provided hash
* *
* @param string $hash * @param string $hash
* @return array * @return array|bool Array on succes, false on failure
* @throws \Exception * @throws \Exception
*/ */
public static function getByHash($hash) public static function getByHash(string $hash)
{ {
return DBA::selectFirst('register', [], ['hash' => $hash]); return DBA::selectFirst('register', [], ['hash' => $hash]);
} }
@ -89,7 +87,7 @@ class Register
* @return boolean * @return boolean
* @throws \Exception * @throws \Exception
*/ */
public static function existsByHash($hash) public static function existsByHash(string $hash): bool
{ {
return DBA::exists('register', ['hash' => $hash]); return DBA::exists('register', ['hash' => $hash]);
} }
@ -100,7 +98,7 @@ class Register
* @return string * @return string
* @throws \Exception * @throws \Exception
*/ */
public static function createForInvitation() public static function createForInvitation(): string
{ {
$code = Strings::getRandomName(8) . random_int(1000, 9999); $code = Strings::getRandomName(8) . random_int(1000, 9999);
@ -124,7 +122,7 @@ class Register
* @return boolean * @return boolean
* @throws \Exception * @throws \Exception
*/ */
public static function createForApproval($uid, $language, $note = '') public static function createForApproval(int $uid, string $language, string $note = ''): bool
{ {
$hash = Strings::getRandomHex(); $hash = Strings::getRandomHex();
@ -151,7 +149,7 @@ class Register
* @return boolean * @return boolean
* @throws \Exception * @throws \Exception
*/ */
public static function deleteByHash($hash) public static function deleteByHash(string $hash): bool
{ {
return DBA::delete('register', ['hash' => $hash]); return DBA::delete('register', ['hash' => $hash]);
} }

View File

@ -32,10 +32,9 @@ class Search
* Returns the list of user defined tags (e.g. #Friendica) * Returns the list of user defined tags (e.g. #Friendica)
* *
* @return array * @return array
*
* @throws \Exception * @throws \Exception
*/ */
public static function getUserTags() public static function getUserTags(): array
{ {
$termsStmt = DBA::p("SELECT DISTINCT(`term`) FROM `search`"); $termsStmt = DBA::p("SELECT DISTINCT(`term`) FROM `search`");

View File

@ -37,8 +37,7 @@ class Subscription
* @param int $applicationid * @param int $applicationid
* @param int $uid * @param int $uid
* @param array $fields * @param array $fields
* * @return array|bool Array on success, false on failure
* @return bool Does it exist?
*/ */
public static function select(int $applicationid, int $uid, array $fields = []) public static function select(int $applicationid, int $uid, array $fields = [])
{ {
@ -53,7 +52,7 @@ class Subscription
* *
* @return bool Does it exist? * @return bool Does it exist?
*/ */
public static function exists(int $applicationid, int $uid) public static function exists(int $applicationid, int $uid): bool
{ {
return DBA::exists('subscription', ['application-id' => $applicationid, 'uid' => $uid]); return DBA::exists('subscription', ['application-id' => $applicationid, 'uid' => $uid]);
} }
@ -64,10 +63,9 @@ class Subscription
* @param int $applicationid * @param int $applicationid
* @param int $uid * @param int $uid
* @param array $fields subscription fields * @param array $fields subscription fields
*
* @return bool result of update * @return bool result of update
*/ */
public static function update(int $applicationid, int $uid, array $fields) public static function update(int $applicationid, int $uid, array $fields): bool
{ {
return DBA::update('subscription', $fields, ['application-id' => $applicationid, 'uid' => $uid]); return DBA::update('subscription', $fields, ['application-id' => $applicationid, 'uid' => $uid]);
} }
@ -76,10 +74,9 @@ class Subscription
* Insert or replace a subscription record * Insert or replace a subscription record
* *
* @param array $fields subscription fields * @param array $fields subscription fields
*
* @return bool result of replace * @return bool result of replace
*/ */
public static function replace(array $fields) public static function replace(array $fields): bool
{ {
return DBA::replace('subscription', $fields); return DBA::replace('subscription', $fields);
} }
@ -91,7 +88,7 @@ class Subscription
* @param int $uid * @param int $uid
* @return bool * @return bool
*/ */
public static function delete(int $applicationid, int $uid) public static function delete(int $applicationid, int $uid): bool
{ {
return DBA::delete('subscription', ['application-id' => $applicationid, 'uid' => $uid]); return DBA::delete('subscription', ['application-id' => $applicationid, 'uid' => $uid]);
} }
@ -136,25 +133,25 @@ class Subscription
/** /**
* Prepare push notification * Prepare push notification
* *
* @param int $nid * @param Notification $Notification Notification instance
* @return void * @return void
*/ */
public static function pushByNotification(Entity\Notification $Notification) public static function pushByNotification(Entity\Notification $notification)
{ {
$type = \Friendica\Factory\Api\Mastodon\Notification::getType($Notification); $type = \Friendica\Factory\Api\Mastodon\Notification::getType($notification);
if (DI::notify()->NotifyOnDesktop($Notification, $type)) { if (DI::notify()->NotifyOnDesktop($notification, $type)) {
DI::notify()->createFromNotification($Notification); DI::notify()->createFromNotification($notification);
} }
if (empty($type)) { if (empty($type)) {
return; return;
} }
$subscriptions = DBA::select('subscription', [], ['uid' => $Notification->uid, $type => true]); $subscriptions = DBA::select('subscription', [], ['uid' => $notification->uid, $type => true]);
while ($subscription = DBA::fetch($subscriptions)) { while ($subscription = DBA::fetch($subscriptions)) {
Logger::info('Push notification', ['id' => $subscription['id'], 'uid' => $subscription['uid'], 'type' => $type]); Logger::info('Push notification', ['id' => $subscription['id'], 'uid' => $subscription['uid'], 'type' => $type]);
Worker::add(PRIORITY_HIGH, 'PushSubscription', $subscription['id'], $Notification->id); Worker::add(PRIORITY_HIGH, 'PushSubscription', $subscription['id'], $notification->id);
} }
DBA::close($subscriptions); DBA::close($subscriptions);
} }

View File

@ -117,16 +117,18 @@ class User
switch ($accounttype) { switch ($accounttype) {
case 'person': case 'person':
return User::ACCOUNT_TYPE_PERSON; return User::ACCOUNT_TYPE_PERSON;
case 'organisation': case 'organisation':
return User::ACCOUNT_TYPE_ORGANISATION; return User::ACCOUNT_TYPE_ORGANISATION;
case 'news': case 'news':
return User::ACCOUNT_TYPE_NEWS; return User::ACCOUNT_TYPE_NEWS;
case 'community': case 'community':
return User::ACCOUNT_TYPE_COMMUNITY; return User::ACCOUNT_TYPE_COMMUNITY;
default:
return null;
break;
} }
return null;
} }
/** /**
@ -362,14 +364,12 @@ class User
/** /**
* Get a user based on its email * Get a user based on its email
* *
* @param string $email * @param string $email
* @param array $fields * @param array $fields
*
* @return array|boolean User record if it exists, false otherwise * @return array|boolean User record if it exists, false otherwise
*
* @throws Exception * @throws Exception
*/ */
public static function getByEmail($email, array $fields = []) public static function getByEmail(string $email, array $fields = [])
{ {
return DBA::selectFirst('user', $fields, ['email' => $email]); return DBA::selectFirst('user', $fields, ['email' => $email]);
} }
@ -512,7 +512,7 @@ class User
* @throws HTTPException\ForbiddenException * @throws HTTPException\ForbiddenException
* @throws HTTPException\NotFoundException * @throws HTTPException\NotFoundException
*/ */
public static function getIdFromPasswordAuthentication($user_info, string $password, bool $third_party = false) public static function getIdFromPasswordAuthentication($user_info, string $password, bool $third_party = false): int
{ {
// Addons registered with the "authenticate" hook may create the user on the // Addons registered with the "authenticate" hook may create the user on the
// fly. `getAuthenticationInfo` will fail if the user doesn't exist yet. If // fly. `getAuthenticationInfo` will fail if the user doesn't exist yet. If
@ -1164,32 +1164,32 @@ class User
$type = Images::getMimeTypeByData($img_str, $photo, $type); $type = Images::getMimeTypeByData($img_str, $photo, $type);
$Image = new Image($img_str, $type); $image = new Image($img_str, $type);
if ($Image->isValid()) { if ($image->isValid()) {
$Image->scaleToSquare(300); $image->scaleToSquare(300);
$resource_id = Photo::newResource(); $resource_id = Photo::newResource();
// Not using Photo::PROFILE_PHOTOS here, so that it is discovered as translateble string // Not using Photo::PROFILE_PHOTOS here, so that it is discovered as translateble string
$profile_album = DI::l10n()->t('Profile Photos'); $profile_album = DI::l10n()->t('Profile Photos');
$r = Photo::store($Image, $uid, 0, $resource_id, $filename, $profile_album, 4); $r = Photo::store($image, $uid, 0, $resource_id, $filename, $profile_album, 4);
if ($r === false) { if ($r === false) {
$photo_failure = true; $photo_failure = true;
} }
$Image->scaleDown(80); $image->scaleDown(80);
$r = Photo::store($Image, $uid, 0, $resource_id, $filename, $profile_album, 5); $r = Photo::store($image, $uid, 0, $resource_id, $filename, $profile_album, 5);
if ($r === false) { if ($r === false) {
$photo_failure = true; $photo_failure = true;
} }
$Image->scaleDown(48); $image->scaleDown(48);
$r = Photo::store($Image, $uid, 0, $resource_id, $filename, $profile_album, 6); $r = Photo::store($image, $uid, 0, $resource_id, $filename, $profile_album, 6);
if ($r === false) { if ($r === false) {
$photo_failure = true; $photo_failure = true;
@ -1342,7 +1342,6 @@ class User
* @param string $email The user's email address * @param string $email The user's email address
* @param string $nick The user's nick name * @param string $nick The user's nick name
* @param string $lang The user's language (default is english) * @param string $lang The user's language (default is english)
*
* @return bool True, if the user was created successfully * @return bool True, if the user was created successfully
* @throws HTTPException\InternalServerErrorException * @throws HTTPException\InternalServerErrorException
* @throws ErrorException * @throws ErrorException
@ -1731,7 +1730,6 @@ class User
* @param string $type The type of users, which should get (all, bocked, removed) * @param string $type The type of users, which should get (all, bocked, removed)
* @param string $order Order of the user list (Default is 'contact.name') * @param string $order Order of the user list (Default is 'contact.name')
* @param bool $descending Order direction (Default is ascending) * @param bool $descending Order direction (Default is ascending)
*
* @return array|bool The list of the users * @return array|bool The list of the users
* @throws Exception * @throws Exception
*/ */
@ -1744,11 +1742,13 @@ class User
$condition['account_removed'] = false; $condition['account_removed'] = false;
$condition['blocked'] = false; $condition['blocked'] = false;
break; break;
case 'blocked': case 'blocked':
$condition['account_removed'] = false; $condition['account_removed'] = false;
$condition['blocked'] = true; $condition['blocked'] = true;
$condition['verified'] = true; $condition['verified'] = true;
break; break;
case 'removed': case 'removed':
$condition['account_removed'] = true; $condition['account_removed'] = true;
break; break;

View File

@ -34,7 +34,7 @@ class Verb
* @return integer verb id * @return integer verb id
* @throws \Exception * @throws \Exception
*/ */
public static function getID(string $verb) public static function getID(string $verb): int
{ {
if (empty($verb)) { if (empty($verb)) {
return 0; return 0;
@ -56,7 +56,7 @@ class Verb
* @param integer $id * @param integer $id
* @return string verb * @return string verb
*/ */
public static function getByID(int $id) public static function getByID(int $id): string
{ {
if (empty($id)) { if (empty($id)) {
return ''; return '';