]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/ParseUrl.php
Merge pull request #11786 from Quix0r/revert-11783-logging-unsupported
[friendica.git] / src / Util / ParseUrl.php
index 8d8329675862779ca3cf2e2b2c511bfd07dfeb49..0183d6b14ae5be6785f90eaf5c16af01e6974de9 100644 (file)
@@ -60,7 +60,7 @@ class ParseUrl
         * @param int    $timeout
         * @return array content type
         */
-       public static function getContentType(string $url, string $accept = HttpClientAccept::DEFAULT, int $timeout = 0)
+       public static function getContentType(string $url, string $accept = HttpClientAccept::DEFAULT, int $timeout = 0): array
        {
                if (!empty($timeout)) {
                        $options = [HttpClientOptions::TIMEOUT => $timeout];
@@ -108,7 +108,7 @@ class ParseUrl
         * @see   ParseUrl::getSiteinfo() for more information about scraping
         * embeddable content
         */
-       public static function getSiteinfoCached($url, $do_oembed = true): array
+       public static function getSiteinfoCached(string $url, bool $do_oembed = true): array
        {
                if (empty($url)) {
                        return [
@@ -187,7 +187,7 @@ class ParseUrl
         * </body>
         * @endverbatim
         */
-       public static function getSiteinfo($url, $do_oembed = true, $count = 1)
+       public static function getSiteinfo(string $url, bool $do_oembed = true, int $count = 1)
        {
                if (empty($url)) {
                        return [
@@ -550,12 +550,15 @@ class ParseUrl
        {
                if (!empty($siteinfo['images'])) {
                        array_walk($siteinfo['images'], function (&$image) use ($page_url) {
-                               // According to the specifications someone could place a picture url into the content field as well.
-                               // But this doesn't seem to happen in the wild, so we don't cover it here.
+                               /*
+                                * According to the specifications someone could place a picture
+                                * URL into the content field as well. But this doesn't seem to
+                                * happen in the wild, so we don't cover it here.
+                                */
                                if (!empty($image['url'])) {
                                        $image['url'] = self::completeUrl($image['url'], $page_url);
                                        $photodata = Images::getInfoFromURLCached($image['url']);
-                                       if (!empty($photodata) && ($photodata[0] > 50) && ($photodata[1] > 50)) {
+                                       if (($photodata) && ($photodata[0] > 50) && ($photodata[1] > 50)) {
                                                $image['src'] = $image['url'];
                                                $image['width'] = $photodata[0];
                                                $image['height'] = $photodata[1];
@@ -640,15 +643,16 @@ class ParseUrl
         * @param string $string Tags
         * @return array with formatted Hashtags
         */
-       public static function convertTagsToArray($string)
+       public static function convertTagsToArray(string $string): array
        {
                $arr_tags = str_getcsv($string);
                if (count($arr_tags)) {
                        // add the # sign to every tag
-                       array_walk($arr_tags, ["self", "arrAddHashes"]);
+                       array_walk($arr_tags, ['self', 'arrAddHashes']);
 
                        return $arr_tags;
                }
+               return [];
        }
 
        /**
@@ -660,9 +664,9 @@ class ParseUrl
         * @param int    $k   Counter for internal use
         * @return void
         */
-       private static function arrAddHashes(&$tag, $k)
+       private static function arrAddHashes(string &$tag, int $k)
        {
-               $tag = "#" . $tag;
+               $tag = '#' . $tag;
        }
 
        /**
@@ -679,41 +683,41 @@ class ParseUrl
         *
         * @return string The url with a scheme
         */
-       private static function completeUrl($url, $scheme)
+       private static function completeUrl(string $url, string $scheme): string
        {
                $urlarr = parse_url($url);
 
                // If the url does allready have an scheme
                // we can stop the process here
-               if (isset($urlarr["scheme"])) {
-                       return($url);
+               if (isset($urlarr['scheme'])) {
+                       return $url;
                }
 
                $schemearr = parse_url($scheme);
 
-               $complete = $schemearr["scheme"]."://".$schemearr["host"];
+               $complete = $schemearr['scheme'] . '://' . $schemearr['host'];
 
-               if (!empty($schemearr["port"])) {
-                       $complete .= ":".$schemearr["port"];
+               if (!empty($schemearr['port'])) {
+                       $complete .= ':' . $schemearr['port'];
                }
 
-               if (!empty($urlarr["path"])) {
-                       if (strpos($urlarr["path"], "/") !== 0) {
-                               $complete .= "/";
+               if (!empty($urlarr['path'])) {
+                       if (strpos($urlarr['path'], '/') !== 0) {
+                               $complete .= '/';
                        }
 
-                       $complete .= $urlarr["path"];
+                       $complete .= $urlarr['path'];
                }
 
-               if (!empty($urlarr["query"])) {
-                       $complete .= "?".$urlarr["query"];
+               if (!empty($urlarr['query'])) {
+                       $complete .= '?' . $urlarr['query'];
                }
 
-               if (!empty($urlarr["fragment"])) {
-                       $complete .= "#".$urlarr["fragment"];
+               if (!empty($urlarr['fragment'])) {
+                       $complete .= '#' . $urlarr['fragment'];
                }
 
-               return($complete);
+               return $complete;
        }
 
        /**
@@ -723,7 +727,7 @@ class ParseUrl
         * @param array $jsonld
         * @return array siteinfo
         */
-       private static function parseParts(array $siteinfo, array $jsonld)
+       private static function parseParts(array $siteinfo, array $jsonld): array
        {
                if (!empty($jsonld['@graph']) && is_array($jsonld['@graph'])) {
                        foreach ($jsonld['@graph'] as $part) {
@@ -768,7 +772,7 @@ class ParseUrl
         * @param array $jsonld
         * @return array siteinfo
         */
-       private static function parseJsonLd(array $siteinfo, array $jsonld)
+       private static function parseJsonLd(array $siteinfo, array $jsonld): array
        {
                $type = JsonLD::fetchElement($jsonld, '@type');
                if (empty($type)) {
@@ -861,7 +865,7 @@ class ParseUrl
         * @param array $jsonld
         * @return array siteinfo
         */
-       private static function parseJsonLdAuthor(array $siteinfo, array $jsonld)
+       private static function parseJsonLdAuthor(array $siteinfo, array $jsonld): array
        {
                $jsonldinfo = [];
 
@@ -945,7 +949,7 @@ class ParseUrl
         * @param array $jsonld
         * @return array siteinfo
         */
-       private static function parseJsonLdArticle(array $siteinfo, array $jsonld)
+       private static function parseJsonLdArticle(array $siteinfo, array $jsonld): array
        {
                $jsonldinfo = [];
 
@@ -1015,7 +1019,7 @@ class ParseUrl
         * @param array $jsonld
         * @return array siteinfo
         */
-       private static function parseJsonLdWebPage(array $siteinfo, array $jsonld)
+       private static function parseJsonLdWebPage(array $siteinfo, array $jsonld): array
        {
                $jsonldinfo = [];
 
@@ -1054,7 +1058,7 @@ class ParseUrl
         * @param array $jsonld
         * @return array siteinfo
         */
-       private static function parseJsonLdWebSite(array $siteinfo, array $jsonld)
+       private static function parseJsonLdWebSite(array $siteinfo, array $jsonld): array
        {
                $jsonldinfo = [];
 
@@ -1092,7 +1096,7 @@ class ParseUrl
         * @param array $jsonld
         * @return array siteinfo
         */
-       private static function parseJsonLdWebOrganization(array $siteinfo, array $jsonld)
+       private static function parseJsonLdWebOrganization(array $siteinfo, array $jsonld): array
        {
                $jsonldinfo = [];
 
@@ -1138,7 +1142,7 @@ class ParseUrl
         * @param array $jsonld
         * @return array siteinfo
         */
-       private static function parseJsonLdWebPerson(array $siteinfo, array $jsonld)
+       private static function parseJsonLdWebPerson(array $siteinfo, array $jsonld): array
        {
                $jsonldinfo = [];
 
@@ -1183,7 +1187,7 @@ class ParseUrl
         * @param array $jsonld
         * @return array siteinfo
         */
-       private static function parseJsonLdMediaObject(array $siteinfo, array $jsonld, string $name)
+       private static function parseJsonLdMediaObject(array $siteinfo, array $jsonld, string $name): array
        {
                $media = [];