Browse Source

Fix phpstan level 9 error for f.php and lib/favicons.php (#5263)

* Fix phpstan level 9 error

* Fix phpstan level 9 error

* Remarque's from Alkarex

---------

Co-authored-by: Luc <sanchezluc+freshrss@gmail.com>
Luc SANCHEZ 3 years ago
parent
commit
4f078958b5
2 changed files with 10 additions and 1 deletions
  1. 6 1
      lib/favicons.php
  2. 4 0
      p/f.php

+ 6 - 1
lib/favicons.php

@@ -12,8 +12,11 @@ function isImgMime(string $content): bool {
 	}
 	$isImage = true;
 	try {
+		/** @var finfo $fInfo */
 		$fInfo = finfo_open(FILEINFO_MIME_TYPE);
-		$isImage = strpos(finfo_buffer($fInfo, $content), 'image') !== false;
+		/** @var string $content */
+		$content = finfo_buffer($fInfo, $content);
+		$isImage = strpos($content, 'image') !== false;
 		finfo_close($fInfo);
 	} catch (Exception $e) {
 		echo 'Caught exception: ',  $e->getMessage(), "\n";
@@ -28,6 +31,7 @@ function downloadHttp(string &$url, array $curlOptions = []): string {
 	if (!$url) {
 		return '';
 	}
+	/** @var CurlHandle $ch */
 	$ch = curl_init($url);
 	curl_setopt_array($ch, [
 			CURLOPT_RETURNTRANSFER => true,
@@ -38,6 +42,7 @@ function downloadHttp(string &$url, array $curlOptions = []): string {
 			CURLOPT_ENCODING => '',	//Enable all encodings
 		]);
 	curl_setopt_array($ch, $curlOptions);
+	/** @var string $response */
 	$response = curl_exec($ch);
 	$info = curl_getinfo($ch);
 	curl_close($ch);

+ 4 - 0
p/f.php

@@ -32,6 +32,10 @@ if ($ico_mtime == false || $ico_mtime < $txt_mtime || ($ico_mtime < time() - (mt
 
 	// no ico file or we should download a new one.
 	$url = file_get_contents($txt);
+	if ($url === false) {
+		show_default_favicon(1800);
+		exit();
+	}
 	if (!download_favicon($url, $ico)) {
 		// Download failed
 		if ($ico_mtime == false) {