mirror of
https://github.com/friendica/friendica
synced 2024-12-23 10:40:16 +00:00
Changes:
- added missing type-hints - added missing documentation
This commit is contained in:
parent
e90ad0c1cd
commit
7ec07178c8
3 changed files with 44 additions and 34 deletions
|
@ -39,7 +39,7 @@ class Post
|
||||||
* @return int ID of inserted post
|
* @return int ID of inserted post
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function insert(int $uri_id, array $data = [])
|
public static function insert(int $uri_id, array $data = []): int
|
||||||
{
|
{
|
||||||
if (empty($uri_id)) {
|
if (empty($uri_id)) {
|
||||||
throw new BadMethodCallException('Empty URI_id');
|
throw new BadMethodCallException('Empty URI_id');
|
||||||
|
@ -107,8 +107,10 @@ class Post
|
||||||
* @param object $stmt statement object
|
* @param object $stmt statement object
|
||||||
* @param bool $do_close
|
* @param bool $do_close
|
||||||
* @return array Data array
|
* @return array Data array
|
||||||
|
* @todo Find proper type-hint for $stmt and maybe avoid boolean
|
||||||
*/
|
*/
|
||||||
public static function toArray($stmt, $do_close = true) {
|
public static function toArray($stmt, bool $do_close = true)
|
||||||
|
{
|
||||||
if (is_bool($stmt)) {
|
if (is_bool($stmt)) {
|
||||||
return $stmt;
|
return $stmt;
|
||||||
}
|
}
|
||||||
|
@ -131,7 +133,8 @@ class Post
|
||||||
* @return boolean Are there rows for that condition?
|
* @return boolean Are there rows for that condition?
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function exists($condition) {
|
public static function exists(array $condition): bool
|
||||||
|
{
|
||||||
return DBA::exists('post-user-view', $condition);
|
return DBA::exists('post-user-view', $condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +154,7 @@ class Post
|
||||||
* $count = Post::count($condition);
|
* $count = Post::count($condition);
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function count(array $condition = [], array $params = [])
|
public static function count(array $condition = [], array $params = []): int
|
||||||
{
|
{
|
||||||
return DBA::count('post-user-view', $condition, $params);
|
return DBA::count('post-user-view', $condition, $params);
|
||||||
}
|
}
|
||||||
|
@ -172,7 +175,7 @@ class Post
|
||||||
* $count = Post::count($condition);
|
* $count = Post::count($condition);
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function countThread(array $condition = [], array $params = [])
|
public static function countThread(array $condition = [], array $params = []): int
|
||||||
{
|
{
|
||||||
return DBA::count('post-thread-user-view', $condition, $params);
|
return DBA::count('post-thread-user-view', $condition, $params);
|
||||||
}
|
}
|
||||||
|
@ -193,7 +196,7 @@ class Post
|
||||||
* $count = Post::count($condition);
|
* $count = Post::count($condition);
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function countPosts(array $condition = [], array $params = [])
|
public static function countPosts(array $condition = [], array $params = []): int
|
||||||
{
|
{
|
||||||
return DBA::count('post-view', $condition, $params);
|
return DBA::count('post-view', $condition, $params);
|
||||||
}
|
}
|
||||||
|
@ -209,7 +212,7 @@ class Post
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
* @see DBA::select
|
* @see DBA::select
|
||||||
*/
|
*/
|
||||||
public static function selectFirst(array $fields = [], array $condition = [], $params = [])
|
public static function selectFirst(array $fields = [], array $condition = [], array $params = [])
|
||||||
{
|
{
|
||||||
$params['limit'] = 1;
|
$params['limit'] = 1;
|
||||||
|
|
||||||
|
@ -234,7 +237,7 @@ class Post
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
* @see DBA::select
|
* @see DBA::select
|
||||||
*/
|
*/
|
||||||
public static function selectFirstPost(array $fields = [], array $condition = [], $params = [])
|
public static function selectFirstPost(array $fields = [], array $condition = [], array $params = [])
|
||||||
{
|
{
|
||||||
$params['limit'] = 1;
|
$params['limit'] = 1;
|
||||||
|
|
||||||
|
@ -259,7 +262,7 @@ class Post
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
* @see DBA::select
|
* @see DBA::select
|
||||||
*/
|
*/
|
||||||
public static function selectFirstThread(array $fields = [], array $condition = [], $params = [])
|
public static function selectFirstThread(array $fields = [], array $condition = [], array $params = [])
|
||||||
{
|
{
|
||||||
$params['limit'] = 1;
|
$params['limit'] = 1;
|
||||||
|
|
||||||
|
@ -284,7 +287,7 @@ class Post
|
||||||
* @return array
|
* @return array
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function selectToArray(array $fields = [], array $condition = [], $params = [])
|
public static function selectToArray(array $fields = [], array $condition = [], array $params = [])
|
||||||
{
|
{
|
||||||
$result = self::select($fields, $condition, $params);
|
$result = self::select($fields, $condition, $params);
|
||||||
|
|
||||||
|
@ -312,7 +315,7 @@ class Post
|
||||||
* @return boolean|object
|
* @return boolean|object
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
private static function selectView(string $view, array $selected = [], array $condition = [], $params = [])
|
private static function selectView(string $view, array $selected = [], array $condition = [], array $params = [])
|
||||||
{
|
{
|
||||||
if (empty($selected)) {
|
if (empty($selected)) {
|
||||||
$selected = array_merge(Item::DISPLAY_FIELDLIST, Item::ITEM_FIELDLIST);
|
$selected = array_merge(Item::DISPLAY_FIELDLIST, Item::ITEM_FIELDLIST);
|
||||||
|
@ -337,7 +340,7 @@ class Post
|
||||||
* @return boolean|object
|
* @return boolean|object
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function select(array $selected = [], array $condition = [], $params = [])
|
public static function select(array $selected = [], array $condition = [], array $params = [])
|
||||||
{
|
{
|
||||||
return self::selectView('post-user-view', $selected, $condition, $params);
|
return self::selectView('post-user-view', $selected, $condition, $params);
|
||||||
}
|
}
|
||||||
|
@ -352,7 +355,7 @@ class Post
|
||||||
* @return boolean|object
|
* @return boolean|object
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function selectPosts(array $selected = [], array $condition = [], $params = [])
|
public static function selectPosts(array $selected = [], array $condition = [], array $params = [])
|
||||||
{
|
{
|
||||||
return self::selectView('post-view', $selected, $condition, $params);
|
return self::selectView('post-view', $selected, $condition, $params);
|
||||||
}
|
}
|
||||||
|
@ -367,7 +370,7 @@ class Post
|
||||||
* @return boolean|object
|
* @return boolean|object
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function selectThread(array $selected = [], array $condition = [], $params = [])
|
public static function selectThread(array $selected = [], array $condition = [], array $params = [])
|
||||||
{
|
{
|
||||||
return self::selectView('post-thread-user-view', $selected, $condition, $params);
|
return self::selectView('post-thread-user-view', $selected, $condition, $params);
|
||||||
}
|
}
|
||||||
|
@ -384,7 +387,7 @@ class Post
|
||||||
* @return boolean|object
|
* @return boolean|object
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
private static function selectViewForUser(string $view, $uid, array $selected = [], array $condition = [], $params = [])
|
private static function selectViewForUser(string $view, int $uid, array $selected = [], array $condition = [], array $params = [])
|
||||||
{
|
{
|
||||||
if (empty($selected)) {
|
if (empty($selected)) {
|
||||||
$selected = Item::DISPLAY_FIELDLIST;
|
$selected = Item::DISPLAY_FIELDLIST;
|
||||||
|
@ -425,7 +428,7 @@ class Post
|
||||||
* @return boolean|object
|
* @return boolean|object
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function selectForUser($uid, array $selected = [], array $condition = [], $params = [])
|
public static function selectForUser(int $uid, array $selected = [], array $condition = [], array $params = [])
|
||||||
{
|
{
|
||||||
return self::selectViewForUser('post-user-view', $uid, $selected, $condition, $params);
|
return self::selectViewForUser('post-user-view', $uid, $selected, $condition, $params);
|
||||||
}
|
}
|
||||||
|
@ -441,7 +444,7 @@ class Post
|
||||||
* @return boolean|object
|
* @return boolean|object
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function selectPostsForUser($uid, array $selected = [], array $condition = [], $params = [])
|
public static function selectPostsForUser(int $uid, array $selected = [], array $condition = [], array $params = [])
|
||||||
{
|
{
|
||||||
return self::selectViewForUser('post-view', $uid, $selected, $condition, $params);
|
return self::selectViewForUser('post-view', $uid, $selected, $condition, $params);
|
||||||
}
|
}
|
||||||
|
@ -457,7 +460,7 @@ class Post
|
||||||
* @return boolean|object
|
* @return boolean|object
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function selectThreadForUser($uid, array $selected = [], array $condition = [], $params = [])
|
public static function selectThreadForUser(int $uid, array $selected = [], array $condition = [], array $params = [])
|
||||||
{
|
{
|
||||||
return self::selectViewForUser('post-thread-user-view', $uid, $selected, $condition, $params);
|
return self::selectViewForUser('post-thread-user-view', $uid, $selected, $condition, $params);
|
||||||
}
|
}
|
||||||
|
@ -473,7 +476,7 @@ class Post
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
* @see DBA::select
|
* @see DBA::select
|
||||||
*/
|
*/
|
||||||
public static function selectFirstForUser($uid, array $selected = [], array $condition = [], $params = [])
|
public static function selectFirstForUser(int $uid, array $selected = [], array $condition = [], array $params = [])
|
||||||
{
|
{
|
||||||
$params['limit'] = 1;
|
$params['limit'] = 1;
|
||||||
|
|
||||||
|
@ -640,7 +643,7 @@ class Post
|
||||||
* @return boolean was the delete successful?
|
* @return boolean was the delete successful?
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function delete(array $conditions, array $options = [])
|
public static function delete(array $conditions, array $options = []): bool
|
||||||
{
|
{
|
||||||
return DBA::delete('post', $conditions, $options);
|
return DBA::delete('post', $conditions, $options);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,10 +54,10 @@ class Profile
|
||||||
*
|
*
|
||||||
* @param integer User ID
|
* @param integer User ID
|
||||||
*
|
*
|
||||||
* @return array Profile data
|
* @return array|bool Profile data or false on error
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function getByUID($uid)
|
public static function getByUID(int $uid)
|
||||||
{
|
{
|
||||||
return DBA::selectFirst('profile', [], ['uid' => $uid]);
|
return DBA::selectFirst('profile', [], ['uid' => $uid]);
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ class Profile
|
||||||
* @param int $id The contact owner ID
|
* @param int $id The contact owner ID
|
||||||
* @param array $fields The selected fields
|
* @param array $fields The selected fields
|
||||||
*
|
*
|
||||||
* @return array Profile data for the ID
|
* @return array|bool Profile data for the ID or false on error
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function getById(int $uid, int $id, array $fields = [])
|
public static function getById(int $uid, int $id, array $fields = [])
|
||||||
|
@ -81,7 +81,7 @@ class Profile
|
||||||
* Returns profile data for the contact owner
|
* Returns profile data for the contact owner
|
||||||
*
|
*
|
||||||
* @param int $uid The User ID
|
* @param int $uid The User ID
|
||||||
* @param array $fields The fields to retrieve
|
* @param array|bool $fields The fields to retrieve or false on error
|
||||||
*
|
*
|
||||||
* @return array Array of profile data
|
* @return array Array of profile data
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
|
@ -94,9 +94,9 @@ class Profile
|
||||||
/**
|
/**
|
||||||
* Update a profile entry and distribute the changes if needed
|
* Update a profile entry and distribute the changes if needed
|
||||||
*
|
*
|
||||||
* @param array $fields
|
* @param array $fields Profile fields to update
|
||||||
* @param integer $uid
|
* @param integer $uid User id
|
||||||
* @return boolean
|
* @return boolean Whether update was successful
|
||||||
*/
|
*/
|
||||||
public static function update(array $fields, int $uid): bool
|
public static function update(array $fields, int $uid): bool
|
||||||
{
|
{
|
||||||
|
@ -136,8 +136,10 @@ class Profile
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Publish a changed profile
|
* Publish a changed profile
|
||||||
* @param int $uid
|
*
|
||||||
|
* @param int $uid User id
|
||||||
* @param bool $force Force publishing to the directory
|
* @param bool $force Force publishing to the directory
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function publishUpdate(int $uid, bool $force = false)
|
public static function publishUpdate(int $uid, bool $force = false)
|
||||||
{
|
{
|
||||||
|
@ -163,7 +165,7 @@ class Profile
|
||||||
*
|
*
|
||||||
* @return string Location string
|
* @return string Location string
|
||||||
*/
|
*/
|
||||||
public static function formatLocation(array $profile)
|
public static function formatLocation(array $profile): string
|
||||||
{
|
{
|
||||||
$location = '';
|
$location = '';
|
||||||
|
|
||||||
|
|
|
@ -34,9 +34,10 @@ class PushSubscriber
|
||||||
*
|
*
|
||||||
* @param integer $uid User ID
|
* @param integer $uid User ID
|
||||||
* @param int $default_priority
|
* @param int $default_priority
|
||||||
|
* @return void
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
public static function publishFeed($uid, $default_priority = PRIORITY_HIGH)
|
public static function publishFeed(int $uid, int $default_priority = PRIORITY_HIGH)
|
||||||
{
|
{
|
||||||
$condition = ['push' => 0, 'uid' => $uid];
|
$condition = ['push' => 0, 'uid' => $uid];
|
||||||
DBA::update('push_subscriber', ['push' => 1, 'next_try' => DBA::NULL_DATETIME], $condition);
|
DBA::update('push_subscriber', ['push' => 1, 'next_try' => DBA::NULL_DATETIME], $condition);
|
||||||
|
@ -48,9 +49,10 @@ class PushSubscriber
|
||||||
* start workers to transmit the feed data
|
* start workers to transmit the feed data
|
||||||
*
|
*
|
||||||
* @param int $default_priority
|
* @param int $default_priority
|
||||||
|
* @return void
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
public static function requeue($default_priority = PRIORITY_HIGH)
|
public static function requeue(int $default_priority = PRIORITY_HIGH)
|
||||||
{
|
{
|
||||||
// We'll push to each subscriber that has push > 0,
|
// We'll push to each subscriber that has push > 0,
|
||||||
// i.e. there has been an update (set in notifier.php).
|
// i.e. there has been an update (set in notifier.php).
|
||||||
|
@ -80,9 +82,10 @@ class PushSubscriber
|
||||||
* @param string $hub_callback Callback address
|
* @param string $hub_callback Callback address
|
||||||
* @param string $hub_topic Feed topic
|
* @param string $hub_topic Feed topic
|
||||||
* @param string $hub_secret Subscription secret
|
* @param string $hub_secret Subscription secret
|
||||||
|
* @return void
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function renew($uid, $nick, $subscribe, $hub_callback, $hub_topic, $hub_secret)
|
public static function renew(int $uid, string $nick, int $subscribe, string $hub_callback, string $hub_topic, string $hub_secret)
|
||||||
{
|
{
|
||||||
// fetch the old subscription if it exists
|
// fetch the old subscription if it exists
|
||||||
$subscriber = DBA::selectFirst('push_subscriber', ['last_update', 'push'], ['callback_url' => $hub_callback]);
|
$subscriber = DBA::selectFirst('push_subscriber', ['last_update', 'push'], ['callback_url' => $hub_callback]);
|
||||||
|
@ -119,9 +122,10 @@ class PushSubscriber
|
||||||
* Delay the push subscriber
|
* Delay the push subscriber
|
||||||
*
|
*
|
||||||
* @param integer $id Subscriber ID
|
* @param integer $id Subscriber ID
|
||||||
|
* @return void
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function delay($id)
|
public static function delay(int $id)
|
||||||
{
|
{
|
||||||
$subscriber = DBA::selectFirst('push_subscriber', ['push', 'callback_url', 'renewed', 'nickname'], ['id' => $id]);
|
$subscriber = DBA::selectFirst('push_subscriber', ['push', 'callback_url', 'renewed', 'nickname'], ['id' => $id]);
|
||||||
if (!DBA::isResult($subscriber)) {
|
if (!DBA::isResult($subscriber)) {
|
||||||
|
@ -158,9 +162,10 @@ class PushSubscriber
|
||||||
*
|
*
|
||||||
* @param integer $id Subscriber ID
|
* @param integer $id Subscriber ID
|
||||||
* @param string $last_update Date of last transmitted item
|
* @param string $last_update Date of last transmitted item
|
||||||
|
* @return void
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function reset($id, $last_update)
|
public static function reset(int $id, string $last_update)
|
||||||
{
|
{
|
||||||
$subscriber = DBA::selectFirst('push_subscriber', ['callback_url', 'nickname'], ['id' => $id]);
|
$subscriber = DBA::selectFirst('push_subscriber', ['callback_url', 'nickname'], ['id' => $id]);
|
||||||
if (!DBA::isResult($subscriber)) {
|
if (!DBA::isResult($subscriber)) {
|
||||||
|
|
Loading…
Reference in a new issue