From fcfeed8413af5055d79aee4315e86e49349042ad Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 3 Feb 2023 20:03:04 +0000 Subject: [PATCH] fix l2 errors --- core/extension.php | 2 +- core/imageboard/image.php | 2 -- core/polyfills.php | 4 ++-- core/send_event.php | 4 ++++ ext/comment/main.php | 2 ++ ext/image_view_counter/main.php | 1 + ext/pools/main.php | 2 -- ext/post_titles/main.php | 4 ++-- ext/rating/main.php | 6 +++--- ext/res_limit/main.php | 4 ++-- ext/tagger_xml/main.php | 1 + tests/phpstan.neon | 5 +++-- 12 files changed, 21 insertions(+), 16 deletions(-) diff --git a/core/extension.php b/core/extension.php index eab89965..3822d9d1 100644 --- a/core/extension.php +++ b/core/extension.php @@ -395,7 +395,7 @@ abstract class DataHandlerExtension extends Extension { global $page; if ($this->supported_mime($event->image->get_mime())) { - /** @noinspection PhpPossiblePolymorphicInvocationInspection */ + // @phpstan-ignore-next-line $this->theme->display_image($page, $event->image); } } diff --git a/core/imageboard/image.php b/core/imageboard/image.php index c5ec8296..27149baf 100644 --- a/core/imageboard/image.php +++ b/core/imageboard/image.php @@ -268,7 +268,6 @@ class Image * Turn a bunch of strings into a bunch of TagCondition * and ImgCondition objects */ - /** @var $stpe SearchTermParseEvent */ $stpe = send_event(new SearchTermParseEvent($stpen++, null, $terms)); if ($stpe->order) { $order = $stpe->order; @@ -288,7 +287,6 @@ class Image continue; } - /** @var $stpe SearchTermParseEvent */ $stpe = send_event(new SearchTermParseEvent($stpen++, $term, $terms)); if ($stpe->order) { $order = $stpe->order; diff --git a/core/polyfills.php b/core/polyfills.php index b9a56cec..2e88b7c8 100644 --- a/core/polyfills.php +++ b/core/polyfills.php @@ -39,7 +39,7 @@ function ip_in_range(string $IP, string $CIDR): bool list($net, $mask) = explode("/", $CIDR); $ip_net = ip2long($net); - $ip_mask = ~((1 << (32 - $mask)) - 1); + $ip_mask = ~((1 << (32 - (int)$mask)) - 1); $ip_ip = ip2long($IP); @@ -499,7 +499,7 @@ function truncate(string $string, int $limit, string $break=" ", string $pad=".. function parse_shorthand_int(string $limit): int { if (preg_match('/^([\d\.]+)([tgmk])?b?$/i', (string)$limit, $m)) { - $value = $m[1]; + $value = (float)$m[1]; if (isset($m[2])) { switch (strtolower($m[2])) { /** @noinspection PhpMissingBreakStatementInspection */ diff --git a/core/send_event.php b/core/send_event.php index ac989cfb..fbba1999 100644 --- a/core/send_event.php +++ b/core/send_event.php @@ -96,6 +96,10 @@ $_shm_event_count = 0; /** * Send an event to all registered Extensions. + * + * @template T of Event + * @param T $event + * @return T */ function send_event(Event $event): Event { diff --git a/ext/comment/main.php b/ext/comment/main.php index 8e254877..707910ba 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -580,9 +580,11 @@ class CommentList extends Extension $comment ); + // @phpstan-ignore-next-line if ($akismet->errorsExist()) { return false; } else { + // @phpstan-ignore-next-line return $akismet->isSpam(); } } diff --git a/ext/image_view_counter/main.php b/ext/image_view_counter/main.php index 90ff6f7d..41e8c200 100644 --- a/ext/image_view_counter/main.php +++ b/ext/image_view_counter/main.php @@ -6,6 +6,7 @@ namespace Shimmie2; class ImageViewCounter extends Extension { + /** @var ImageViewCounterTheme */ protected ?Themelet $theme; private int $view_interval = 3600; # allows views to be added each hour diff --git a/ext/pools/main.php b/ext/pools/main.php index 169a0cc3..017d136e 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -441,8 +441,6 @@ class Pools extends Extension * When displaying an image, optionally list all the pools that the * image is currently a member of on a side panel, as well as a link * to the Next image in the pool. - * - * @var DisplayingImageEvent $event */ public function onDisplayingImage(DisplayingImageEvent $event) { diff --git a/ext/post_titles/main.php b/ext/post_titles/main.php index 4577caf2..0088964f 100644 --- a/ext/post_titles/main.php +++ b/ext/post_titles/main.php @@ -81,8 +81,8 @@ class PostTitles extends Extension } public function onBulkImport(BulkImportEvent $event) { - if (array_key_exists("title", $event->fields) && $event->fields->title!=null) { - $this->set_title($event->image->id, $event->fields->title); + if (array_key_exists("title", $event->fields) && $event->fields['title']!=null) { + $this->set_title($event->image->id, $event->fields['title']); } } diff --git a/ext/rating/main.php b/ext/rating/main.php index da3cc2b0..0c551412 100644 --- a/ext/rating/main.php +++ b/ext/rating/main.php @@ -183,9 +183,9 @@ class Ratings extends Extension public function onBulkImport(BulkImportEvent $event) { if (array_key_exists("rating", $event->fields) - && $event->fields->rating != null - && Ratings::rating_is_valid($event->fields->rating)) { - $this->set_rating($event->image->id, $event->fields->rating, ""); + && $event->fields['rating'] != null + && Ratings::rating_is_valid($event->fields['rating'])) { + $this->set_rating($event->image->id, $event->fields['rating'], ""); } } diff --git a/ext/res_limit/main.php b/ext/res_limit/main.php index a0e6f27b..69c61f33 100644 --- a/ext/res_limit/main.php +++ b/ext/res_limit/main.php @@ -44,8 +44,8 @@ class ResolutionLimit extends Extension continue; } $valids++; - $width = $parts[0]; - $height = $parts[1]; + $width = (int)$parts[0]; + $height = (int)$parts[1]; if ($image->width / $width == $image->height / $height) { $ok = true; break; diff --git a/ext/tagger_xml/main.php b/ext/tagger_xml/main.php index b18b096b..b736b98d 100644 --- a/ext/tagger_xml/main.php +++ b/ext/tagger_xml/main.php @@ -99,6 +99,7 @@ class TaggerXML extends Extension private function list_to_xml(\FFSPHP\PDOStatement $tags, string $type, string $query, ?array$misc=null): string { + // @phpstan-ignore-next-line $r = $tags->_numOfRows; $s_misc = ""; diff --git a/tests/phpstan.neon b/tests/phpstan.neon index 1ba74d6e..951171fd 100644 --- a/tests/phpstan.neon +++ b/tests/phpstan.neon @@ -1,9 +1,10 @@ parameters: - level: 1 + level: 2 paths: - ../core - ../ext - ../tests - ../themes/default ignoreErrors: - - '#Attribute class GQLA\\Expose#' \ No newline at end of file + - '#Attribute class GQLA\\Expose#' + - '#Access to an undefined property Shimmie2\\Image::\$#'