From 93cc732d398ec131eb4f26b5f2e7901b14918e6a Mon Sep 17 00:00:00 2001 From: Shish Date: Tue, 28 May 2019 19:00:23 +0100 Subject: [PATCH] fix tests --- core/config.php | 30 +++++++++++++++--------------- core/database.php | 5 ++++- core/imageboard/image.php | 2 +- core/polyfills.php | 10 ++++++++-- ext/index/theme.php | 2 +- ext/shimmie_api/main.php | 2 +- 6 files changed, 30 insertions(+), 21 deletions(-) diff --git a/core/config.php b/core/config.php index 889265c4..209e4f55 100644 --- a/core/config.php +++ b/core/config.php @@ -113,74 +113,74 @@ abstract class BaseConfig implements Config { public $values = []; - public function set_int(string $name, $value) + public function set_int(string $name, ?int $value): void { $this->values[$name] = parse_shorthand_int($value); $this->save($name); } - public function set_string(string $name, $value) + public function set_string(string $name, ?string $value): void { $this->values[$name] = $value; $this->save($name); } - public function set_bool(string $name, $value) + public function set_bool(string $name, $value): void { $this->values[$name] = bool_escape($value) ? 'Y' : 'N'; $this->save($name); } - public function set_array(string $name, array $value) + public function set_array(string $name, array $value): void { $this->values[$name] = implode(",", $value); $this->save($name); } - public function set_default_int(string $name, int $value) + public function set_default_int(string $name, int $value): void { if (is_null($this->get($name))) { $this->values[$name] = $value; } } - public function set_default_string(string $name, string $value) + public function set_default_string(string $name, string $value): void { if (is_null($this->get($name))) { $this->values[$name] = $value; } } - public function set_default_bool(string $name, bool $value) + public function set_default_bool(string $name, bool $value): void { if (is_null($this->get($name))) { $this->values[$name] = $value ? 'Y' : 'N'; } } - public function set_default_array(string $name, array $value) + public function set_default_array(string $name, array $value): void { if (is_null($this->get($name))) { $this->values[$name] = implode(",", $value); } } - public function get_int(string $name, $default=null) + public function get_int(string $name, $default=null): ?int { return (int)($this->get($name, $default)); } - public function get_string(string $name, $default=null) + public function get_string(string $name, $default=null): ?string { return $this->get($name, $default); } - public function get_bool(string $name, $default=null) + public function get_bool(string $name, $default=null): ?bool { return bool_escape($this->get($name, $default)); } - public function get_array(string $name, array $default=[]): array + public function get_array(string $name, ?array $default=[]): ?array { return explode(",", $this->get($name, "")); } @@ -208,7 +208,7 @@ class HardcodeConfig extends BaseConfig $this->values = $dict; } - public function save(string $name=null) + public function save(string $name=null): void { // static config is static } @@ -242,7 +242,7 @@ class StaticConfig extends BaseConfig } } - public function save(string $name=null) + public function save(string $name=null): void { // static config is static } @@ -283,7 +283,7 @@ class DatabaseConfig extends BaseConfig } } - public function save(string $name=null) + public function save(string $name=null): void { if (is_null($name)) { reset($this->values); // rewind the array to the first element diff --git a/core/database.php b/core/database.php index 9dd63b9e..dbeb50a1 100644 --- a/core/database.php +++ b/core/database.php @@ -369,6 +369,7 @@ class MockDatabase extends Database ); return $this->responses[$this->query_id++]; } + public function _execute(string $query, array $params=[]) { log_debug( @@ -410,9 +411,11 @@ class MockDatabase extends Database { return $sql; } - public function create_table(string $name, string $def) + + public function create_table(string $name, string $def): void { } + public function connect_engine() { } diff --git a/core/imageboard/image.php b/core/imageboard/image.php index 8c9e32c0..415d961a 100644 --- a/core/imageboard/image.php +++ b/core/imageboard/image.php @@ -485,7 +485,7 @@ class Image /** * Get the image's source URL */ - public function get_source(): string + public function get_source(): ?string { return $this->source; } diff --git a/core/polyfills.php b/core/polyfills.php index 21a27031..a1e135ef 100644 --- a/core/polyfills.php +++ b/core/polyfills.php @@ -391,8 +391,11 @@ function endsWith(string $haystack, string $needle): bool /** * Make some data safe for printing into HTML */ -function html_escape(string $input): string +function html_escape(?string $input): string { + if (is_null($input)) { + return ""; + } return htmlentities($input, ENT_QUOTES, "UTF-8"); } @@ -407,12 +410,15 @@ function html_unescape(string $input): string /** * Make sure some data is safe to be used in integer context */ -function int_escape(string $input): int +function int_escape(?string $input): int { /* Side note, Casting to an integer is FASTER than using intval. http://hakre.wordpress.com/2010/05/13/php-casting-vs-intval/ */ + if (is_null($input)) { + return 0; + } return (int)$input; } diff --git a/ext/index/theme.php b/ext/index/theme.php index 66195087..5b58d627 100644 --- a/ext/index/theme.php +++ b/ext/index/theme.php @@ -91,7 +91,7 @@ and of course start organising your images :-) /** * #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/ext/shimmie_api/main.php b/ext/shimmie_api/main.php index 317fae7b..ed5a3e1c 100644 --- a/ext/shimmie_api/main.php +++ b/ext/shimmie_api/main.php @@ -109,7 +109,7 @@ class ShimmieApi extends Extension /** * #return string[] */ - private function api_get_tags(string $arg): array + private function api_get_tags(?string $arg): array { global $database; if (!empty($arg)) {