Fix many strict errors

This commit is contained in:
Art4 2025-06-06 10:55:59 +00:00
parent 07db85b99d
commit 95b3322731
11 changed files with 33 additions and 21 deletions

View file

@ -26,6 +26,7 @@ parameters:
dynamicConstantNames: dynamicConstantNames:
- DB_UPDATE_VERSION - DB_UPDATE_VERSION
# See all rules at https://github.com/phpstan/phpstan-strict-rules/blob/2.0.x/rules.neon
strictRules: strictRules:
allRules: false allRules: false

View file

@ -215,8 +215,8 @@ class Pager
// Limit the number of displayed page number buttons. // Limit the number of displayed page number buttons.
if ($numpages > 8) { if ($numpages > 8) {
$numstart = (($this->getPage() > 4) ? ($this->getPage() - 4) : 1); $numstart = ($this->getPage() > 4) ? ($this->getPage() - 4) : 1;
$numstop = (($this->getPage() > ($numpages - 7)) ? $numpages : ($numstart + 8)); $numstop = ($this->getPage() > ($numpages - 7)) ? $numpages : ($numstart + 8);
} }
$pages = []; $pages = [];

View file

@ -55,7 +55,7 @@ class HTML
$xpath = new DOMXPath($doc); $xpath = new DOMXPath($doc);
/** @var \DOMNode[] $list */ /** @var \DOMNodeList<\DOMNode>|false $list */
$list = $xpath->query("//" . $tag); $list = $xpath->query("//" . $tag);
foreach ($list as $node) { foreach ($list as $node) {
$attr = []; $attr = [];
@ -1018,7 +1018,7 @@ class HTML
*/ */
public static function checkRelMeLink(DOMDocument $doc, UriInterface $meUrl): bool public static function checkRelMeLink(DOMDocument $doc, UriInterface $meUrl): bool
{ {
$xpath = new \DOMXpath($doc); $xpath = new \DOMXPath($doc);
// This expression checks that "me" is among the space-delimited values of the "rel" attribute. // This expression checks that "me" is among the space-delimited values of the "rel" attribute.
// And that the href attribute contains exactly the provided URL // And that the href attribute contains exactly the provided URL

View file

@ -28,7 +28,7 @@ abstract class AbstractLock implements ICanLock
*/ */
protected function hasAcquiredLock(string $key): bool protected function hasAcquiredLock(string $key): bool
{ {
return isset($this->acquireLock[$key]) && $this->acquiredLocks[$key] === true; return isset($this->acquiredLocks[$key]) && $this->acquiredLocks[$key] === true;
} }
/** /**

View file

@ -99,8 +99,11 @@ class Cache extends AbstractSessionHandler
} }
#[\ReturnTypeWillChange] #[\ReturnTypeWillChange]
public function gc($max_lifetime): bool /**
* @return int|false
*/
public function gc($max_lifetime)
{ {
return true; return 0; // Cache does not support garbage collection, so we return 0 to indicate no action taken
} }
} }

View file

@ -124,13 +124,23 @@ class Database extends AbstractSessionHandler
} }
#[\ReturnTypeWillChange] #[\ReturnTypeWillChange]
public function gc($max_lifetime): bool /**
* @return int|false
*/
public function gc($max_lifetime)
{ {
try { try {
return $this->dba->delete('session', ["`expire` < ?", time()]); $result = $this->dba->delete('session', ["`expire` < ?", time()]);
} catch (\Exception $exception) { } catch (\Exception $exception) {
$this->logger->warning('Cannot use garbage collector.', ['exception' => $exception]); $this->logger->warning('Cannot use garbage collector.', ['exception' => $exception]);
return false; return false;
} }
if ($result !== false) {
// TODO: DBA::delete() returns true, but we need to return the number of deleted rows as interger
$result = 0;
}
return $result;
} }
} }

View file

@ -521,7 +521,7 @@ class Worker
} }
if ($sleeping) { if ($sleeping) {
DI::logger()->info('Cooldown ended.', ['max-load' => $load_cooldown, 'max-processes' => $processes_cooldown, 'load' => $load, 'called-by' => System::callstack(1)]); DI::logger()->info('Cooldown ended.', ['max-load' => $load_cooldown, 'max-processes' => $processes_cooldown, 'load' => $load ?? [], 'called-by' => System::callstack(1)]);
} }
} }

View file

@ -193,7 +193,7 @@ class PostUpdate
Contact::removeDuplicates($contact['nurl'], $contact['uid']); Contact::removeDuplicates($contact['nurl'], $contact['uid']);
} }
DBA::close($contact); DBA::close($contacts);
DI::keyValue()->set('post_update_version', 1322); DI::keyValue()->set('post_update_version', 1322);
DI::logger()->info('Done'); DI::logger()->info('Done');

View file

@ -8,7 +8,7 @@
namespace Friendica\Network; namespace Friendica\Network;
use DOMDocument; use DOMDocument;
use DomXPath; use DOMXPath;
use Exception; use Exception;
use Friendica\Content\Text\HTML; use Friendica\Content\Text\HTML;
use Friendica\Core\Hook; use Friendica\Core\Hook;
@ -1273,7 +1273,7 @@ class Probe
return []; return [];
} }
$xpath = new DomXPath($doc); $xpath = new DOMXPath($doc);
$vcards = $xpath->query("//div[contains(concat(' ', @class, ' '), ' vcard ')]"); $vcards = $xpath->query("//div[contains(concat(' ', @class, ' '), ' vcard ')]");
if (!is_object($vcards)) { if (!is_object($vcards)) {

View file

@ -363,12 +363,11 @@ class Image
* Rotates image * Rotates image
* *
* @param integer $degrees degrees to rotate image * @param integer $degrees degrees to rotate image
* @return mixed
*/ */
public function rotate(int $degrees) public function rotate(int $degrees): void
{ {
if (!$this->isValid()) { if (!$this->isValid()) {
return false; return;
} }
if ($this->isImagick()) { if ($this->isImagick()) {
@ -393,12 +392,11 @@ class Image
* *
* @param boolean $horiz optional, default true * @param boolean $horiz optional, default true
* @param boolean $vert optional, default false * @param boolean $vert optional, default false
* @return mixed
*/ */
public function flip(bool $horiz = true, bool $vert = false) public function flip(bool $horiz = true, bool $vert = false): void
{ {
if (!$this->isValid()) { if (!$this->isValid()) {
return false; return;
} }
if ($this->isImagick()) { if ($this->isImagick()) {

View file

@ -592,7 +592,7 @@ class HTTPSignature
return []; return [];
} }
$sig_block = self::parseSigHeader($http_headers['HTTP_SIGNATURE']); $sig_block = self::parseSigheader($http_headers['HTTP_SIGNATURE']);
if (empty($sig_block['keyId'])) { if (empty($sig_block['keyId'])) {
DI::logger()->debug('No keyId', ['sig_block' => $sig_block]); DI::logger()->debug('No keyId', ['sig_block' => $sig_block]);
@ -652,7 +652,7 @@ class HTTPSignature
} }
} }
$sig_block = self::parseSigHeader($http_headers['HTTP_SIGNATURE']); $sig_block = self::parseSigheader($http_headers['HTTP_SIGNATURE']);
// Add fields from the signature block to the header. See issue 8845 // Add fields from the signature block to the header. See issue 8845
if (!empty($sig_block['created']) && empty($headers['(created)'])) { if (!empty($sig_block['created']) && empty($headers['(created)'])) {