Added more known type-hints

Signed-off-by: Roland Häder <roland@mxchange.org>
This commit is contained in:
Roland Häder 2022-06-08 17:26:47 +02:00
parent 98954dd14e
commit 143e4c4a18
Signed by: roland
GPG key ID: C82EDE5DDFA0BA77
2 changed files with 18 additions and 19 deletions

View file

@ -61,7 +61,7 @@ class HTML
* inner value from an attribute value and disregard the tag children. * inner value from an attribute value and disregard the tag children.
* @return bool Whether a replacement was done * @return bool Whether a replacement was done
*/ */
private static function tagToBBCodeSub(DOMDocument $doc, string $tag, array $attributes, string $startbb, string $endbb, bool $ignoreChildren = false) private static function tagToBBCodeSub(DOMDocument $doc, string $tag, array $attributes, string $startbb, string $endbb, bool $ignoreChildren = false): bool
{ {
$savestart = str_replace('$', '\x01', $startbb); $savestart = str_replace('$', '\x01', $startbb);
$replace = false; $replace = false;
@ -141,7 +141,7 @@ class HTML
* @return string * @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
public static function toBBCode($message, $basepath = '') public static function toBBCode(string $message, string $basepath = ''): string
{ {
DI::profiler()->startRecording('rendering'); DI::profiler()->startRecording('rendering');
$message = str_replace("\r", "", $message); $message = str_replace("\r", "", $message);
@ -409,7 +409,7 @@ class HTML
* *
* @return string The expanded URL * @return string The expanded URL
*/ */
private static function qualifyURLsSub($matches, $basepath) private static function qualifyURLsSub(array $matches, string $basepath): string
{ {
$base = parse_url($basepath); $base = parse_url($basepath);
unset($base['query']); unset($base['query']);
@ -436,7 +436,7 @@ class HTML
* *
* @return string Body with expanded URLs * @return string Body with expanded URLs
*/ */
private static function qualifyURLs($body, $basepath) private static function qualifyURLs(string $body, string $basepath): string
{ {
$URLSearchString = "^\[\]"; $URLSearchString = "^\[\]";
@ -462,7 +462,7 @@ class HTML
return $body; return $body;
} }
private static function breakLines($line, $level, $wraplength = 75) private static function breakLines(string $line, int $level, int $wraplength = 75): string
{ {
if ($wraplength == 0) { if ($wraplength == 0) {
$wraplength = 2000000; $wraplength = 2000000;
@ -503,7 +503,7 @@ class HTML
return implode("\n", $newlines); return implode("\n", $newlines);
} }
private static function quoteLevel($message, $wraplength = 75) private static function quoteLevel(string $message, int $wraplength = 75): string
{ {
$lines = explode("\n", $message); $lines = explode("\n", $message);
@ -539,7 +539,7 @@ class HTML
return implode("\n", $newlines); return implode("\n", $newlines);
} }
private static function collectURLs($message) private static function collectURLs(string $message): array
{ {
$pattern = '/<a.*?href="(.*?)".*?>(.*?)<\/a>/is'; $pattern = '/<a.*?href="(.*?)".*?>(.*?)<\/a>/is';
preg_match_all($pattern, $message, $result, PREG_SET_ORDER); preg_match_all($pattern, $message, $result, PREG_SET_ORDER);
@ -585,7 +585,7 @@ class HTML
* @param bool $compact True: Completely strips image tags; False: Keeps image URLs * @param bool $compact True: Completely strips image tags; False: Keeps image URLs
* @return string * @return string
*/ */
public static function toPlaintext(string $html, $wraplength = 75, $compact = false) public static function toPlaintext(string $html, int $wraplength = 75, bool $compact = false): string
{ {
DI::profiler()->startRecording('rendering'); DI::profiler()->startRecording('rendering');
$message = str_replace("\r", "", $html); $message = str_replace("\r", "", $html);
@ -705,7 +705,7 @@ class HTML
* @param string $html * @param string $html
* @return string * @return string
*/ */
public static function toMarkdown($html) public static function toMarkdown(string $html): string
{ {
DI::profiler()->startRecording('rendering'); DI::profiler()->startRecording('rendering');
$converter = new HtmlConverter(['hard_break' => true]); $converter = new HtmlConverter(['hard_break' => true]);
@ -721,7 +721,7 @@ class HTML
* @param string $s * @param string $s
* @return string * @return string
*/ */
public static function toBBCodeVideo($s) public static function toBBCodeVideo(string $s): string
{ {
$s = preg_replace( $s = preg_replace(
'#<object[^>]+>(.*?)https?://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+)(.*?)</object>#ism', '#<object[^>]+>(.*?)https?://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+)(.*?)</object>#ism',
@ -751,7 +751,7 @@ class HTML
* @param string $base base url * @param string $base base url
* @return string * @return string
*/ */
public static function relToAbs($text, $base) public static function relToAbs(string $text, string $base): string
{ {
if (empty($base)) { if (empty($base)) {
return $text; return $text;
@ -790,7 +790,7 @@ class HTML
* @return string html for loader * @return string html for loader
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
public static function scrollLoader() public static function scrollLoader(): string
{ {
$tpl = Renderer::getMarkupTemplate("scroll_loader.tpl"); $tpl = Renderer::getMarkupTemplate("scroll_loader.tpl");
return Renderer::replaceMacros($tpl, [ return Renderer::replaceMacros($tpl, [
@ -819,7 +819,7 @@ class HTML
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException * @throws \ImagickException
*/ */
public static function micropro($contact, $redirect = false, $class = '', $textmode = false) public static function micropro(array $contact, bool $redirect = false, string $class = '', bool $textmode = false): string
{ {
// Use the contact URL if no address is available // Use the contact URL if no address is available
if (empty($contact['addr'])) { if (empty($contact['addr'])) {
@ -859,13 +859,12 @@ class HTML
* *
* @param string $s Search query. * @param string $s Search query.
* @param string $id HTML id * @param string $id HTML id
* @param string $url Search url.
* @param bool $aside Display the search widgit aside. * @param bool $aside Display the search widgit aside.
* *
* @return string Formatted HTML. * @return string Formatted HTML.
* @throws \Exception * @throws \Exception
*/ */
public static function search($s, $id = 'search-box', $aside = true) public static function search(string $s, string $id = 'search-box', bool $aside = true): string
{ {
$mode = 'text'; $mode = 'text';
@ -906,7 +905,7 @@ class HTML
* @param string $s * @param string $s
* @return string * @return string
*/ */
public static function toLink($s) public static function toLink(string $s): string
{ {
$s = preg_replace("/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\'\%\$\!\+]*)/", ' <a href="$1" target="_blank" rel="noopener noreferrer">$1</a>', $s); $s = preg_replace("/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\'\%\$\!\+]*)/", ' <a href="$1" target="_blank" rel="noopener noreferrer">$1</a>', $s);
$s = preg_replace("/\<(.*?)(src|href)=(.*?)\&amp\;(.*?)\>/ism", '<$1$2=$3&$4>', $s); $s = preg_replace("/\<(.*?)(src|href)=(.*?)\&amp\;(.*?)\>/ism", '<$1$2=$3&$4>', $s);
@ -923,7 +922,7 @@ class HTML
* @return string * @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
public static function applyContentFilter($html, array $reasons) public static function applyContentFilter(string $html, array $reasons): string
{ {
if (count($reasons)) { if (count($reasons)) {
$tpl = Renderer::getMarkupTemplate('wall/content_filter.tpl'); $tpl = Renderer::getMarkupTemplate('wall/content_filter.tpl');
@ -943,7 +942,7 @@ class HTML
* @param string $s * @param string $s
* @return string * @return string
*/ */
public static function unamp($s) public static function unamp(string $s): string
{ {
return str_replace('&amp;', '&', $s); return str_replace('&amp;', '&', $s);
} }

View file

@ -2769,7 +2769,7 @@ class Item
* @hook prepare_body ('item'=>item array, 'html'=>body string, 'is_preview'=>boolean, 'filter_reasons'=>string array) after first bbcode to html * @hook prepare_body ('item'=>item array, 'html'=>body string, 'is_preview'=>boolean, 'filter_reasons'=>string array) after first bbcode to html
* @hook prepare_body_final ('item'=>item array, 'html'=>body string) after attach icons and blockquote special case handling (spoiler, author) * @hook prepare_body_final ('item'=>item array, 'html'=>body string) after attach icons and blockquote special case handling (spoiler, author)
*/ */
public static function prepareBody(array &$item, $attach = false, $is_preview = false, $only_cache = false) public static function prepareBody(array &$item, bool $attach = false, bool $is_preview = false, bool $only_cache = false): string
{ {
$a = DI::app(); $a = DI::app();
Hook::callAll('prepare_body_init', $item); Hook::callAll('prepare_body_init', $item);