- added missing type-hints
- added documentation
- removed parameter $baseURL while it can be locally get the same way but
  lesser parameter
- used ActivityNamespace::SALMON_ME
- changed double-quotes to single
This commit is contained in:
Roland Häder 2022-08-12 14:00:02 +02:00
parent 074bae33c9
commit cfa575b8e5
No known key found for this signature in database
GPG key ID: C82EDE5DDFA0BA77
10 changed files with 71 additions and 35 deletions

View file

@ -73,6 +73,7 @@ class DomainPatternBlocklist
/**
* @param string $pattern
* @param string $reason
*
* @return int 0 if the block list couldn't be saved, 1 if the pattern was added, 2 if it was updated in place
*/
public function addPattern(string $pattern, string $reason): int
@ -105,6 +106,7 @@ class DomainPatternBlocklist
/**
* @param string $pattern
*
* @return int 0 if the block list couldn't be saved, 1 if the pattern wasn't found, 2 if it was removed
*/
public function removePattern(string $pattern): int
@ -123,6 +125,13 @@ class DomainPatternBlocklist
return $found ? ($this->set($blocklist) ? 2 : 0) : 1;
}
/**
* @param string $filename
*
* @return void
* @throws Exception
* @todo maybe throw more explicit exception
*/
public function exportToFile(string $filename)
{
$fp = fopen($filename, 'w');
@ -165,6 +174,7 @@ class DomainPatternBlocklist
* Extracts a server domain pattern block list from the provided CSV file name. Deduplicates the list based on patterns.
*
* @param string $filename
*
* @return array
* @throws Exception
*/

View file

@ -109,7 +109,7 @@ class ApiResponse extends Response
* @param int $cid Contact ID of template
* @return array
*/
private function addRSSValues(array $arr, int $cid)
private function addRSSValues(array $arr, int $cid): array
{
if (empty($cid)) {
return $arr;
@ -244,6 +244,8 @@ class ApiResponse extends Response
* Wrapper around exit() for JSON only responses
*
* @param array $data
*
* @return void
*/
public function exitWithJson(array $data)
{

View file

@ -68,10 +68,11 @@ class Show extends BaseApi
/**
* @param array $profile_row array containing data from db table 'profile'
* @param ProfileFields $profileFields
*
* @return array
* @throws HTTPException\InternalServerErrorException
*/
private static function formatProfile($profile_row, ProfileFields $profileFields)
private static function formatProfile($profile_row, ProfileFields $profileFields): array
{
$custom_fields = [];
foreach ($profileFields as $profileField) {

View file

@ -95,7 +95,7 @@ abstract class ContactEndpoint extends BaseApi
* @throws HTTPException\NotFoundException
* @throws \ImagickException
*/
protected static function list(array $ids, int $total_count, int $uid, int $cursor = -1, int $count = self::DEFAULT_COUNT, bool $skip_status = false, bool $include_user_entities = true)
protected static function list(array $ids, int $total_count, int $uid, int $cursor = -1, int $count = self::DEFAULT_COUNT, bool $skip_status = false, bool $include_user_entities = true): array
{
$return = self::ids($ids, $total_count, $cursor, $count, false);
@ -128,7 +128,7 @@ abstract class ContactEndpoint extends BaseApi
* @return array
* @throws HTTPException\NotFoundException
*/
protected static function ids(array $ids, int $total_count, int $cursor = -1, int $count = self::DEFAULT_COUNT, bool $stringify_ids = false)
protected static function ids(array $ids, int $total_count, int $cursor = -1, int $count = self::DEFAULT_COUNT, bool $stringify_ids = false): array
{
$next_cursor = 0;
$previous_cursor = 0;

View file

@ -54,6 +54,8 @@ abstract class DirectMessagesEndpoint extends BaseApi
* @param array $request
* @param int $uid
* @param array $condition
*
* @return void
*/
protected function getMessages(array $request, int $uid, array $condition)
{

View file

@ -102,9 +102,9 @@ class Xrd extends BaseModule
}
if ($mode == Response::TYPE_XML) {
self::printXML($alias, DI::baseUrl()->get(), $user, $owner, $avatar);
self::printXML($alias, $user, $owner, $avatar);
} else {
self::printJSON($alias, DI::baseUrl()->get(), $owner, $avatar);
self::printJSON($alias, $owner, $avatar);
}
}
@ -153,8 +153,9 @@ class Xrd extends BaseModule
System::jsonExit($json, 'application/jrd+json; charset=utf-8');
}
private static function printJSON($alias, $baseURL, $owner, $avatar)
private static function printJSON(string $alias, array $owner, array $avatar)
{
$baseURL = DI::baseUrl()->get();
$salmon_key = Salmon::salmonKey($owner['spubkey']);
$json = [
@ -234,8 +235,9 @@ class Xrd extends BaseModule
System::jsonExit($json, 'application/jrd+json; charset=utf-8');
}
private static function printXML($alias, $baseURL, $user, $owner, $avatar)
private static function printXML(string $alias, array $user, array $owner, array $avatar)
{
$baseURL = DI::baseUrl()->get();
$salmon_key = Salmon::salmonKey($owner['spubkey']);
$tpl = Renderer::getMarkupTemplate('xrd_person.tpl');

View file

@ -112,6 +112,7 @@ class Notification extends BaseRepository
* Returns only the most recent notifications for the same conversation or contact
*
* @param int $uid
*
* @return Collection\Notifications
* @throws Exception
*/
@ -139,6 +140,7 @@ class Notification extends BaseRepository
* Returns only the most recent notifications for the same conversation or contact
*
* @param int $uid
*
* @return Collection\Notifications
* @throws Exception
*/
@ -201,6 +203,7 @@ class Notification extends BaseRepository
* @param int|null $min_id Retrieve models with an id no fewer than this, as close to it as possible
* @param int|null $max_id Retrieve models with an id no greater than this, as close to it as possible
* @param int $limit
*
* @return BaseCollection
* @throws Exception
* @see _selectByBoundaries

View file

@ -88,6 +88,7 @@ class Notify extends BaseRepository
/**
* @param array $condition
* @param array $params
*
* @return Entity\Notify
* @throws HTTPException\NotFoundException
*/
@ -117,6 +118,7 @@ class Notify extends BaseRepository
/**
* @param int $id
*
* @return Entity\Notify
* @throws HTTPException\NotFoundException
*/
@ -153,6 +155,7 @@ class Notify extends BaseRepository
/**
* @param Entity\Notify $Notify
*
* @return Entity\Notify
* @throws HTTPException\NotFoundException
* @throws HTTPException\InternalServerErrorException
@ -459,7 +462,7 @@ class Notify extends BaseRepository
case Model\Notification\Type::SYSTEM:
switch($params['event']) {
case "SYSTEM_REGISTER_REQUEST":
case 'SYSTEM_REGISTER_REQUEST':
$itemlink = $params['link'];
$subject = $l10n->t('[Friendica System Notify]') . ' ' . $l10n->t('registration request');
@ -479,7 +482,8 @@ class Notify extends BaseRepository
$tsitelink = sprintf($sitelink, $params['link']);
$hsitelink = sprintf($sitelink, '<a href="'.$params['link'].'">'.$sitename.'</a><br><br>');
break;
case "SYSTEM_DB_UPDATE_FAIL":
case 'SYSTEM_DB_UPDATE_FAIL': // @TODO Unused (only here)
break;
}
break;
@ -492,7 +496,7 @@ class Notify extends BaseRepository
return $this->storeAndSend($params, $sitelink, $tsitelink, $hsitelink, $title, $subject, $preamble, $epreamble, $body, $itemlink, $show_in_notification_page);
}
private function storeAndSend($params, $sitelink, $tsitelink, $hsitelink, $title, $subject, $preamble, $epreamble, $body, $itemlink, $show_in_notification_page)
private function storeAndSend(array $params, string $sitelink, string $tsitelink, string $hsitelink, string $title, string $subject, string $preamble, string $epreamble, string $body, string $itemlink, bool $show_in_notification_page): bool
{
$item_id = $params['item']['id'] ?? 0;
$uri_id = $params['item']['uri-id'] ?? null;
@ -671,7 +675,7 @@ class Notify extends BaseRepository
return false;
}
public function createFromNotification(Entity\Notification $Notification)
public function createFromNotification(Entity\Notification $Notification): bool
{
$this->logger->info('Start', ['uid' => $Notification->uid, 'id' => $Notification->id, 'type' => $Notification->type]);

View file

@ -128,7 +128,7 @@ class Diaspora
return false;
}
$children = $basedom->children('http://salmon-protocol.org/ns/magic-env');
$children = $basedom->children(ActivityNamespace::SALMON_ME);
if (sizeof($children) == 0) {
Logger::notice('XML has no children');
@ -2969,7 +2969,7 @@ class Diaspora
]
];
$namespaces = ['me' => 'http://salmon-protocol.org/ns/magic-env'];
$namespaces = ['me' => ActivityNamespace::SALMON_ME];
return XML::fromArray($xmldata, $xml, false, $namespaces);
}

View file

@ -145,14 +145,18 @@ class Salmon
$signature3 = Strings::base64UrlEncode(Crypto::rsaSign($data, $owner['sprvkey']));
// At first try the non compliant method that works for GNU Social
$xmldata = ["me:env" => ["me:data" => $data,
"@attributes" => ["type" => $data_type],
"me:encoding" => $encoding,
"me:alg" => $algorithm,
"me:sig" => $signature,
"@attributes2" => ["key_id" => $keyhash]]];
$xmldata = [
'me:env' => [
'me:data' => $data,
'@attributes' => ['type' => $data_type],
'me:encoding' => $encoding,
'me:alg' => $algorithm,
'me:sig' => $signature,
'@attributes2' => ['key_id' => $keyhash],
]
];
$namespaces = ["me" => "http://salmon-protocol.org/ns/magic-env"];
$namespaces = ['me' => ActivityNamespace::SALMON_ME];
$salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
@ -170,14 +174,18 @@ class Salmon
Logger::notice('GNU Social salmon failed. Falling back to compliant mode');
// Now try the compliant mode that normally isn't used for GNU Social
$xmldata = ["me:env" => ["me:data" => $data,
"@attributes" => ["type" => $data_type],
"me:encoding" => $encoding,
"me:alg" => $algorithm,
"me:sig" => $signature2,
"@attributes2" => ["key_id" => $keyhash]]];
$xmldata = [
'me:env' => [
'me:data' => $data,
'@attributes' => ['type' => $data_type],
'me:encoding' => $encoding,
'me:alg' => $algorithm,
'me:sig' => $signature2,
'@attributes2' => ['key_id' => $keyhash]
]
];
$namespaces = ["me" => "http://salmon-protocol.org/ns/magic-env"];
$namespaces = ['me' => ActivityNamespace::SALMON_ME];
$salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
@ -193,14 +201,18 @@ class Salmon
Logger::notice('compliant salmon failed. Falling back to old status.net');
// Last try. This will most likely fail as well.
$xmldata = ["me:env" => ["me:data" => $data,
"@attributes" => ["type" => $data_type],
"me:encoding" => $encoding,
"me:alg" => $algorithm,
"me:sig" => $signature3,
"@attributes2" => ["key_id" => $keyhash]]];
$xmldata = [
'me:env' => [
'me:data' => $data,
'@attributes' => ['type' => $data_type],
'me:encoding' => $encoding,
'me:alg' => $algorithm,
'me:sig' => $signature3,
'@attributes2' => ['key_id' => $keyhash],
]
];
$namespaces = ["me" => "http://salmon-protocol.org/ns/magic-env"];
$namespaces = ['me' => ActivityNamespace::SALMON_ME];
$salmon = XML::fromArray($xmldata, $xml, false, $namespaces);