- 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 $pattern
* @param string $reason * @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 * @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 public function addPattern(string $pattern, string $reason): int
@ -105,6 +106,7 @@ class DomainPatternBlocklist
/** /**
* @param string $pattern * @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 * @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 public function removePattern(string $pattern): int
@ -123,6 +125,13 @@ class DomainPatternBlocklist
return $found ? ($this->set($blocklist) ? 2 : 0) : 1; 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) public function exportToFile(string $filename)
{ {
$fp = fopen($filename, 'w'); $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. * Extracts a server domain pattern block list from the provided CSV file name. Deduplicates the list based on patterns.
* *
* @param string $filename * @param string $filename
*
* @return array * @return array
* @throws Exception * @throws Exception
*/ */

View File

@ -109,7 +109,7 @@ class ApiResponse extends Response
* @param int $cid Contact ID of template * @param int $cid Contact ID of template
* @return array * @return array
*/ */
private function addRSSValues(array $arr, int $cid) private function addRSSValues(array $arr, int $cid): array
{ {
if (empty($cid)) { if (empty($cid)) {
return $arr; return $arr;
@ -244,6 +244,8 @@ class ApiResponse extends Response
* Wrapper around exit() for JSON only responses * Wrapper around exit() for JSON only responses
* *
* @param array $data * @param array $data
*
* @return void
*/ */
public function exitWithJson(array $data) 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 array $profile_row array containing data from db table 'profile'
* @param ProfileFields $profileFields * @param ProfileFields $profileFields
*
* @return array * @return array
* @throws HTTPException\InternalServerErrorException * @throws HTTPException\InternalServerErrorException
*/ */
private static function formatProfile($profile_row, ProfileFields $profileFields) private static function formatProfile($profile_row, ProfileFields $profileFields): array
{ {
$custom_fields = []; $custom_fields = [];
foreach ($profileFields as $profileField) { foreach ($profileFields as $profileField) {

View File

@ -95,7 +95,7 @@ abstract class ContactEndpoint extends BaseApi
* @throws HTTPException\NotFoundException * @throws HTTPException\NotFoundException
* @throws \ImagickException * @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); $return = self::ids($ids, $total_count, $cursor, $count, false);
@ -128,7 +128,7 @@ abstract class ContactEndpoint extends BaseApi
* @return array * @return array
* @throws HTTPException\NotFoundException * @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; $next_cursor = 0;
$previous_cursor = 0; $previous_cursor = 0;

View File

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

View File

@ -102,9 +102,9 @@ class Xrd extends BaseModule
} }
if ($mode == Response::TYPE_XML) { if ($mode == Response::TYPE_XML) {
self::printXML($alias, DI::baseUrl()->get(), $user, $owner, $avatar); self::printXML($alias, $user, $owner, $avatar);
} else { } 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'); 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']); $salmon_key = Salmon::salmonKey($owner['spubkey']);
$json = [ $json = [
@ -234,8 +235,9 @@ class Xrd extends BaseModule
System::jsonExit($json, 'application/jrd+json; charset=utf-8'); 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']); $salmon_key = Salmon::salmonKey($owner['spubkey']);
$tpl = Renderer::getMarkupTemplate('xrd_person.tpl'); $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 * Returns only the most recent notifications for the same conversation or contact
* *
* @param int $uid * @param int $uid
*
* @return Collection\Notifications * @return Collection\Notifications
* @throws Exception * @throws Exception
*/ */
@ -139,6 +140,7 @@ class Notification extends BaseRepository
* Returns only the most recent notifications for the same conversation or contact * Returns only the most recent notifications for the same conversation or contact
* *
* @param int $uid * @param int $uid
*
* @return Collection\Notifications * @return Collection\Notifications
* @throws Exception * @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 $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|null $max_id Retrieve models with an id no greater than this, as close to it as possible
* @param int $limit * @param int $limit
*
* @return BaseCollection * @return BaseCollection
* @throws Exception * @throws Exception
* @see _selectByBoundaries * @see _selectByBoundaries

View File

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

View File

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

View File

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