diff --git a/dev/tools/phan/baseline.txt b/dev/tools/phan/baseline.txt index a0811521ad83b..24b013506ea8e 100644 --- a/dev/tools/phan/baseline.txt +++ b/dev/tools/phan/baseline.txt @@ -318,7 +318,6 @@ return [ 'htdocs/core/class/html.formwebsite.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownPropertyType'], 'htdocs/core/class/ldap.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanPluginUnknownArrayPropertyType', 'PhanPossiblyUndeclaredVariable'], 'htdocs/core/class/link.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownPropertyType'], - 'htdocs/core/class/mastodonhandler.class.php' => ['PhanPluginUnknownArrayMethodParamType'], 'htdocs/core/class/notify.class.php' => ['PhanUndeclaredProperty'], 'htdocs/core/class/openid.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanPluginUnknownPropertyType'], 'htdocs/core/class/reddithandler.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanPluginUnknownArrayPropertyType'], diff --git a/htdocs/core/class/mastodonhandler.class.php b/htdocs/core/class/mastodonhandler.class.php index 6494d7ed616bb..4019d2b86050c 100644 --- a/htdocs/core/class/mastodonhandler.class.php +++ b/htdocs/core/class/mastodonhandler.class.php @@ -65,7 +65,7 @@ class MastodonHandler /** * Constructor to set the necessary credentials. * - * @param array $authParams parameters for authentication + * @param array{client_id?:string,client_secret?:string,redirect_uri?:string,access_token?:string} $authParams parameters for authentication */ public function __construct($authParams) { @@ -84,8 +84,8 @@ public function __construct($authParams) * @param int $maxNb Maximum number of posts to retrieve * @param int $cacheDelay Cache delay in seconds * @param string $cacheDir Directory for caching - * @param array $authParams Authentication parameters - * @return array|false Array of posts if successful, False otherwise + * @param array{client_id?:string,client_secret?:string,redirect_uri?:string,access_token?:string} $authParams Authentication parameters + * @return false|array{id:string,content:string,created_at:string,url:string,media_url:string}|array{} Array of posts if successful, False otherwise */ public function fetch($urlAPI, $maxNb = 5, $cacheDelay = 60, $cacheDir = '', $authParams = []) { @@ -94,6 +94,7 @@ public function fetch($urlAPI, $maxNb = 5, $cacheDelay = 60, $cacheDir = '', $au } $cacheFile = $cacheDir.'/'.dol_hash($urlAPI, '3'); $foundInCache = false; + /** @var ?string $data */ $data = null; // Check cache @@ -101,8 +102,8 @@ public function fetch($urlAPI, $maxNb = 5, $cacheDelay = 60, $cacheDir = '', $au $fileDate = dol_filemtime($cacheFile); if ($fileDate >= (dol_now() - $cacheDelay)) { $foundInCache = true; - // Read file into cache - $data = file_get_contents($cacheFile); + // Read file into cache (false should not happen) + $data = (string) file_get_contents($cacheFile); } } $foundInCache = false; // To force to not use the cache @@ -116,7 +117,7 @@ public function fetch($urlAPI, $maxNb = 5, $cacheDelay = 60, $cacheDir = '', $au $result = getURLContent($urlAPI, 'GET', '', 1, $headers, array('http', 'https'), 0); if (empty($result['curl_error_no']) && $result['http_code'] == 200 && !empty($result['content'])) { - $data = $result['content']; + $data = (string) $result['content']; if ($cacheDir) { dol_mkdir($cacheDir); @@ -127,7 +128,7 @@ public function fetch($urlAPI, $maxNb = 5, $cacheDelay = 60, $cacheDir = '', $au return false; } } - if (!is_null($data)) { + if (!is_null($data)) { // Because of force to not use cache, $data is not null, ignore until cache is enabled @phpstan-ignore-line $data = json_decode($data, true); if (is_array($data)) { $this->posts = [];