This commit is contained in:
Artur Weigandt 2025-06-06 14:31:12 +00:00 committed by GitHub
commit 1e77245a71
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 92 additions and 39 deletions

View file

@ -2,6 +2,9 @@
# #
# SPDX-License-Identifier: CC0-1.0 # SPDX-License-Identifier: CC0-1.0
includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon
parameters: parameters:
level: 3 level: 3
@ -23,6 +26,10 @@ 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:
allRules: false
ignoreErrors: ignoreErrors:
- -
# Ignore missing GdImage class in PHP <= 7.4 # Ignore missing GdImage class in PHP <= 7.4

View file

@ -157,6 +157,7 @@
"php-mock/php-mock-phpunit": "^2.10", "php-mock/php-mock-phpunit": "^2.10",
"phpmd/phpmd": "^2.15", "phpmd/phpmd": "^2.15",
"phpstan/phpstan": "^2.0", "phpstan/phpstan": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpunit": "^9" "phpunit/phpunit": "^9"
}, },
"scripts": { "scripts": {

50
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "897b878d6db24b9a6437bd9f971478be", "content-hash": "e93a8ac7e31cf3e5e0ca76134e5ffa0b",
"packages": [ "packages": [
{ {
"name": "asika/simple-console", "name": "asika/simple-console",
@ -5849,6 +5849,54 @@
], ],
"time": "2024-11-11T15:43:04+00:00" "time": "2024-11-11T15:43:04+00:00"
}, },
{
"name": "phpstan/phpstan-strict-rules",
"version": "2.0.0",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan-strict-rules.git",
"reference": "a4a6a08bd4a461e516b9c3b8fdbf0f1883b34158"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan-strict-rules/zipball/a4a6a08bd4a461e516b9c3b8fdbf0f1883b34158",
"reference": "a4a6a08bd4a461e516b9c3b8fdbf0f1883b34158",
"shasum": ""
},
"require": {
"php": "^7.4 || ^8.0",
"phpstan/phpstan": "^2.0"
},
"require-dev": {
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/phpstan-deprecation-rules": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpunit/phpunit": "^9.6"
},
"type": "phpstan-extension",
"extra": {
"phpstan": {
"includes": [
"rules.neon"
]
}
},
"autoload": {
"psr-4": {
"PHPStan\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Extra strict and opinionated rules for PHPStan",
"support": {
"issues": "https://github.com/phpstan/phpstan-strict-rules/issues",
"source": "https://github.com/phpstan/phpstan-strict-rules/tree/2.0.0"
},
"time": "2024-10-26T16:04:33+00:00"
},
{ {
"name": "phpunit/php-code-coverage", "name": "phpunit/php-code-coverage",
"version": "9.2.31", "version": "9.2.31",

View file

@ -92,5 +92,7 @@ HELP;
CoreWorker::unclaimProcess($process); CoreWorker::unclaimProcess($process);
$this->processRepo->delete($process); $this->processRepo->delete($process);
return;
} }
} }

View file

@ -208,15 +208,15 @@ class Pager
'class' => $this->getPage() == 1 ? 'disabled' : '' 'class' => $this->getPage() == 1 ? 'disabled' : ''
]; ];
$numpages = $totalItemCount / $this->getItemsPerPage(); $numpages = (int) ceil($totalItemCount / $this->getItemsPerPage());
$numstart = 1; $numstart = 1;
$numstop = $numpages; $numstop = $numpages;
// 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 = [];
@ -237,22 +237,6 @@ class Pager
} }
} }
if (($totalItemCount % $this->getItemsPerPage()) != 0) {
if ($i == $this->getPage()) {
$pages[$i] = [
'url' => '#',
'text' => $i,
'class' => 'current active'
];
} else {
$pages[$i] = [
'url' => Strings::ensureQueryParameter($this->baseQueryString . '&page=' . $i),
'text' => $i,
'class' => 'n'
];
}
}
$data['pages'] = $pages; $data['pages'] = $pages;
$lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages); $lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages);

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)'])) {