[core,tests] even more types

This commit is contained in:
Shish 2024-01-15 13:40:18 +00:00
parent 2688843d80
commit 802ff336a2
16 changed files with 31 additions and 51 deletions

View file

@ -82,7 +82,7 @@ abstract class Extension
} }
} }
public static function is_enabled(string $key): ?bool public static function is_enabled(string $key): bool
{ {
return in_array($key, self::$enabled_extensions); return in_array($key, self::$enabled_extensions);
} }

View file

@ -182,9 +182,6 @@ class Search
} }
} }
} }
if (is_null($total)) {
return 0;
}
return $total; return $total;
} }

View file

@ -30,10 +30,6 @@ class TagUsage
{ {
global $cache, $database; global $cache, $database;
if (!$search) {
return [];
}
$search = strtolower($search); $search = strtolower($search);
if ( if (
$search == '' || $search == '' ||

View file

@ -202,13 +202,9 @@ class User
{ {
global $database; global $database;
$hash = password_hash($password, PASSWORD_BCRYPT); $hash = password_hash($password, PASSWORD_BCRYPT);
if (is_string($hash)) { $this->passhash = $hash;
$this->passhash = $hash; $database->execute("UPDATE users SET pass=:hash WHERE id=:id", ["hash" => $this->passhash, "id" => $this->id]);
$database->execute("UPDATE users SET pass=:hash WHERE id=:id", ["hash" => $this->passhash, "id" => $this->id]); log_info("core-user", 'Set password for '.$this->name);
log_info("core-user", 'Set password for '.$this->name);
} else {
throw new SCoreException("Failed to hash password");
}
} }
public function set_email(string $address): void public function set_email(string $address): void

View file

@ -615,7 +615,7 @@ function _set_up_shimmie_environment(): void
// The trace system has a certain amount of memory consumption every time it is used, // The trace system has a certain amount of memory consumption every time it is used,
// so to prevent running out of memory during complex operations code that uses it should // so to prevent running out of memory during complex operations code that uses it should
// check if tracer output is enabled before making use of it. // check if tracer output is enabled before making use of it.
$tracer_enabled = constant('TRACE_FILE') !== null; $tracer_enabled = !is_null('TRACE_FILE');
} }

View file

@ -605,7 +605,7 @@ class Artists extends Extension
$i = 0; $i = 0;
$urlsAsString = str_replace("\r\n", "\n", $urlsAsString); $urlsAsString = str_replace("\r\n", "\n", $urlsAsString);
$urlsAsString = str_replace("\n\r", "\n", $urlsAsString); $urlsAsString = str_replace("\n\r", "\n", $urlsAsString);
$urlsAsArray = is_null($urlsAsString) ? [] : explode("\n", $urlsAsString); $urlsAsArray = empty($urlsAsString) ? [] : explode("\n", $urlsAsString);
$urlsIDsAsArray = is_null($urlsIDsAsString) ? [] : explode(" ", $urlsIDsAsString); $urlsIDsAsArray = is_null($urlsIDsAsString) ? [] : explode(" ", $urlsIDsAsString);
while ($i < count($urlsAsArray)) { while ($i < count($urlsAsArray)) {
// if an URL was updated // if an URL was updated

View file

@ -31,10 +31,6 @@ class AutoComplete extends Extension
{ {
global $cache, $database; global $cache, $database;
if (!$search) {
return [];
}
$search = strtolower($search); $search = strtolower($search);
if ( if (
$search == '' || $search == '' ||

View file

@ -265,7 +265,6 @@ class DanbooruApi extends Extension
private function api_add_post(): void private function api_add_post(): void
{ {
global $database, $user, $page; global $database, $user, $page;
$danboorup_kludge = 1; // danboorup for firefox makes broken links out of location: /path
// Check first if a login was supplied, if it wasn't check if the user is logged in via cookie // Check first if a login was supplied, if it wasn't check if the user is logged in via cookie
// If all that fails, it's an anonymous upload // If all that fails, it's an anonymous upload
@ -331,9 +330,7 @@ class DanbooruApi extends Extension
$page->set_code(409); $page->set_code(409);
$page->add_http_header("X-Danbooru-Errors: duplicate"); $page->add_http_header("X-Danbooru-Errors: duplicate");
$existinglink = make_link("post/view/" . $existing->id); $existinglink = make_link("post/view/" . $existing->id);
if ($danboorup_kludge) { $existinglink = make_http($existinglink);
$existinglink = make_http($existinglink);
}
$page->add_http_header("X-Danbooru-Location: $existinglink"); $page->add_http_header("X-Danbooru-Location: $existinglink");
return; return;
} }
@ -356,9 +353,7 @@ class DanbooruApi extends Extension
}); });
$newid = make_link("post/view/" . $newimg->id); $newid = make_link("post/view/" . $newimg->id);
if ($danboorup_kludge) { $newid = make_http($newid);
$newid = make_http($newid);
}
// Did we POST or GET this call? // Did we POST or GET this call?
if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($_SERVER['REQUEST_METHOD'] == 'POST') {

View file

@ -146,9 +146,7 @@ class GraphQL extends Extension
private static function handle_upload(int $n, string $common_tags, string $common_source): array private static function handle_upload(int $n, string $common_tags, string $common_source): array
{ {
if (!empty($_POST["url$n"])) { if (!empty($_POST["url$n"])) {
return ["error" => "URLs not handled yet"]; throw new \Exception("URLs not handled yet");
$tmpname = "...";
$filename = "...";
} else { } else {
$ec = $_FILES["data$n"]["error"]; $ec = $_FILES["data$n"]["error"];
switch($ec) { switch($ec) {

View file

@ -331,7 +331,7 @@ class OuroborosAPI extends Extension
} }
} }
$meta = []; $meta = [];
$meta['tags'] = is_array($post->tags) ? $post->tags : Tag::explode($post->tags); $meta['tags'] = Tag::explode($post->tags);
$meta['source'] = $post->source; $meta['source'] = $post->source;
if (Extension::is_enabled(RatingsInfo::KEY) !== false) { if (Extension::is_enabled(RatingsInfo::KEY) !== false) {
$meta['rating'] = $post->rating; $meta['rating'] = $post->rating;
@ -365,7 +365,7 @@ class OuroborosAPI extends Extension
if (!is_null($img)) { if (!is_null($img)) {
$handler = $config->get_string(ImageConfig::UPLOAD_COLLISION_HANDLER); $handler = $config->get_string(ImageConfig::UPLOAD_COLLISION_HANDLER);
if ($handler == ImageConfig::COLLISION_MERGE) { if ($handler == ImageConfig::COLLISION_MERGE) {
$postTags = is_array($post->tags) ? $post->tags : Tag::explode($post->tags); $postTags = Tag::explode($post->tags);
$merged = array_merge($postTags, $img->get_tag_array()); $merged = array_merge($postTags, $img->get_tag_array());
send_event(new TagSetEvent($img, $merged)); send_event(new TagSetEvent($img, $merged));

View file

@ -737,19 +737,19 @@ class Pools extends Extension
return; return;
} }
$images = " "; $images = [];
foreach ($event->posts as $post_id) { foreach ($event->posts as $post_id) {
if ($this->add_post($event->pool_id, $post_id, false)) { if ($this->add_post($event->pool_id, $post_id, false)) {
$images .= " " . $post_id; $images[] = $post_id;
} }
} }
if (!strlen($images) == 0) { if (count($images) > 0) {
$count = (int)$database->get_one( $count = (int)$database->get_one(
"SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid", "SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid",
["pid" => $event->pool_id] ["pid" => $event->pool_id]
); );
$this->add_history($event->pool_id, 1, $images, $count); $this->add_history($event->pool_id, 1, implode(" ", $images), $count);
} }
} }

View file

@ -104,9 +104,6 @@ class RotateImage extends Extension
$image_obj = Image::by_id($image_id); $image_obj = Image::by_id($image_id);
$hash = $image_obj->hash; $hash = $image_obj->hash;
if (is_null($hash)) {
throw new ImageRotateException("Post does not have a hash associated with it.");
}
$image_filename = warehouse_path(Image::IMAGE_DIR, $hash); $image_filename = warehouse_path(Image::IMAGE_DIR, $hash);
if (file_exists($image_filename) === false) { if (file_exists($image_filename) === false) {

View file

@ -45,7 +45,11 @@ class StatsDInterface extends Extension
$this->_stats("other"); $this->_stats("other");
} }
$this->send(StatsDInterface::$stats, 1.0); // @phpstan-ignore-next-line
if (STATSD_HOST) {
$this->send(STATSD_HOST, StatsDInterface::$stats, 1.0);
}
StatsDInterface::$stats = []; StatsDInterface::$stats = [];
} }
@ -74,12 +78,8 @@ class StatsDInterface extends Extension
return 99; return 99;
} }
private function send(array $data, float $sampleRate = 1) private function send(string $host, array $data, float $sampleRate = 1)
{ {
if (!STATSD_HOST) {
return;
}
// sampling // sampling
$sampledData = []; $sampledData = [];
@ -99,7 +99,7 @@ class StatsDInterface extends Extension
// Wrap this in a try/catch - failures in any of this should be silently ignored // Wrap this in a try/catch - failures in any of this should be silently ignored
try { try {
$parts = explode(":", STATSD_HOST); $parts = explode(":", $host);
$host = $parts[0]; $host = $parts[0];
$port = (int)$parts[1]; $port = (int)$parts[1];
$fp = fsockopen("udp://$host", $port, $errno, $errstr); $fp = fsockopen("udp://$host", $port, $errno, $errstr);

View file

@ -160,7 +160,7 @@ class TagList extends Extension
$results = $cache->get("tag_list_omitted_tags:".$tags_config); $results = $cache->get("tag_list_omitted_tags:".$tags_config);
if (is_null($results)) { if (is_null($results)) {
$tags = explode(" ", $tags_config); $tags = Tag::explode($tags_config, false);
if (count($tags) == 0) { if (count($tags) == 0) {
return []; return [];

View file

@ -407,9 +407,6 @@ class Upload extends Extension
if (count($event->images) == 0) { if (count($event->images) == 0) {
throw new UploadException("File type not supported: " . $event->mime); throw new UploadException("File type not supported: " . $event->mime);
} }
if (count($event->images) == 0) {
throw new UploadException("File type not supported: " . $event->mime);
}
return $event->images; return $event->images;
}); });
foreach($new_images as $image) { foreach($new_images as $image) {

View file

@ -8,3 +8,11 @@ parameters:
- ../themes - ../themes
ignoreErrors: ignoreErrors:
- '#Access to an undefined property Shimmie2\\Image::\$#' - '#Access to an undefined property Shimmie2\\Image::\$#'
dynamicConstantNames:
- DEBUG
- SPEED_HAX
- TRUSTED_PROXIES
- TIMEZONE
- BASE_HREF
- STATSD_HOST
- TRACE_FILE