Fixes and type-hints:

- added more checked type-hints as they prevent bad method invocations
- fixed TypeError for HTML::toBBCode() invocations with NULL as first (wrong)
  argument, thanks to @tobias@social.diekershoff.de pointing this out.
This commit is contained in:
Roland Häder 2022-06-16 13:14:00 +02:00
parent bb57d45237
commit b1e4c0931a
No known key found for this signature in database
GPG Key ID: C82EDE5DDFA0BA77
2 changed files with 19 additions and 14 deletions

View File

@ -241,9 +241,13 @@ class APContact
$apcontact['name'] = $apcontact['nick']; $apcontact['name'] = $apcontact['nick'];
} }
$apcontact['about'] = HTML::toBBCode(JsonLD::fetchElement($compacted, 'as:summary', '@value')); $aboutHtml = JsonLD::fetchElement($compacted, 'as:summary', '@value');
if ($aboutHtml != "") {
$apcontact['about'] = HTML::toBBCode($aboutHtml);
}
$ims = JsonLD::fetchElementArray($compacted, 'vcard:hasInstantMessage'); $ims = JsonLD::fetchElementArray($compacted, 'vcard:hasInstantMessage');
if (!empty($ims)) { if (!empty($ims)) {
foreach ($ims as $link) { foreach ($ims as $link) {
if (substr($link, 0, 5) == 'xmpp:') { if (substr($link, 0, 5) == 'xmpp:') {

View File

@ -71,7 +71,7 @@ class Processor
* @param array $languages * @param array $languages
* @return string language JSON * @return string language JSON
*/ */
private static function processLanguages(array $languages) private static function processLanguages(array $languages): string
{ {
$codes = array_keys($languages); $codes = array_keys($languages);
$lang = []; $lang = [];
@ -88,12 +88,13 @@ class Processor
/** /**
* Replaces emojis in the body * Replaces emojis in the body
* *
* @param array $emojis * @param int $uri_id
* @param string $body * @param string $body
* @param array $emojis
* *
* @return string with replaced emojis * @return string with replaced emojis
*/ */
private static function replaceEmojis(int $uri_id, $body, array $emojis) private static function replaceEmojis(int $uri_id, string $body, array $emojis)
{ {
$body = strtr($body, $body = strtr($body,
array_combine( array_combine(
@ -143,7 +144,7 @@ class Processor
* @param array $activity * @param array $activity
* @param array $item * @param array $item
*/ */
private static function storeAttachments($activity, $item) private static function storeAttachments(array $activity, array $item)
{ {
if (empty($activity['attachments'])) { if (empty($activity['attachments'])) {
return; return;
@ -160,7 +161,7 @@ class Processor
* @param array $activity * @param array $activity
* @param array $item * @param array $item
*/ */
private static function storeQuestion($activity, $item) private static function storeQuestion(array $activity, array $item)
{ {
if (empty($activity['question'])) { if (empty($activity['question'])) {
return; return;
@ -191,7 +192,7 @@ class Processor
* @param array $activity Activity array * @param array $activity Activity array
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
public static function updateItem($activity) public static function updateItem(array $activity)
{ {
$item = Post::selectFirst(['uri', 'uri-id', 'thr-parent', 'gravity', 'post-type'], ['uri' => $activity['id']]); $item = Post::selectFirst(['uri', 'uri-id', 'thr-parent', 'gravity', 'post-type'], ['uri' => $activity['id']]);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
@ -262,7 +263,7 @@ class Processor
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException * @throws \ImagickException
*/ */
public static function createItem($activity) public static function createItem(array $activity): array
{ {
$item = []; $item = [];
$item['verb'] = Activity::POST; $item['verb'] = Activity::POST;
@ -411,7 +412,7 @@ class Processor
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException * @throws \ImagickException
*/ */
public static function deleteItem($activity) public static function deleteItem(array $activity)
{ {
$owner = Contact::getIdForURL($activity['actor']); $owner = Contact::getIdForURL($activity['actor']);
@ -426,7 +427,7 @@ class Processor
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException * @throws \ImagickException
*/ */
public static function addTag($activity) public static function addTag(array $activity)
{ {
if (empty($activity['object_content']) || empty($activity['object_id'])) { if (empty($activity['object_content']) || empty($activity['object_id'])) {
return; return;
@ -457,7 +458,7 @@ class Processor
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException * @throws \ImagickException
*/ */
public static function createActivity($activity, $verb) public static function createActivity(array $activity, string $verb)
{ {
$item = self::createItem($activity); $item = self::createItem($activity);
if (empty($item)) { if (empty($item)) {
@ -561,7 +562,7 @@ class Processor
* @return int event id * @return int event id
* @throws \Exception * @throws \Exception
*/ */
public static function createEvent($activity, $item) public static function createEvent(array $activity, array $item): int
{ {
$event['summary'] = HTML::toBBCode($activity['name'] ?: $activity['summary']); $event['summary'] = HTML::toBBCode($activity['name'] ?: $activity['summary']);
$event['desc'] = HTML::toBBCode($activity['content']); $event['desc'] = HTML::toBBCode($activity['content']);
@ -605,7 +606,7 @@ class Processor
* @return array|bool Returns the item array or false if there was an unexpected occurrence * @return array|bool Returns the item array or false if there was an unexpected occurrence
* @throws \Exception * @throws \Exception
*/ */
private static function processContent($activity, $item) private static function processContent(array $activity, array $item)
{ {
if (!empty($activity['mediatype']) && ($activity['mediatype'] == 'text/markdown')) { if (!empty($activity['mediatype']) && ($activity['mediatype'] == 'text/markdown')) {
$item['title'] = strip_tags($activity['name']); $item['title'] = strip_tags($activity['name']);
@ -615,7 +616,7 @@ class Processor
$content = $activity['content']; $content = $activity['content'];
} else { } else {
// By default assume "text/html" // By default assume "text/html"
$item['title'] = HTML::toBBCode($activity['name']); $item['title'] = (empty($activity['name']) ? HTML::toBBCode($activity['name']) : '');
$content = HTML::toBBCode($activity['content']); $content = HTML::toBBCode($activity['content']);
} }