From 2396ae2ef961f4611a45f89b05edd9d74f512dfe Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 28 May 2019 20:27:23 +0100 Subject: [PATCH] fix a bunch of lints --- composer.json | 3 ++- core/basethemelet.php | 8 ++++---- core/cacheengine.php | 5 +++-- core/database.php | 2 +- core/imageboard/event.php | 6 +++--- core/imageboard/search.php | 2 +- core/userclass.php | 4 ++-- core/util.php | 2 +- ext/admin/main.php | 2 +- ext/artists/main.php | 4 ++-- ext/artists/theme.php | 2 +- ext/comment/main.php | 2 +- ext/comment/theme.php | 14 -------------- ext/cron_uploader/main.php | 4 ++-- ext/favorites/main.php | 2 +- ext/handle_pixel/main.php | 9 --------- ext/index/main.php | 2 +- ext/pools/theme.php | 6 ++++-- ext/rating/main.php | 2 +- ext/rule34/main.php | 6 ++---- ext/rule34/theme.php | 4 ++-- ext/setup/main.php | 6 +++--- ext/tag_categories/theme.php | 3 --- ext/tag_edit/main.php | 10 +++++----- ext/tagger/main.php | 2 +- ext/user/main.php | 2 +- ext/view/main.php | 12 ++++++------ ext/wiki/main.php | 7 +++++-- themes/danbooru/index.theme.php | 2 +- themes/danbooru2/comment.theme.php | 6 +++--- themes/danbooru2/index.theme.php | 2 +- themes/futaba/comment.theme.php | 6 +++--- themes/futaba/themelet.class.php | 2 +- themes/lite/themelet.class.php | 4 ++-- 34 files changed, 67 insertions(+), 88 deletions(-) diff --git a/composer.json b/composer.json index 509164c6..902eca86 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,7 @@ "require" : { "php" : ">=7.1", "ext-pdo": "*", + "ext-json": "*", "flexihash/flexihash" : "^2.0.0", "ifixit/php-akismet" : "1.*", @@ -38,7 +39,7 @@ "bower-asset/tablesorter" : "dev-master", "bower-asset/mediaelement" : "2.21.1", "bower-asset/js-cookie" : "2.1.1" - }, + }, "require-dev" : { "phpunit/phpunit" : "6.*" diff --git a/core/basethemelet.php b/core/basethemelet.php index 8ff6eab1..897a1f33 100644 --- a/core/basethemelet.php +++ b/core/basethemelet.php @@ -76,7 +76,7 @@ class BaseThemelet "\n"; } - public function display_paginator(Page $page, string $base, string $query=null, int $page_number, int $total_pages, bool $show_random = false) + public function display_paginator(Page $page, string $base, ?string $query, int $page_number, int $total_pages, bool $show_random = false) { if ($total_pages == 0) { $total_pages = 1; @@ -85,13 +85,13 @@ class BaseThemelet $page->add_block(new Block(null, $body, "main", 90, "paginator")); } - private function gen_page_link(string $base_url, string $query=null, string $page, string $name): string + private function gen_page_link(string $base_url, ?string $query, string $page, string $name): string { $link = make_link($base_url.'/'.$page, $query); return ''.$name.''; } - private function gen_page_link_block(string $base_url, string $query=null, string $page, int $current_page, string $name): string + private function gen_page_link_block(string $base_url, ?string $query, string $page, int $current_page, string $name): string { $paginator = ""; if ($page == $current_page) { @@ -104,7 +104,7 @@ class BaseThemelet return $paginator; } - private function build_paginator(int $current_page, int $total_pages, string $base_url, string $query=null, bool $show_random): string + private function build_paginator(int $current_page, int $total_pages, string $base_url, ?string $query, bool $show_random): string { $next = $current_page + 1; $prev = $current_page - 1; diff --git a/core/cacheengine.php b/core/cacheengine.php index c1e19e64..61fd84ab 100644 --- a/core/cacheengine.php +++ b/core/cacheengine.php @@ -22,7 +22,7 @@ class NoCache implements CacheEngine class MemcacheCache implements CacheEngine { - /** @var \Memcache|null */ + /** @var ?Memcache */ public $memcache=null; public function __construct(string $args) @@ -50,7 +50,7 @@ class MemcacheCache implements CacheEngine class MemcachedCache implements CacheEngine { - /** @var \Memcached|null */ + /** @var ?Memcached */ public $memcache=null; public function __construct(string $args) @@ -169,6 +169,7 @@ class Cache public function __construct(?string $dsn) { $matches = []; + $c = null; if ($dsn && preg_match("#(.*)://(.*)#", $dsn, $matches)) { if ($matches[1] == "memcache") { $c = new MemcacheCache($matches[2]); diff --git a/core/database.php b/core/database.php index dbeb50a1..9234cfa5 100644 --- a/core/database.php +++ b/core/database.php @@ -350,7 +350,7 @@ class MockDatabase extends Database private $query_id = 0; /** @var array */ private $responses = []; - /** @var \NoCache|null */ + /** @var ?NoCache */ public $cache = null; public function __construct(array $responses = []) diff --git a/core/imageboard/event.php b/core/imageboard/event.php index 9f09655a..6ed27177 100644 --- a/core/imageboard/event.php +++ b/core/imageboard/event.php @@ -37,7 +37,7 @@ class ImageAdditionException extends SCoreException */ class ImageDeletionEvent extends Event { - /** @var \Image */ + /** @var Image */ public $image; /** @@ -59,7 +59,7 @@ class ImageReplaceEvent extends Event { /** @var int */ public $id; - /** @var \Image */ + /** @var Image */ public $image; /** @@ -123,7 +123,7 @@ class ParseLinkTemplateEvent extends Event public $link; /** @var string */ public $original; - /** @var \Image */ + /** @var Image */ public $image; public function __construct(string $link, Image $image) diff --git a/core/imageboard/search.php b/core/imageboard/search.php index dd1712f7..6a2bc916 100644 --- a/core/imageboard/search.php +++ b/core/imageboard/search.php @@ -45,7 +45,7 @@ class TagQuerylet class ImgQuerylet { - /** @var \Querylet */ + /** @var Querylet */ public $qlet; /** @var bool */ public $positive; diff --git a/core/userclass.php b/core/userclass.php index 862b4194..de781aa2 100644 --- a/core/userclass.php +++ b/core/userclass.php @@ -12,12 +12,12 @@ class UserClass { /** - * @var null|string + * @var ?string */ public $name = null; /** - * @var \UserClass|null + * @var ?UserClass */ public $parent = null; diff --git a/core/util.php b/core/util.php index b5908246..4481729e 100644 --- a/core/util.php +++ b/core/util.php @@ -216,7 +216,7 @@ function transload(string $url, string $mfile): ?array $s_mfile = escapeshellarg($mfile); system("wget --no-check-certificate $s_url --output-document=$s_mfile"); - return file_exists($mfile); + return file_exists($mfile) ? ["ok"=>"true"] : null; } if ($config->get_string("transload_engine") === "fopen") { diff --git a/ext/admin/main.php b/ext/admin/main.php index 05722392..4ca59eb7 100644 --- a/ext/admin/main.php +++ b/ext/admin/main.php @@ -25,7 +25,7 @@ */ class AdminBuildingEvent extends Event { - /** @var \Page */ + /** @var Page */ public $page; public function __construct(Page $page) diff --git a/ext/artists/main.php b/ext/artists/main.php index bb1343d3..7a3f3377 100644 --- a/ext/artists/main.php +++ b/ext/artists/main.php @@ -10,9 +10,9 @@ */ class AuthorSetEvent extends Event { - /** @var \Image */ + /** @var Image */ public $image; - /** @var \User */ + /** @var User */ public $user; /** @var string */ public $author; diff --git a/ext/artists/theme.php b/ext/artists/theme.php index f9ebb745..825e2f1b 100644 --- a/ext/artists/theme.php +++ b/ext/artists/theme.php @@ -15,7 +15,7 @@ class ArtistsTheme extends Themelet "; } - public function sidebar_options(string $mode, ?int $artistID=null, $is_admin=false): bool + public function sidebar_options(string $mode, ?int $artistID=null, $is_admin=false): void { global $page, $user; diff --git a/ext/comment/main.php b/ext/comment/main.php index ba4b58e4..85a9672b 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -15,7 +15,7 @@ class CommentPostingEvent extends Event { /** @var int */ public $image_id; - /** @var \User */ + /** @var User */ public $user; /** @var string */ public $comment; diff --git a/ext/comment/theme.php b/ext/comment/theme.php index fb8532ef..a17131af 100644 --- a/ext/comment/theme.php +++ b/ext/comment/theme.php @@ -1,23 +1,9 @@ ct)) { - $this->ct = hsl_rainbow(); - } - if (!array_key_exists($ip, $this->anon_map)) { - $this->anon_map[$ip] = $this->ct[$this->anon_cid++ % count($this->ct)]; - } - return $this->anon_map[$ip]; - } /** * Display a page with a list of images, and for each image, the image's comments. diff --git a/ext/cron_uploader/main.php b/ext/cron_uploader/main.php index 1af4a68b..4076ac56 100644 --- a/ext/cron_uploader/main.php +++ b/ext/cron_uploader/main.php @@ -340,7 +340,7 @@ class CronUploader extends Extension $img->set_tags(Tag::explode($tags)); } - private function generate_image_queue($base = "", $subdir = "") + private function generate_image_queue(string $base = "", string $subdir = ""): void { if ($base == "") { $base = $this->root_dir . "/queue"; @@ -348,7 +348,7 @@ class CronUploader extends Extension if (! is_dir($base)) { $this->add_upload_info("Image Queue Directory could not be found at \"$base\"."); - return []; + return; } foreach (glob("$base/$subdir/*") as $fullpath) { diff --git a/ext/favorites/main.php b/ext/favorites/main.php index 4dc2df1f..1ccf2031 100644 --- a/ext/favorites/main.php +++ b/ext/favorites/main.php @@ -17,7 +17,7 @@ class FavoriteSetEvent extends Event { /** @var int */ public $image_id; - /** @var \User */ + /** @var User */ public $user; /** @var bool */ public $do_set; diff --git a/ext/handle_pixel/main.php b/ext/handle_pixel/main.php index db1c56f8..6d196910 100644 --- a/ext/handle_pixel/main.php +++ b/ext/handle_pixel/main.php @@ -136,15 +136,6 @@ class PixelFileHandler extends DataHandlerExtension return true; } // }}} - // epeg thumber {{{ - private function make_thumb_epeg(string $inname, string $outname): bool - { - global $config; - $w = $config->get_int("thumb_width"); - exec("epeg $inname -c 'Created by EPEG' --max $w $outname"); - return true; - } - // }}} // GD thumber {{{ private function make_thumb_gd(string $inname, string $outname): bool { diff --git a/ext/index/main.php b/ext/index/main.php index 91b6c5d1..f8d77843 100644 --- a/ext/index/main.php +++ b/ext/index/main.php @@ -164,7 +164,7 @@ class SearchTermParseEvent extends Event public $term = null; /** @var string[] */ public $context = []; - /** @var \Querylet[] */ + /** @var Querylet[] */ public $querylets = []; public function __construct(string $term=null, array $context=[]) diff --git a/ext/pools/theme.php b/ext/pools/theme.php index 2dd12045..72829d88 100644 --- a/ext/pools/theme.php +++ b/ext/pools/theme.php @@ -120,7 +120,7 @@ class PoolsTheme extends Themelet $page->add_block(new Block("Create Pool", $create_html, "main", 20)); } - private function display_top(array $pools=null, string $heading, bool $check_all=false) + private function display_top(?array $pools, string $heading, bool $check_all=false) { global $page, $user; @@ -361,7 +361,9 @@ class PoolsTheme extends Themelet $prefix = "+"; } elseif ($history['action'] == 0) { $prefix = "-"; - } + } else { + throw new Exception("history['action'] not in {0, 1}"); + } $images = trim($history['images']); $images = explode(" ", $images); diff --git a/ext/rating/main.php b/ext/rating/main.php index 7d5d9468..e15fcd16 100644 --- a/ext/rating/main.php +++ b/ext/rating/main.php @@ -21,7 +21,7 @@ class RatingSetEvent extends Event { - /** @var \Image */ + /** @var Image */ public $image; /** @var string */ public $rating; diff --git a/ext/rule34/main.php b/ext/rule34/main.php index 8ed086a6..2d321e79 100644 --- a/ext/rule34/main.php +++ b/ext/rule34/main.php @@ -123,10 +123,8 @@ class Rule34 extends Extension } } - if ($aae->redirect) { - $page->set_mode("redirect"); - $page->set_redirect(make_link("admin")); - } + $page->set_mode("redirect"); + $page->set_redirect(make_link("admin")); } } diff --git a/ext/rule34/theme.php b/ext/rule34/theme.php index b880a759..09712b3d 100644 --- a/ext/rule34/theme.php +++ b/ext/rule34/theme.php @@ -2,7 +2,7 @@ class Rule34Theme extends Themelet { - public function show_comic_changer(User $duser, bool $current_state): string + public function show_comic_changer(User $duser, bool $current_state): void { global $page; $checked = $current_state ? 'checked="checked"' : ''; @@ -15,7 +15,7 @@ class Rule34Theme extends Themelet $page->add_block(new Block("Rule34 Comic Options", $html)); } - public function display_bans(Page $page, $bans) + public function display_bans(Page $page, array $bans) { global $database, $user; $h_bans = ""; diff --git a/ext/setup/main.php b/ext/setup/main.php index 32a7b349..b316c975 100644 --- a/ext/setup/main.php +++ b/ext/setup/main.php @@ -13,7 +13,7 @@ */ class ConfigSaveEvent extends Event { - /** @var \Config */ + /** @var Config */ public $config; public function __construct(Config $config) @@ -28,7 +28,7 @@ class ConfigSaveEvent extends Event */ class SetupBuildingEvent extends Event { - /** @var \SetupPanel */ + /** @var SetupPanel */ public $panel; public function __construct(SetupPanel $panel) @@ -42,7 +42,7 @@ class SetupBuildingEvent extends Event */ class SetupPanel { - /** @var \SetupBlock[] */ + /** @var SetupBlock[] */ public $blocks = []; public function add_block(SetupBlock $block) diff --git a/ext/tag_categories/theme.php b/ext/tag_categories/theme.php index 50e6ef25..d8a15c8c 100644 --- a/ext/tag_categories/theme.php +++ b/ext/tag_categories/theme.php @@ -2,9 +2,6 @@ class TagCategoriesTheme extends Themelet { - private $heading = ""; - private $list = ""; - public function show_tag_categories($page, $tc_dict) { $tc_block_index = 0; diff --git a/ext/tag_edit/main.php b/ext/tag_edit/main.php index 978b8a3f..8a74750a 100644 --- a/ext/tag_edit/main.php +++ b/ext/tag_edit/main.php @@ -48,9 +48,9 @@ */ class OwnerSetEvent extends Event { - /** @var \Image */ + /** @var Image */ public $image; - /** @var \User */ + /** @var User */ public $owner; public function __construct(Image $image, User $owner) @@ -63,7 +63,7 @@ class OwnerSetEvent extends Event class SourceSetEvent extends Event { - /** @var \Image */ + /** @var Image */ public $image; /** @var string */ public $source; @@ -78,7 +78,7 @@ class SourceSetEvent extends Event class TagSetEvent extends Event { - /** @var \Image */ + /** @var Image */ public $image; public $tags; public $metatags; @@ -116,7 +116,7 @@ class TagSetEvent extends Event class LockSetEvent extends Event { - /** @var \Image */ + /** @var Image */ public $image; /** @var bool */ public $locked; diff --git a/ext/tagger/main.php b/ext/tagger/main.php index 69dc5f62..e7a9148e 100644 --- a/ext/tagger/main.php +++ b/ext/tagger/main.php @@ -140,7 +140,7 @@ class TaggerXML extends Extension return $result.""; } - private function tag_to_xml(string $tag): string + private function tag_to_xml(PDORow $tag): string { return "".htmlentities( $value ) ."
"; return "--- $value\n"; break; + + default: + throw new Exception("stat needs to be =, + or -"); } } // }}} diff --git a/themes/danbooru/index.theme.php b/themes/danbooru/index.theme.php index ffff72ac..ef59ef69 100644 --- a/themes/danbooru/index.theme.php +++ b/themes/danbooru/index.theme.php @@ -53,7 +53,7 @@ class CustomIndexTheme extends IndexTheme return $h_search; } - protected function build_table(array $images, string $query): string + protected function build_table(array $images, ?string $query): string { $h_query = html_escape($query); $table = "
"; diff --git a/themes/danbooru2/comment.theme.php b/themes/danbooru2/comment.theme.php index c817fa09..f043f445 100644 --- a/themes/danbooru2/comment.theme.php +++ b/themes/danbooru2/comment.theme.php @@ -2,7 +2,7 @@ class CustomCommentListTheme extends CommentListTheme { - public function display_comment_list($images, $page_number, $total_pages, $can_post) + public function display_comment_list(array $images, int $page_number, int $total_pages, bool $can_post) { global $config, $page, $user; @@ -82,13 +82,13 @@ class CustomCommentListTheme extends CommentListTheme } } - public function display_recent_comments($comments) + public function display_recent_comments(array $comments) { // no recent comments in this theme } - protected function comment_to_html(Comment $comment, $trim=false) + protected function comment_to_html(Comment $comment, bool $trim=false): string { global $user; diff --git a/themes/danbooru2/index.theme.php b/themes/danbooru2/index.theme.php index e14202e9..51455d43 100644 --- a/themes/danbooru2/index.theme.php +++ b/themes/danbooru2/index.theme.php @@ -56,7 +56,7 @@ class CustomIndexTheme extends IndexTheme /** * #param Image[] $images */ - protected function build_table(array $images, string $query): string + protected function build_table(array $images, ?string $query): string { $h_query = html_escape($query); $table = "
"; diff --git a/themes/futaba/comment.theme.php b/themes/futaba/comment.theme.php index c871438c..2fd0a6ad 100644 --- a/themes/futaba/comment.theme.php +++ b/themes/futaba/comment.theme.php @@ -4,7 +4,7 @@ class CustomCommentListTheme extends CommentListTheme { public $inner_id = 0; - public function display_comment_list($images, $page_number, $total_pages, $can_post) + public function display_comment_list(array $images, int $page_number, int $total_pages, bool $can_post) { global $config, $page; @@ -49,7 +49,7 @@ class CustomCommentListTheme extends CommentListTheme } } - public function display_recent_comments($comments) + public function display_recent_comments(array $comments) { // sidebar fails in this theme } @@ -60,7 +60,7 @@ class CustomCommentListTheme extends CommentListTheme } - protected function comment_to_html(Comment $comment, $trim=false) + protected function comment_to_html(Comment $comment, bool $trim=false): string { $inner_id = $this->inner_id; // because custom themes can't add params, because PHP global $user; diff --git a/themes/futaba/themelet.class.php b/themes/futaba/themelet.class.php index 2e4c7a28..b84d3aae 100644 --- a/themes/futaba/themelet.class.php +++ b/themes/futaba/themelet.class.php @@ -5,7 +5,7 @@ class Themelet extends BaseThemelet /** * Add a generic paginator. */ - public function display_paginator(Page $page, string $base, string $query, int $page_number, int $total_pages, bool $show_random = false) + public function display_paginator(Page $page, string $base, ?string $query, int $page_number, int $total_pages, bool $show_random = false) { if ($total_pages == 0) { $total_pages = 1; diff --git a/themes/lite/themelet.class.php b/themes/lite/themelet.class.php index d96302ff..ef64903d 100644 --- a/themes/lite/themelet.class.php +++ b/themes/lite/themelet.class.php @@ -18,7 +18,7 @@ class Themelet extends BaseThemelet "; } - public function display_paginator(Page $page, string $base, string $query, int $page_number, int $total_pages, bool $show_random = false) + public function display_paginator(Page $page, string $base, ?string $query, int $page_number, int $total_pages, bool $show_random = false) { if ($total_pages == 0) { $total_pages = 1; @@ -27,7 +27,7 @@ class Themelet extends BaseThemelet $page->add_block(new Block(null, $body, "main", 90)); } - public function litetheme_gen_page_link(string $base_url, string $query, string $page, string $name, ?string $link_class=null): string + public function litetheme_gen_page_link(string $base_url, ?string $query, string $page, string $name, ?string $link_class=null): string { $link = make_link("$base_url/$page", $query); return "$name";