diff --git a/core/imageboard/image.php b/core/imageboard/image.php index 68ccd612..46b514bb 100644 --- a/core/imageboard/image.php +++ b/core/imageboard/image.php @@ -559,6 +559,8 @@ class Image { * Set the tags for this image. */ public function set_tags(array $unfiltered_tags) { + global $database; + $tags = []; foreach ($unfiltered_tags as $tag) { if(mb_strlen($tag, 'UTF-8') > 255){ @@ -572,8 +574,6 @@ class Image { $tags[] = $tag; } - assert('count($tags) > 0', var_export($tags, true)); - global $database; if(count($tags) <= 0) { throw new SCoreException('Tried to set zero tags'); @@ -916,7 +916,7 @@ class Image { } } - assert('$positive_tag_id_array || $negative_tag_id_array', @$_GET['q']); + assert($positive_tag_id_array || $negative_tag_id_array, @$_GET['q']); $wheres = array(); if (!empty($positive_tag_id_array)) { $positive_tag_id_list = join(', ', $positive_tag_id_array); diff --git a/core/polyfills.php b/core/polyfills.php index 9e867cfd..3a19e636 100644 --- a/core/polyfills.php +++ b/core/polyfills.php @@ -546,7 +546,7 @@ function clamp(int $val, int $min=null, int $max=null): int { $val = $max; } if(!is_null($min) && !is_null($max)) { - assert('$val >= $min && $val <= $max', "$min <= $val <= $max"); + assert($val >= $min && $val <= $max, "$min <= $val <= $max"); } return $val; } diff --git a/core/util.php b/core/util.php index cd06b8d9..965b56a3 100644 --- a/core/util.php +++ b/core/util.php @@ -389,6 +389,8 @@ function _sanitise_environment() { date_default_timezone_set(TIMEZONE); } + ini_set('zend.assertions', 1); // generate assertions + ini_set('assert.exception', 1); // throw exceptions when failed if(DEBUG) { error_reporting(E_ALL); assert_options(ASSERT_ACTIVE, 1); diff --git a/ext/cron_uploader/main.php b/ext/cron_uploader/main.php index a9b05650..ab7b50a7 100644 --- a/ext/cron_uploader/main.php +++ b/ext/cron_uploader/main.php @@ -304,14 +304,9 @@ class CronUploader extends Extension { /** * Generate the necessary DataUploadEvent for a given image and tags. - * - * @param string $tmpname - * @param string $filename - * @param string $tags */ - private function add_image($tmpname, $filename, $tags) { + private function add_image(string $tmpname, string $filename, string $tags) { assert ( file_exists ( $tmpname ) ); - assert('is_string($tags)'); $pathinfo = pathinfo ( $filename ); if (! array_key_exists ( 'extension', $pathinfo )) { diff --git a/ext/livefeed/main.php b/ext/livefeed/main.php index 5e58226e..79874b45 100644 --- a/ext/livefeed/main.php +++ b/ext/livefeed/main.php @@ -48,12 +48,8 @@ class LiveFeed extends Extension { public function get_priority(): int {return 99;} - /** - * @param string $data - */ - private function msg($data) { + private function msg(string $data) { global $config; - assert('is_string($data)'); $host = $config->get_string("livefeed_host", "127.0.0.1:25252"); diff --git a/ext/tag_edit/main.php b/ext/tag_edit/main.php index c90420c1..05cf6752 100644 --- a/ext/tag_edit/main.php +++ b/ext/tag_edit/main.php @@ -342,14 +342,7 @@ class TagEdit extends Extension { } } - /** - * @param string $tags - * @param string $source - */ - private function mass_source_edit($tags, $source) { - assert('is_string($tags)'); - assert('is_string($source)'); - + private function mass_source_edit(string $tags, string $source) { $tags = Tag::explode($tags); $last_id = -1; diff --git a/ext/tag_history/main.php b/ext/tag_history/main.php index 75b19403..209e17d5 100644 --- a/ext/tag_history/main.php +++ b/ext/tag_history/main.php @@ -353,9 +353,8 @@ class Tag_History extends Extension { * @param Image $image * @param string[] $tags */ - private function add_tag_history(Image $image, $tags) { + private function add_tag_history(Image $image, array $tags) { global $database, $config, $user; - assert('is_array($tags)'); $new_tags = Tag::implode($tags); $old_tags = $image->get_tag_list(); diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index 711d2d40..1be00b33 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -494,9 +494,8 @@ class TagList extends Extension { * @param Page $page * @param string[] $search */ - private function add_refine_block(Page $page, $search) { + private function add_refine_block(Page $page, array $search) { global $database, $config; - assert('is_array($search)'); $wild_tags = $search; $str_search = Tag::implode($search); diff --git a/ext/upload/main.php b/ext/upload/main.php index ce6abe3f..5ac90ac3 100644 --- a/ext/upload/main.php +++ b/ext/upload/main.php @@ -24,16 +24,15 @@ class DataUploadEvent extends Event { /** * Some data is being uploaded. * This should be caught by a file handler. - * -- Removed: param $user The user uploading the data. * @param string $tmpname The temporary file used for upload. * @param array $metadata Info about the file, should contain at least "filename", "extension", "tags" and "source". */ public function __construct(string $tmpname, array $metadata) { - assert('file_exists($tmpname)'); - assert('is_string($metadata["filename"])'); - assert('is_string($metadata["extension"])'); - assert('is_array($metadata["tags"])'); - assert('is_string($metadata["source"]) || is_null($metadata["source"])'); + assert(file_exists($tmpname)); + assert(is_string($metadata["filename"])); + assert(is_string($metadata["extension"])); + assert(is_array($metadata["tags"])); + assert(is_string($metadata["source"]) || is_null($metadata["source"])); $this->tmpname = $tmpname; @@ -298,12 +297,8 @@ class Upload extends Extension { * @param int $replace * @return bool TRUE on upload successful. */ - private function try_upload($file, $tags, $source, $replace=-1) { + private function try_upload(array $file, array $tags, string $source=null, int $replace=-1): bool { global $page; - assert('is_array($file)'); - assert('is_array($tags)'); - assert('is_string($source) || is_null($source)'); - assert('is_int($replace)'); if(empty($source)) $source = null; @@ -346,21 +341,8 @@ class Upload extends Extension { return $ok; } - /** - * Handle an transload. - * - * @param string $url - * @param string[] $tags - * @param string|null $source - * @param int $replace - * @return bool Returns TRUE on transload successful. - */ - private function try_transload($url, $tags, $source, $replace=-1) { + private function try_transload(string $url, array $tags, string $source=null, int $replace=-1): bool { global $page, $config, $user; - assert('is_string($url)'); - assert('is_array($tags)'); - assert('is_string($source) || is_null($source)'); - assert('is_int($replace)'); $ok = true;