]> git.mxchange.org Git - friendica.git/commitdiff
Fix many strict errors
authorArt4 <art4@wlabs.de>
Fri, 6 Jun 2025 10:55:59 +0000 (10:55 +0000)
committerArt4 <art4@wlabs.de>
Fri, 6 Jun 2025 10:55:59 +0000 (10:55 +0000)
.phpstan.neon
src/Content/Pager.php
src/Content/Text/HTML.php
src/Core/Lock/Type/AbstractLock.php
src/Core/Session/Handler/Cache.php
src/Core/Session/Handler/Database.php
src/Core/Worker.php
src/Database/PostUpdate.php
src/Network/Probe.php
src/Object/Image.php
src/Util/HTTPSignature.php

index 551cf2b69bd81e9f7b15ddf7c1572dc439ce1de3..15d3ec15fb5a7d683c34d72fa630fe9d7247559c 100644 (file)
@@ -26,6 +26,7 @@ parameters:
     dynamicConstantNames:
         - DB_UPDATE_VERSION
 
+    # See all rules at https://github.com/phpstan/phpstan-strict-rules/blob/2.0.x/rules.neon
     strictRules:
         allRules: false
 
index 0cdf5c0e4a68ec0edfc7016ba5ae893d27219eff..4d35ff2b466ebe6a66f9c67424c61f5a2bf1ec7a 100644 (file)
@@ -215,8 +215,8 @@ class Pager
 
                        // Limit the number of displayed page number buttons.
                        if ($numpages > 8) {
-                               $numstart = (($this->getPage() > 4) ? ($this->getPage() - 4) : 1);
-                               $numstop = (($this->getPage() > ($numpages - 7)) ? $numpages : ($numstart + 8));
+                               $numstart = ($this->getPage() > 4) ? ($this->getPage() - 4) : 1;
+                               $numstop = ($this->getPage() > ($numpages - 7)) ? $numpages : ($numstart + 8);
                        }
 
                        $pages = [];
index 72c61f38cc1324af02c519a19349a8d2aab9e50b..701125dd27fdd46d48e41374581d36aa14d2ffd5 100644 (file)
@@ -55,7 +55,7 @@ class HTML
 
                $xpath = new DOMXPath($doc);
 
-               /** @var \DOMNode[] $list */
+               /** @var \DOMNodeList<\DOMNode>|false $list */
                $list = $xpath->query("//" . $tag);
                foreach ($list as $node) {
                        $attr = [];
@@ -1018,7 +1018,7 @@ class HTML
         */
        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.
                // And that the href attribute contains exactly the provided URL
index 9d8b5849b22d2f7ec78ea45f8bd31835af8d75a1..6854be267cfefdc46ce602db815952b3a8c75543 100644 (file)
@@ -28,7 +28,7 @@ abstract class AbstractLock implements ICanLock
         */
        protected function hasAcquiredLock(string $key): bool
        {
-               return isset($this->acquireLock[$key]) && $this->acquiredLocks[$key] === true;
+               return isset($this->acquiredLocks[$key]) && $this->acquiredLocks[$key] === true;
        }
 
        /**
index 7629d9a1647c96e2963a6bc0a90d4cb273867fa8..65b87872a72808c028e33e47687a574512d8efdc 100644 (file)
@@ -99,8 +99,11 @@ class Cache extends AbstractSessionHandler
        }
 
        #[\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
        }
 }
index 3ef64294b99b70e4ad6504aa2cc86d6a72f2acff..d8146139a12ec076eabc92c2be2b05aaa0c96504 100644 (file)
@@ -124,13 +124,23 @@ class Database extends AbstractSessionHandler
        }
 
        #[\ReturnTypeWillChange]
-       public function gc($max_lifetime): bool
+       /**
+        * @return int|false
+        */
+       public function gc($max_lifetime)
        {
                try {
-                       return $this->dba->delete('session', ["`expire` < ?", time()]);
+                       $result = $this->dba->delete('session', ["`expire` < ?", time()]);
                } catch (\Exception $exception) {
                        $this->logger->warning('Cannot use garbage collector.', ['exception' => $exception]);
                        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;
        }
 }
index fd332785027d6bc7bd605213fbee9675b8cf8d83..fd2ab5c242c2ef9097e294a58b7a5fd9f93cc203 100644 (file)
@@ -521,7 +521,7 @@ class Worker
                }
 
                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)]);
                }
        }
 
index 6aebda80962b4791f5fb7599d6e0960ebf5d211d..031c2fec1d81418063a214815e0e885419d71a92 100644 (file)
@@ -193,7 +193,7 @@ class PostUpdate
                        Contact::removeDuplicates($contact['nurl'], $contact['uid']);
                }
 
-               DBA::close($contact);
+               DBA::close($contacts);
                DI::keyValue()->set('post_update_version', 1322);
 
                DI::logger()->info('Done');
index 471f6e313ab0e81f017d09f06401756bb88988f2..92ee97b816390714355c8e2a191a357fbcce7f2b 100644 (file)
@@ -8,7 +8,7 @@
 namespace Friendica\Network;
 
 use DOMDocument;
-use DomXPath;
+use DOMXPath;
 use Exception;
 use Friendica\Content\Text\HTML;
 use Friendica\Core\Hook;
@@ -1273,7 +1273,7 @@ class Probe
                        return [];
                }
 
-               $xpath = new DomXPath($doc);
+               $xpath = new DOMXPath($doc);
 
                $vcards = $xpath->query("//div[contains(concat(' ', @class, ' '), ' vcard ')]");
                if (!is_object($vcards)) {
index 0aad761341bdf6dc5d34c0a28ddcbe3befd99536..283a8d48959bc36baec2b4d7c03a7effd6d41980 100644 (file)
@@ -363,12 +363,11 @@ class Image
         * Rotates image
         *
         * @param integer $degrees degrees to rotate image
-        * @return mixed
         */
-       public function rotate(int $degrees)
+       public function rotate(int $degrees): void
        {
                if (!$this->isValid()) {
-                       return false;
+                       return;
                }
 
                if ($this->isImagick()) {
@@ -393,12 +392,11 @@ class Image
         *
         * @param boolean $horiz optional, default true
         * @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()) {
-                       return false;
+                       return;
                }
 
                if ($this->isImagick()) {
index a779a59a86baf0ec659779482cf369651298d650..c5a182f98e2415f977856d3dab3946efb39a81c1 100644 (file)
@@ -592,7 +592,7 @@ class HTTPSignature
                        return [];
                }
 
-               $sig_block = self::parseSigHeader($http_headers['HTTP_SIGNATURE']);
+               $sig_block = self::parseSigheader($http_headers['HTTP_SIGNATURE']);
 
                if (empty($sig_block['keyId'])) {
                        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
                if (!empty($sig_block['created']) && empty($headers['(created)'])) {