diff --git a/composer.json b/composer.json
index d45a0d2b..02a060d5 100644
--- a/composer.json
+++ b/composer.json
@@ -60,8 +60,8 @@
"ext-memcache": "memcache caching",
"ext-memcached": "memcached caching",
"ext-apc": "apc caching",
+ "ext-apcu": "apc caching",
"ext-redis": "redis caching",
- "ext-dom": "some extensions",
"ext-curl": "some extensions",
"ext-ctype": "some extensions",
"ext-json": "some extensions",
diff --git a/core/basethemelet.php b/core/basethemelet.php
index d6c4a222..2338d34f 100644
--- a/core/basethemelet.php
+++ b/core/basethemelet.php
@@ -138,8 +138,8 @@ class BaseThemelet
$next_html = $at_end ? "Next" : $this->gen_page_link($base_url, $query, $next, "Next");
$last_html = $at_end ? "Last" : $this->gen_page_link($base_url, $query, $total_pages, "Last");
- $start = $current_page-5 > 1 ? $current_page-5 : 1;
- $end = $start+10 < $total_pages ? $start+10 : $total_pages;
+ $start = max($current_page - 5, 1);
+ $end = min($start + 10, $total_pages);
$pages = [];
foreach (range($start, $end) as $i) {
diff --git a/core/cacheengine.php b/core/cacheengine.php
index 164b879e..44307588 100644
--- a/core/cacheengine.php
+++ b/core/cacheengine.php
@@ -27,15 +27,15 @@ class NoCache implements CacheEngine
class MemcachedCache implements CacheEngine
{
- public ?Memcached $memcache=null;
+ public ?\Memcached $memcache=null;
public function __construct(string $args)
{
$hp = explode(":", $args);
- $this->memcache = new Memcached();
- #$this->memcache->setOption(Memcached::OPT_COMPRESSION, False);
- #$this->memcache->setOption(Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_PHP);
- #$this->memcache->setOption(Memcached::OPT_PREFIX_KEY, phpversion());
+ $this->memcache = new \Memcached();
+ #$this->memcache->setOption(\Memcached::OPT_COMPRESSION, False);
+ #$this->memcache->setOption(\Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_PHP);
+ #$this->memcache->setOption(\Memcached::OPT_PREFIX_KEY, phpversion());
$this->memcache->addServer($hp[0], (int)$hp[1]);
}
@@ -46,9 +46,9 @@ class MemcachedCache implements CacheEngine
$val = $this->memcache->get($key);
$res = $this->memcache->getResultCode();
- if ($res == Memcached::RES_SUCCESS) {
+ if ($res == \Memcached::RES_SUCCESS) {
return $val;
- } elseif ($res == Memcached::RES_NOTFOUND) {
+ } elseif ($res == \Memcached::RES_NOTFOUND) {
return false;
} else {
error_log("Memcached error during get($key): $res");
@@ -62,7 +62,7 @@ class MemcachedCache implements CacheEngine
$this->memcache->set($key, $val, $time);
$res = $this->memcache->getResultCode();
- if ($res != Memcached::RES_SUCCESS) {
+ if ($res != \Memcached::RES_SUCCESS) {
error_log("Memcached error during set($key): $res");
}
}
@@ -73,7 +73,7 @@ class MemcachedCache implements CacheEngine
$this->memcache->delete($key);
$res = $this->memcache->getResultCode();
- if ($res != Memcached::RES_SUCCESS && $res != Memcached::RES_NOTFOUND) {
+ if ($res != \Memcached::RES_SUCCESS && $res != \Memcached::RES_NOTFOUND) {
error_log("Memcached error during delete($key): $res");
}
}
@@ -104,15 +104,15 @@ class APCCache implements CacheEngine
class RedisCache implements CacheEngine
{
- private Redis $redis;
+ private \Redis $redis;
public function __construct(string $args)
{
- $this->redis = new Redis();
+ $this->redis = new \Redis();
$hp = explode(":", $args);
$this->redis->pconnect($hp[0], (int)$hp[1]);
- $this->redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
- $this->redis->setOption(Redis::OPT_PREFIX, 'shm:');
+ $this->redis->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_PHP);
+ $this->redis->setOption(\Redis::OPT_PREFIX, 'shm:');
}
public function get(string $key)
diff --git a/core/captcha.php b/core/captcha.php
index d7390d7d..34b5af7b 100644
--- a/core/captcha.php
+++ b/core/captcha.php
@@ -27,7 +27,7 @@ function captcha_get_html(): string
";
} else {
session_start();
- $captcha = Securimage::getCaptchaHtml(['securimage_path' => './vendor/dapphp/securimage/']);
+ $captcha = \Securimage::getCaptchaHtml(['securimage_path' => './vendor/dapphp/securimage/']);
}
}
return $captcha;
@@ -53,7 +53,7 @@ function captcha_check(): bool
}
} else {
session_start();
- $securimg = new Securimage();
+ $securimg = new \Securimage();
if ($securimg->check($_POST['captcha_code']) === false) {
log_info("core", "Captcha failed (Securimage)");
return false;
diff --git a/core/command_builder.php b/core/command_builder.php
index 9c4519eb..34b4532e 100644
--- a/core/command_builder.php
+++ b/core/command_builder.php
@@ -16,7 +16,7 @@ class CommandBuilder
public function __construct(String $executable)
{
if (empty($executable)) {
- throw new InvalidArgumentException("executable cannot be empty");
+ throw new \InvalidArgumentException("executable cannot be empty");
}
$this->executable = $executable;
diff --git a/core/database.php b/core/database.php
index d9215cf0..eb4a060c 100644
--- a/core/database.php
+++ b/core/database.php
@@ -151,12 +151,17 @@ class Database
if (is_null($this->db)) {
$this->connect_db();
}
- return $this->db->execute(
+ $ret = $this->db->execute(
"-- " . str_replace("%2F", "/", urlencode($_GET['q'] ?? '')). "\n" .
$query,
$args
);
- } catch (PDOException $pdoe) {
+ if($ret === false) {
+ throw new SCoreException("Query failed", $query);
+ }
+ /** @noinspection PhpIncompatibleReturnTypeInspection */
+ return $ret;
+ } catch (\PDOException $pdoe) {
throw new SCoreException($pdoe->getMessage(), $query);
}
}
diff --git a/core/imageboard/image.php b/core/imageboard/image.php
index 1d30a2c9..85b8410e 100644
--- a/core/imageboard/image.php
+++ b/core/imageboard/image.php
@@ -746,7 +746,7 @@ class Image
VALUES(:iid, :tid)
", ["iid"=>$this->id, "tid"=>$id]);
- array_push($written_tags, $id);
+ $written_tags[] = $id;
}
$database->execute(
"
diff --git a/core/install.php b/core/install.php
index ee504573..b18c14f8 100644
--- a/core/install.php
+++ b/core/install.php
@@ -34,7 +34,7 @@ function install()
// Pull in necessary files
require_once "vendor/autoload.php";
global $_tracer;
- $_tracer = new EventTracer();
+ $_tracer = new \EventTracer();
require_once "core/exceptions.php";
require_once "core/cacheengine.php";
@@ -102,7 +102,7 @@ function ask_questions()
";
}
- $drivers = PDO::getAvailableDrivers();
+ $drivers = \PDO::getAvailableDrivers();
if (
!in_array(DatabaseDriverID::MYSQL->value, $drivers) &&
!in_array(DatabaseDriverID::PGSQL->value, $drivers) &&
@@ -292,7 +292,7 @@ function create_tables(Database $db)
if ($db->is_transaction_open()) {
$db->commit();
}
- } catch (PDOException $e) {
+ } catch (\PDOException $e) {
throw new InstallerException(
"PDO Error:",
"
An error occurred while trying to create the database tables necessary for Shimmie.
diff --git a/core/sanitize_php.php b/core/sanitize_php.php
index 80aebb3c..598d412b 100644
--- a/core/sanitize_php.php
+++ b/core/sanitize_php.php
@@ -9,6 +9,9 @@ namespace Shimmie2;
* be included right at the very start of index.php and tests/bootstrap.php
*/
+use JetBrains\PhpStorm\NoReturn;
+
+#[NoReturn]
function die_nicely($title, $body, $code=0)
{
print("
@@ -48,7 +51,7 @@ set_error_handler(function ($errNo, $errStr) {
// Should we turn ALL notices into errors? PHP allows a lot of
// terrible things to happen by default...
if (str_starts_with($errStr, 'Use of undefined constant ')) {
- throw new Exception("PHP Error#$errNo: $errStr");
+ throw new \Exception("PHP Error#$errNo: $errStr");
} else {
return false;
}
diff --git a/core/util.php b/core/util.php
index 1c2ecbeb..78f95e20 100644
--- a/core/util.php
+++ b/core/util.php
@@ -560,10 +560,6 @@ function get_debug_info(): string
* Request initialisation stuff *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-/** @privatesection
- * @noinspection PhpIncludeInspection
- */
-
function require_all(array $files): void
{
foreach ($files as $filename) {
diff --git a/ext/auto_tagger/main.php b/ext/auto_tagger/main.php
index 01a1f378..bd73a23d 100644
--- a/ext/auto_tagger/main.php
+++ b/ext/auto_tagger/main.php
@@ -220,7 +220,7 @@ class AutoTagger extends Extension
$existing_tags = Tag::explode($existing_tags);
foreach ($additional_tags as $t) {
if (!in_array(strtolower($t), $existing_tags)) {
- array_push($existing_tags, strtolower($t));
+ $existing_tags[] = strtolower($t);
}
}
diff --git a/ext/bulk_actions/main.php b/ext/bulk_actions/main.php
index d922ff79..00b5571b 100644
--- a/ext/bulk_actions/main.php
+++ b/ext/bulk_actions/main.php
@@ -297,7 +297,7 @@ class BulkActions extends Extension
try {
send_event(new SourceSetEvent($image, $source));
$total++;
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$page->flash("Error while setting source for {$image->id}: " . $e->getMessage());
}
}
diff --git a/ext/bulk_add_csv/main.php b/ext/bulk_add_csv/main.php
index 31d5b094..5bdb9252 100644
--- a/ext/bulk_add_csv/main.php
+++ b/ext/bulk_add_csv/main.php
@@ -112,7 +112,7 @@ class BulkAddCSV extends Extension
try {
$this->add_image($fullpath, $pathinfo["basename"], $tags, $source, $rating, $thumbfile);
$list .= "ok\n";
- } catch (Exception $ex) {
+ } catch (\Exception $ex) {
$list .= "failed:
". $ex->getMessage();
}
} else {
diff --git a/ext/bulk_download/main.php b/ext/bulk_download/main.php
index 9d465393..64e38025 100644
--- a/ext/bulk_download/main.php
+++ b/ext/bulk_download/main.php
@@ -49,11 +49,11 @@ class BulkDownload extends Extension
($event->action == BulkDownload::DOWNLOAD_ACTION_NAME)) {
$download_filename = $user->name . '-' . date('YmdHis') . '.zip';
$zip_filename = tempnam(sys_get_temp_dir(), "shimmie_bulk_download");
- $zip = new ZipArchive();
+ $zip = new \ZipArchive();
$size_total = 0;
$max_size = $config->get_int(BulkDownloadConfig::SIZE_LIMIT);
- if ($zip->open($zip_filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) === true) {
+ if ($zip->open($zip_filename, \ZIPARCHIVE::CREATE | \ZIPARCHIVE::OVERWRITE) === true) {
foreach ($event->items as $image) {
$img_loc = warehouse_path(Image::IMAGE_DIR, $image->hash, false);
$size_total += filesize($img_loc);
diff --git a/ext/bulk_import_export/main.php b/ext/bulk_import_export/main.php
index ef9be4b8..98d8da9f 100644
--- a/ext/bulk_import_export/main.php
+++ b/ext/bulk_import_export/main.php
@@ -17,7 +17,7 @@ class BulkImportExport extends DataHandlerExtension
if ($this->supported_mime($event->mime) &&
$user->can(Permissions::BULK_IMPORT)) {
- $zip = new ZipArchive();
+ $zip = new \ZipArchive();
if ($zip->open($event->tmpname) === true) {
$json_data = $this->get_export_data($zip);
@@ -71,11 +71,11 @@ class BulkImportExport extends DataHandlerExtension
$database->commit();
$total++;
- } catch (Exception $ex) {
+ } catch (\Exception $ex) {
$failed++;
try {
$database->rollBack();
- } catch (Exception $ex2) {
+ } catch (\Exception $ex2) {
log_error(BulkImportExportInfo::KEY, "Could not roll back transaction: " . $ex2->getMessage(), "Could not import " . $item->hash . ": " . $ex->getMessage());
}
log_error(BulkImportExportInfo::KEY, "Could not import " . $item->hash . ": " . $ex->getMessage(), "Could not import " . $item->hash . ": " . $ex->getMessage());
@@ -118,11 +118,11 @@ class BulkImportExport extends DataHandlerExtension
($event->action == self::EXPORT_ACTION_NAME)) {
$download_filename = $user->name . '-' . date('YmdHis') . '.zip';
$zip_filename = tempnam(sys_get_temp_dir(), "shimmie_bulk_export");
- $zip = new ZipArchive();
+ $zip = new \ZipArchive();
$json_data = [];
- if ($zip->open($zip_filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) === true) {
+ if ($zip->open($zip_filename, \ZIPARCHIVE::CREATE | \ZIPARCHIVE::OVERWRITE) === true) {
foreach ($event->items as $image) {
$img_loc = warehouse_path(Image::IMAGE_DIR, $image->hash, false);
@@ -134,7 +134,7 @@ class BulkImportExport extends DataHandlerExtension
$data["filename"] = $image->filename;
$data["source"] = $image->source;
- array_push($json_data, $data);
+ $json_data[] = $data;
$zip->addFile($img_loc, $image->hash);
}
@@ -167,7 +167,7 @@ class BulkImportExport extends DataHandlerExtension
return false;
}
- private function get_export_data(ZipArchive $zip): ?array
+ private function get_export_data(\ZipArchive $zip): ?array
{
$info = $zip->getStream(self::EXPORT_INFO_FILE_NAME);
if ($info !== false) {
diff --git a/ext/comment/main.php b/ext/comment/main.php
index 0fc0aadf..5f9402f0 100644
--- a/ext/comment/main.php
+++ b/ext/comment/main.php
@@ -552,7 +552,7 @@ class CommentList extends Extension
'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? 'none',
];
- $akismet = new Akismet(
+ $akismet = new \Akismet(
$_SERVER['SERVER_NAME'],
$config->get_string('comment_wordpress_key'),
$comment
diff --git a/ext/et/main.php b/ext/et/main.php
index f8288757..a9d9037f 100644
--- a/ext/et/main.php
+++ b/ext/et/main.php
@@ -113,7 +113,7 @@ class ET extends Extension
'branch' => $commitBranch,
'origin' => $commitOrigin,
];
- } catch (Exception $e) {
+ } catch (\Exception $e) {
}
}
diff --git a/ext/handle_cbz/main.php b/ext/handle_cbz/main.php
index 879d47f0..2a6ac9c0 100644
--- a/ext/handle_cbz/main.php
+++ b/ext/handle_cbz/main.php
@@ -49,7 +49,7 @@ class CBZFileHandler extends DataHandlerExtension
{
$out = "data/comic-cover-FIXME.jpg"; // TODO: random
- $za = new ZipArchive();
+ $za = new \ZipArchive();
$za->open($archive);
$names = [];
for ($i=0; $i<$za->numFiles;$i++) {
diff --git a/ext/handle_pixel/main.php b/ext/handle_pixel/main.php
index 3c4d33b4..cc758b8e 100644
--- a/ext/handle_pixel/main.php
+++ b/ext/handle_pixel/main.php
@@ -53,7 +53,7 @@ class PixelFileHandler extends DataHandlerExtension
log_warning("handle_pixel", "Insufficient memory while creating thumbnail: ".$e->getMessage());
imagestring($thumb, 5, 10, 24, "Image Too Large :(", $black);
return true;
- } catch (Exception $e) {
+ } catch (\Exception $e) {
log_error("handle_pixel", "Error while creating thumbnail: ".$e->getMessage());
return false;
}
diff --git a/ext/handle_svg/main.php b/ext/handle_svg/main.php
index 0e6ae9c7..848c95a7 100644
--- a/ext/handle_svg/main.php
+++ b/ext/handle_svg/main.php
@@ -96,7 +96,7 @@ class MiniSVGParser
xml_parser_free($xml_parser);
}
- public function startElement($parser, $name, $attrs)
+ public function startElement($parser, $name, $attrs): void
{
if ($name == "SVG" && $this->xml_depth == 0) {
$this->width = int_escape($attrs["WIDTH"]);
@@ -105,7 +105,7 @@ class MiniSVGParser
$this->xml_depth++;
}
- public function endElement($parser, $name)
+ public function endElement($parser, $name): void
{
$this->xml_depth--;
}
diff --git a/ext/image_hash_ban/test.php b/ext/image_hash_ban/test.php
index c70ca147..5c8e433f 100644
--- a/ext/image_hash_ban/test.php
+++ b/ext/image_hash_ban/test.php
@@ -35,7 +35,7 @@ class ImageBanTest extends ShimmiePHPUnitTestCase
// Can't repost
try {
$this->post_image("tests/pbx_screenshot.jpg", "pbx");
- $this->assertTrue(false);
+ $this->fail();
} catch (UploadException $e) {
$this->assertTrue(true);
}
diff --git a/ext/link_image/test.php b/ext/link_image/test.php
index 3f9d78c3..5681bf12 100644
--- a/ext/link_image/test.php
+++ b/ext/link_image/test.php
@@ -14,7 +14,7 @@ class LinkImageTest extends ShimmiePHPUnitTestCase
$matches = [];
preg_match("#value='https?://.*/(post/view/[0-9]+)'#", $this->page_to_text(), $matches);
- $this->assertTrue(count($matches) > 0);
+ $this->assertNotEmpty($matches);
$page = $this->get_page($matches[1]);
$this->assertEquals("Post $image_id: pie", $page->title);
}
diff --git a/ext/livefeed/main.php b/ext/livefeed/main.php
index 8bdd5b36..acaff4b3 100644
--- a/ext/livefeed/main.php
+++ b/ext/livefeed/main.php
@@ -68,7 +68,7 @@ class LiveFeed extends Extension
}
fwrite($fp, "$data\n");
fclose($fp);
- } catch (Exception $e) {
+ } catch (\Exception $e) {
/* logging errors shouldn't break everything */
}
}
diff --git a/ext/log_db/main.php b/ext/log_db/main.php
index 6af1abe9..e7848631 100644
--- a/ext/log_db/main.php
+++ b/ext/log_db/main.php
@@ -50,7 +50,7 @@ class ActorColumn extends Column
public function get_sql_filter(): string
{
- $driver = $this->table->db->getAttribute(PDO::ATTR_DRIVER_NAME);
+ $driver = $this->table->db->getAttribute(\PDO::ATTR_DRIVER_NAME);
switch ($driver) {
case "pgsql":
return "((LOWER(username) = LOWER(:{$this->name}_0)) OR (address && cast(:{$this->name}_1 as inet)))";
diff --git a/ext/log_logstash/main.php b/ext/log_logstash/main.php
index 47f051bb..3119b427 100644
--- a/ext/log_logstash/main.php
+++ b/ext/log_logstash/main.php
@@ -28,7 +28,7 @@ class LogLogstash extends Extension
];
$this->send_data($data);
- } catch (Exception $e) {
+ } catch (\Exception $e) {
// we can't log that logging is broken
}
}
@@ -52,7 +52,7 @@ class LogLogstash extends Extension
}
fwrite($fp, json_encode($data));
fclose($fp);
- } catch (Exception $e) {
+ } catch (\Exception $e) {
// we can't log that logging is broken
}
}
diff --git a/ext/log_net/main.php b/ext/log_net/main.php
index d998dcc7..571c6cfe 100644
--- a/ext/log_net/main.php
+++ b/ext/log_net/main.php
@@ -44,7 +44,7 @@ class LogNet extends Extension
}
fwrite($fp, "$data\n");
fclose($fp);
- } catch (Exception $e) {
+ } catch (\Exception $e) {
/* logging errors shouldn't break everything */
}
}
diff --git a/ext/not_a_tag/test.php b/ext/not_a_tag/test.php
index 505188de..3a9277c7 100644
--- a/ext/not_a_tag/test.php
+++ b/ext/not_a_tag/test.php
@@ -28,7 +28,7 @@ class NotATagTest extends ShimmiePHPUnitTestCase
// Modified Bad as user - redirect
try {
send_event(new TagSetEvent($image, ["three", "face"]));
- $this->assertTrue(false, "Should've had an exception");
+ $this->fail("Should've had an exception");
} catch (TagSetException $e) {
$this->assertTrue(true);
}
diff --git a/ext/numeric_score/main.php b/ext/numeric_score/main.php
index 94eda54b..6c76469c 100644
--- a/ext/numeric_score/main.php
+++ b/ext/numeric_score/main.php
@@ -147,7 +147,7 @@ class NumericScore extends Extension
$dte = [$totaldate, $year, "\\y\\e\\a\\r\=Y", "year"];
} else {
// this should never happen due to the fact that the page event is already matched against earlier.
- throw new UnexpectedValueException("Error: Invalid page event.");
+ throw new \UnexpectedValueException("Error: Invalid page event.");
}
$sql .= " AND NOT numeric_score=0 ORDER BY numeric_score DESC LIMIT :limit OFFSET 0";
diff --git a/ext/ouroboros_api/main.php b/ext/ouroboros_api/main.php
index 6e940791..bab98c23 100644
--- a/ext/ouroboros_api/main.php
+++ b/ext/ouroboros_api/main.php
@@ -521,7 +521,7 @@ class OuroborosAPI extends Extension
$response = json_encode($response);
} elseif ($this->type == 'xml') {
// Seriously, XML sucks...
- $xml = new XMLWriter();
+ $xml = new \XMLWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'utf-8');
$xml->startElement('response');
@@ -546,7 +546,7 @@ class OuroborosAPI extends Extension
if ($this->type == 'json') {
$response = json_encode($data);
} elseif ($this->type == 'xml') {
- $xml = new XMLWriter();
+ $xml = new \XMLWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'utf-8');
if (array_key_exists(0, $data)) {
@@ -572,7 +572,7 @@ class OuroborosAPI extends Extension
$page->set_data($response);
}
- private function createItemXML(XMLWriter $xml, string $type, $item)
+ private function createItemXML(\XMLWriter $xml, string $type, $item)
{
$xml->startElement($type);
foreach ($item as $key => $val) {
diff --git a/ext/pools/main.php b/ext/pools/main.php
index 76aff697..169a0cc3 100644
--- a/ext/pools/main.php
+++ b/ext/pools/main.php
@@ -347,7 +347,7 @@ class Pools extends Extension
$image_order = $image_order + 1;
}
$database->commit();
- } catch (Exception $e) {
+ } catch (\Exception $e) {
$database->rollback();
}
$page->set_mode(PageMode::REDIRECT);
@@ -581,7 +581,7 @@ class Pools extends Extension
if ($this->have_permission($user, $pool)) {
send_event(
- new PoolAddPostsEvent($pool_id, iterator_map_to_array("_image_to_id", $event->items))
+ new PoolAddPostsEvent($pool_id, iterator_map_to_array("Shimmie2\_image_to_id", $event->items))
);
}
break;
@@ -592,7 +592,7 @@ class Pools extends Extension
$new_pool_title = $_POST['bulk_pool_new'];
$pce = new PoolCreationEvent($new_pool_title);
send_event($pce);
- send_event(new PoolAddPostsEvent($pce->new_id, iterator_map_to_array("_image_to_id", $event->items)));
+ send_event(new PoolAddPostsEvent($pce->new_id, iterator_map_to_array("Shimmie2\_image_to_id", $event->items)));
break;
}
}
diff --git a/ext/post_titles/main.php b/ext/post_titles/main.php
index 5cb6687e..4577caf2 100644
--- a/ext/post_titles/main.php
+++ b/ext/post_titles/main.php
@@ -81,7 +81,7 @@ class PostTitles extends Extension
}
public function onBulkImport(BulkImportEvent $event)
{
- if (property_exists($event->fields, "title") && $event->fields->title!=null) {
+ if (array_key_exists("title", $event->fields) && $event->fields->title!=null) {
$this->set_title($event->image->id, $event->fields->title);
}
}
diff --git a/ext/random_list/main.php b/ext/random_list/main.php
index 8bd826c8..83584801 100644
--- a/ext/random_list/main.php
+++ b/ext/random_list/main.php
@@ -45,7 +45,7 @@ class RandomList extends Extension
if (!$random_image) {
continue;
}
- array_push($random_images, $random_image);
+ $random_images[] = $random_image;
}
$this->theme->set_page($search_terms);
diff --git a/ext/rating/main.php b/ext/rating/main.php
index 36041948..da3cc2b0 100644
--- a/ext/rating/main.php
+++ b/ext/rating/main.php
@@ -28,18 +28,7 @@ class ImageRating
}
}
-function clear_ratings()
-{
- global $_shm_ratings;
- $keys = array_keys($_shm_ratings);
- foreach ($keys as $key) {
- if ($key != "?") {
- unset($_shm_ratings[$key]);
- }
- }
-}
-
-function add_rating(ImageRating $rating)
+function add_rating(ImageRating $rating): void
{
global $_shm_ratings;
if ($rating->code == "?" && array_key_exists("?", $_shm_ratings)) {
@@ -97,7 +86,7 @@ class Ratings extends Extension
$codes = implode("", array_keys($_shm_ratings));
$search_terms = [];
foreach ($_shm_ratings as $key => $rating) {
- array_push($search_terms, $rating->search_term);
+ $search_terms[] = $rating->search_term;
}
$this->search_regexp = "/^rating[=|:](?:(\*|[" . $codes . "]+)|(" .
implode("|", $search_terms) . "|".implode("|", self::UNRATED_KEYWORDS)."))$/D";
@@ -193,7 +182,7 @@ class Ratings extends Extension
}
public function onBulkImport(BulkImportEvent $event)
{
- if (property_exists($event->fields, "rating")
+ if (array_key_exists("rating", $event->fields)
&& $event->fields->rating != null
&& Ratings::rating_is_valid($event->fields->rating)) {
$this->set_rating($event->image->id, $event->fields->rating, "");
diff --git a/ext/regen_thumb/theme.php b/ext/regen_thumb/theme.php
index 6477c7e5..cf05e5c3 100644
--- a/ext/regen_thumb/theme.php
+++ b/ext/regen_thumb/theme.php
@@ -44,7 +44,7 @@ class RegenThumbTheme extends Themelet
$mimes = [];
$results = $database->get_all("SELECT mime, count(*) count FROM images group by mime");
foreach ($results as $result) {
- array_push($mimes, "");
+ $mimes[] = "";
}
$html = "
diff --git a/ext/res_limit/test.php b/ext/res_limit/test.php
index 8163dd95..7bb9ee49 100644
--- a/ext/res_limit/test.php
+++ b/ext/res_limit/test.php
@@ -35,7 +35,7 @@ class ResolutionLimitTest extends ShimmiePHPUnitTestCase
$this->log_in_as_user();
try {
$this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
- $this->assertTrue(false, "Invalid-size image was allowed");
+ $this->fail("Invalid-size image was allowed");
} catch (UploadException $e) {
$this->assertEquals("Post too small", $e->getMessage());
}
@@ -52,7 +52,7 @@ class ResolutionLimitTest extends ShimmiePHPUnitTestCase
try {
$this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
- $this->assertTrue(false, "Invalid-size image was allowed");
+ $this->fail("Invalid-size image was allowed");
} catch (UploadException $e) {
$this->assertEquals("Post too large", $e->getMessage());
}
@@ -69,7 +69,7 @@ class ResolutionLimitTest extends ShimmiePHPUnitTestCase
try {
$this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
- $this->assertTrue(false, "Invalid-size image was allowed");
+ $this->fail("Invalid-size image was allowed");
} catch (UploadException $e) {
$this->assertEquals("Post needs to be in one of these ratios: 16:9", $e->getMessage());
}
diff --git a/ext/rule34/main.php b/ext/rule34/main.php
index 61254f26..b1f89865 100644
--- a/ext/rule34/main.php
+++ b/ext/rule34/main.php
@@ -108,7 +108,7 @@ class Rule34 extends Extension
$database->set_timeout(DATABASE_TIMEOUT+15000); // deleting users can take a while
if (function_exists("sd_notify_watchdog")) {
- sd_notify_watchdog();
+ \sd_notify_watchdog();
}
if ($event->page_matches("rule34/comic_admin")) {
diff --git a/ext/statsd/main.php b/ext/statsd/main.php
index 75417025..8cfecbfd 100644
--- a/ext/statsd/main.php
+++ b/ext/statsd/main.php
@@ -6,11 +6,6 @@ namespace Shimmie2;
_d("STATSD_HOST", null);
-function dstat($name, $val)
-{
- StatsDInterface::$stats["shimmie.$name"] = $val;
-}
-
class StatsDInterface extends Extension
{
public static array $stats = [];
@@ -115,7 +110,7 @@ class StatsDInterface extends Extension
fwrite($fp, "$stat:$value");
}
fclose($fp);
- } catch (Exception $e) {
+ } catch (\Exception $e) {
// ignore any failures.
}
}
diff --git a/ext/tag_categories/main.php b/ext/tag_categories/main.php
index 5d28d59f..8829a41b 100644
--- a/ext/tag_categories/main.php
+++ b/ext/tag_categories/main.php
@@ -156,7 +156,7 @@ class TagCategories extends Extension
return $h_tag_no_underscores;
}
- public function page_update()
+ public function page_update(): bool
{
global $user, $database;
diff --git a/ext/tag_edit/main.php b/ext/tag_edit/main.php
index f63518dd..8b9e34c9 100644
--- a/ext/tag_edit/main.php
+++ b/ext/tag_edit/main.php
@@ -70,7 +70,7 @@ class TagSetEvent extends Event
if ((!str_contains($tag, ':')) && (!str_contains($tag, '='))) {
//Tag doesn't contain : or =, meaning it can't possibly be a metatag.
//This should help speed wise, as it avoids running every single tag through a bunch of preg_match instead.
- array_push($this->tags, $tag);
+ $this->tags[] = $tag;
continue;
}
@@ -79,9 +79,9 @@ class TagSetEvent extends Event
//seperate tags from metatags
if (!$ttpe->metatag) {
- array_push($this->tags, $tag);
+ $this->tags[] = $tag;
} else {
- array_push($this->metatags, $tag);
+ $this->metatags[] = $tag;
}
}
}
@@ -287,7 +287,7 @@ class TagEdit extends Extension
{
$tags = $event->image->get_tag_list();
$tags = str_replace("/", "", $tags);
- $tags = preg_replace("/^\.+/", "", $tags);
+ $tags = ltrim($tags, ".");
$event->replace('$tags', $tags);
}
diff --git a/ext/tag_edit/test.php b/ext/tag_edit/test.php
index 98d57c35..6ed8b765 100644
--- a/ext/tag_edit/test.php
+++ b/ext/tag_edit/test.php
@@ -30,7 +30,7 @@ class TagEditTest extends ShimmiePHPUnitTestCase
try {
send_event(new TagSetEvent($image, []));
- $this->assertTrue(false);
+ $this->fail();
} catch (SCoreException $e) {
$this->assertEquals("Tried to set zero tags", $e->error);
}
diff --git a/ext/tag_editcloud/main.php b/ext/tag_editcloud/main.php
index 7f2fa3b5..c704a49d 100644
--- a/ext/tag_editcloud/main.php
+++ b/ext/tag_editcloud/main.php
@@ -106,7 +106,7 @@ class TagEditCloud extends Extension
SELECT tag, FLOOR(LN(LN(count - :tag_min1 + 1)+1)*150)/200 AS scaled, count
FROM tags
WHERE count >= :tag_min2
- ORDER BY SUM(count) OVER (PARTITION BY SUBSTRING_INDEX(tag, ':', 1)) DESC, CASE
+ ORDER BY SUM(count) OVER (PARTITION BY SUBSTRING_INDEX(tag, ':', 1)) DESC, CASE
WHEN tag LIKE '%:%' THEN 1
ELSE 2
END, tag
@@ -159,7 +159,7 @@ class TagEditCloud extends Extension
$size = sprintf("%.2f", max($row['scaled'], 0.5));
$js = html_escape('tageditcloud_toggle_tag(this,'.json_encode($full_tag).')'); //Ugly, but it works
- if (array_search($row['tag'], $image->get_tag_array()) !== false) {
+ if (in_array($row['tag'], $image->get_tag_array())) {
if ($used_first) {
if ($last_used_cat !== $current_cat && $last_used_cat !== null) {
$precloud .= "\n";
diff --git a/ext/tagger_xml/main.php b/ext/tagger_xml/main.php
index 315e762d..b18b096b 100644
--- a/ext/tagger_xml/main.php
+++ b/ext/tagger_xml/main.php
@@ -97,7 +97,7 @@ class TaggerXML extends Extension
return $this->list_to_xml($tags, "image", (string)$image_id);
}
- private function list_to_xml(PDOStatement $tags, string $type, string $query, ?array$misc=null): string
+ private function list_to_xml(\FFSPHP\PDOStatement $tags, string $type, string $query, ?array$misc=null): string
{
$r = $tags->_numOfRows;
@@ -115,7 +115,7 @@ class TaggerXML extends Extension
return $result."";
}
- private function tag_to_xml(PDORow $tag): string
+ private function tag_to_xml(\PDORow $tag): string
{
return
"transcode_image($event->tmpname, $mime, $target_mime);
$event->set_mime($target_mime);
$event->set_tmpname($new_image);
- } catch (Exception $e) {
+ } catch (\Exception $e) {
log_error("transcode", "Error while performing upload transcode: ".$e->getMessage());
// We don't want to interfere with the upload process,
// so if something goes wrong the untranscoded image jsut continues
@@ -295,11 +295,11 @@ class TranscodeImage extends Extension
$database->commit();
$total++;
$size_difference += ($before_size - $new_image->filesize);
- } catch (Exception $e) {
+ } catch (\Exception $e) {
log_error("transcode", "Error while bulk transcode on item {$image->id} to $mime: ".$e->getMessage());
try {
$database->rollback();
- } catch (Exception $e) {
+ } catch (\Exception $e) {
// is this safe? o.o
}
}
diff --git a/ext/transcode_video/main.php b/ext/transcode_video/main.php
index 263a3da2..e431d090 100644
--- a/ext/transcode_video/main.php
+++ b/ext/transcode_video/main.php
@@ -166,11 +166,11 @@ class TranscodeVideo extends Extension
if ($output_image!=$image) {
$total++;
}
- } catch (Exception $e) {
+ } catch (\Exception $e) {
log_error("transcode_video", "Error while bulk transcode on item {$image->id} to $format: ".$e->getMessage());
try {
$database->rollback();
- } catch (Exception $e) {
+ } catch (\Exception $e) {
// is this safe? o.o
}
}
diff --git a/ext/update/main.php b/ext/update/main.php
index 8e4c26cd..88ac382b 100644
--- a/ext/update/main.php
+++ b/ext/update/main.php
@@ -95,7 +95,7 @@ class Update extends Extension
/** TODO: Backup all folders (except /data, /images, /thumbs) before attempting this?
Either that or point to https://github.com/shish/shimmie2/blob/master/README.txt -> Upgrade from 2.3.X **/
- $zip = new ZipArchive();
+ $zip = new \ZipArchive();
if ($zip->open("./data/update_$commitSHA.zip") === true) {
for ($i = 1; $i < $zip->numFiles; $i++) {
$filename = $zip->getNameIndex($i);
diff --git a/ext/upload/test.php b/ext/upload/test.php
index 2f901749..60d2361b 100644
--- a/ext/upload/test.php
+++ b/ext/upload/test.php
@@ -107,7 +107,7 @@ class UploadTest extends ShimmiePHPUnitTestCase
file_put_contents("data/huge.jpg", file_get_contents("tests/pbx_screenshot.jpg") . str_repeat("U", 1024*1024*3));
try {
$this->post_image("data/huge.jpg", "test");
- $this->assertTrue(false, "Uploading huge.jpg didn't fail...");
+ $this->fail("Uploading huge.jpg didn't fail...");
} catch (UploadException $e) {
$this->assertEquals("File too large (3.0MB > 1.0MB)", $e->error);
}
diff --git a/ext/wiki/main.php b/ext/wiki/main.php
index f6a3311e..190225a9 100644
--- a/ext/wiki/main.php
+++ b/ext/wiki/main.php
@@ -376,7 +376,7 @@ class Wiki extends Extension
return new WikiPage($row);
}
- public static function format_tag_wiki_page(WikiPage $page)
+ public static function format_tag_wiki_page(WikiPage $page): string
{
global $database, $config;
@@ -434,7 +434,7 @@ class Wiki extends Extension
", ["title"=>$a_tag]);
$tag_html = $tag_list_t->return_tag($a_row, $tag_category_dict ?? []);
- array_push($f_auto_tags, $tag_html[1]);
+ $f_auto_tags[] = $tag_html[1];
}
$template = str_replace("{autotags}", implode(", ", $f_auto_tags), $template);
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 1a9f05cc..3dfddfac 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -191,8 +191,7 @@ abstract class ShimmiePHPUnitTestCase extends TestCase
} elseif ($page->mode == PageMode::DATA) {
return $page->data;
} else {
- $this->assertTrue(false, "Page mode is not PAGE or DATA");
- return "";
+ $this->fail("Page mode is not PAGE or DATA");
}
}
diff --git a/themes/material/page.class.php b/themes/material/page.class.php
index 4c8896aa..67700008 100644
--- a/themes/material/page.class.php
+++ b/themes/material/page.class.php
@@ -198,7 +198,7 @@ EOD;
$b = $block->body;
$i = $block->id;
- $dom = new DomDocument();
+ $dom = new \DomDocument();
$dom->loadHTML($b);
// $output = [];
$html = "