]> _ Git - psq.git/commitdiff
Update GetPageTitleFromUrl.php
authorLouis Jeckel <louis.jeckel@outlook.cm>
Thu, 27 Aug 2020 17:06:40 +0000 (19:06 +0200)
committerLouis Jeckel <louis.jeckel@outlook.cm>
Thu, 27 Aug 2020 17:06:40 +0000 (19:06 +0200)
app/Invokables/GetPageTitleFromUrl.php

index d1e7ed58599ee2d90e67ad98c5012fdea96d5e04..51fbb87c01736e026a1764d109cbcb332931ddbf 100644 (file)
@@ -6,9 +6,10 @@ namespace App\Invokables;
 
 class GetPageTitleFromUrl
 {
-    public function __invoke($url)
+    public function __invoke($url): string
     {
 
+        $unknown = "Titre inconnu";
         $context = stream_context_create(
             [
                 "http" => [
@@ -21,8 +22,10 @@ class GetPageTitleFromUrl
         if($str !== ''){
             $str = trim(preg_replace('/\s+/', ' ', $str)); // supports line breaks inside <title>
             preg_match("/<title>(.*)<\/title>/i",$str,$title); // ignore case
-            return $title[1];
+            return $title[1] ?? $unknown;
         }
+
+        return $unknown;
     }
 
 }