Skip to content

Commit

Permalink
Qual: Fix ci (phpstan notice)
Browse files Browse the repository at this point in the history
# Qual: Fix ci (phpstan notice)

While fixing the ci notice, also fixed the array definitions
which fixes both phan notices and phpstan notices seen on cti.
Removed the exception for phan on this file
  • Loading branch information
mdeweerd committed Oct 7, 2024
1 parent d5d7d48 commit 8e7b257
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
1 change: 0 additions & 1 deletion dev/tools/phan/baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
15 changes: 8 additions & 7 deletions htdocs/core/class/mastodonhandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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 = [])
{
Expand All @@ -94,15 +94,16 @@ 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
if ($cacheDelay > 0 && $cacheDir && dol_is_file($cacheFile)) {
$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
Expand All @@ -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);
Expand All @@ -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 = [];
Expand Down

0 comments on commit 8e7b257

Please sign in to comment.