fix tests

This commit is contained in:
Shish 2019-05-28 19:00:23 +01:00
parent 34b05cca7c
commit 93cc732d39
6 changed files with 30 additions and 21 deletions

View file

@ -113,74 +113,74 @@ abstract class BaseConfig implements Config
{ {
public $values = []; 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->values[$name] = parse_shorthand_int($value);
$this->save($name); $this->save($name);
} }
public function set_string(string $name, $value) public function set_string(string $name, ?string $value): void
{ {
$this->values[$name] = $value; $this->values[$name] = $value;
$this->save($name); $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->values[$name] = bool_escape($value) ? 'Y' : 'N';
$this->save($name); $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->values[$name] = implode(",", $value);
$this->save($name); $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))) { if (is_null($this->get($name))) {
$this->values[$name] = $value; $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))) { if (is_null($this->get($name))) {
$this->values[$name] = $value; $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))) { if (is_null($this->get($name))) {
$this->values[$name] = $value ? 'Y' : 'N'; $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))) { if (is_null($this->get($name))) {
$this->values[$name] = implode(",", $value); $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)); 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); 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)); 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, "")); return explode(",", $this->get($name, ""));
} }
@ -208,7 +208,7 @@ class HardcodeConfig extends BaseConfig
$this->values = $dict; $this->values = $dict;
} }
public function save(string $name=null) public function save(string $name=null): void
{ {
// static config is static // 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 // 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)) { if (is_null($name)) {
reset($this->values); // rewind the array to the first element reset($this->values); // rewind the array to the first element

View file

@ -369,6 +369,7 @@ class MockDatabase extends Database
); );
return $this->responses[$this->query_id++]; return $this->responses[$this->query_id++];
} }
public function _execute(string $query, array $params=[]) public function _execute(string $query, array $params=[])
{ {
log_debug( log_debug(
@ -410,9 +411,11 @@ class MockDatabase extends Database
{ {
return $sql; return $sql;
} }
public function create_table(string $name, string $def)
public function create_table(string $name, string $def): void
{ {
} }
public function connect_engine() public function connect_engine()
{ {
} }

View file

@ -485,7 +485,7 @@ class Image
/** /**
* Get the image's source URL * Get the image's source URL
*/ */
public function get_source(): string public function get_source(): ?string
{ {
return $this->source; return $this->source;
} }

View file

@ -391,8 +391,11 @@ function endsWith(string $haystack, string $needle): bool
/** /**
* Make some data safe for printing into HTML * 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"); 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 * 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. Side note, Casting to an integer is FASTER than using intval.
http://hakre.wordpress.com/2010/05/13/php-casting-vs-intval/ http://hakre.wordpress.com/2010/05/13/php-casting-vs-intval/
*/ */
if (is_null($input)) {
return 0;
}
return (int)$input; return (int)$input;
} }

View file

@ -91,7 +91,7 @@ and of course start organising your images :-)
/** /**
* #param Image[] $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); $h_query = html_escape($query);
$table = "<div class='shm-image-list' data-query='$h_query'>"; $table = "<div class='shm-image-list' data-query='$h_query'>";

View file

@ -109,7 +109,7 @@ class ShimmieApi extends Extension
/** /**
* #return string[] * #return string[]
*/ */
private function api_get_tags(string $arg): array private function api_get_tags(?string $arg): array
{ {
global $database; global $database;
if (!empty($arg)) { if (!empty($arg)) {