diff --git a/.github/workflows/test_and_publish.yml b/.github/workflows/test_and_publish.yml index a87ef278..278cc7af 100644 --- a/.github/workflows/test_and_publish.yml +++ b/.github/workflows/test_and_publish.yml @@ -22,7 +22,7 @@ jobs: strategy: fail-fast: false matrix: - php: ['7.3', '7.4', '8.0'] + php: ['7.4', '8.0'] database: ['pgsql', 'mysql', 'sqlite'] runs-on: ubuntu-latest diff --git a/composer.json b/composer.json index ba0b0314..e3f09fd9 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ ], "require" : { - "php" : "^7.3 | ^8.0", + "php" : "^7.4 | ^8.0", "ext-pdo": "*", "ext-json": "*", "ext-fileinfo": "*", diff --git a/core/basepage.php b/core/basepage.php index b9f223c7..4376772a 100644 --- a/core/basepage.php +++ b/core/basepage.php @@ -20,10 +20,8 @@ abstract class PageMode */ class BasePage { - /** @var string */ - public $mode = PageMode::PAGE; - /** @var string */ - private $mime; + public string $mode = PageMode::PAGE; + private string $mime; /** * Set what this page should do; "page", "data", or "redirect". @@ -52,19 +50,11 @@ class BasePage // ============================================== - /** @var string; public only for unit test */ - public $data = ""; - - /** @var string */ - private $file = null; - - /** @var bool */ - private $file_delete = false; - - /** @var string */ - private $filename = null; - - private $disposition = null; + public string $data = ""; // public only for unit test + private ?string $file = null; + private bool $file_delete = false; + private ?string $filename = null; + private ?string $disposition = null; /** * Set the raw data to be sent. @@ -91,8 +81,7 @@ class BasePage // ============================================== - /** @var string */ - public $redirect = ""; + public string $redirect = ""; /** * Set the URL to redirect to (remember to use make_link() if linking @@ -105,32 +94,25 @@ class BasePage // ============================================== - /** @var int */ - public $code = 200; - - /** @var string */ - public $title = ""; - - /** @var string */ - public $heading = ""; - - /** @var string */ - public $subheading = ""; + public int $code = 200; + public string $title = ""; + public string $heading = ""; + public string $subheading = ""; /** @var string[] */ - public $html_headers = []; + public array $html_headers = []; /** @var string[] */ - public $http_headers = []; + public array $http_headers = []; /** @var string[][] */ - public $cookies = []; + public array $cookies = []; /** @var Block[] */ - public $blocks = []; + public array $blocks = []; /** @var string[] */ - public $flash = []; + public array $flash = []; /** * Set the HTTP status code @@ -428,7 +410,7 @@ class BasePage $this->add_html_header("", 44); } - protected function get_nav_links() + protected function get_nav_links(): array { $pnbe = send_event(new PageNavBuildingEvent()); @@ -574,7 +556,7 @@ EOD; class PageNavBuildingEvent extends Event { - public $links = []; + public array $links = []; public function add_nav_link(string $name, Link $link, string $desc, ?bool $active = null, int $order = 50) { @@ -584,9 +566,9 @@ class PageNavBuildingEvent extends Event class PageSubNavBuildingEvent extends Event { - public $parent; + public string $parent; - public $links = []; + public array $links = []; public function __construct(string $parent) { @@ -602,11 +584,11 @@ class PageSubNavBuildingEvent extends Event class NavLink { - public $name; - public $link; - public $description; - public $order; - public $active = false; + public string $name; + public Link $link; + public string $description; + public int $order; + public bool $active = false; public function __construct(String $name, Link $link, String $description, ?bool $active = null, int $order = 50) { @@ -663,7 +645,7 @@ class NavLink } } -function sort_nav_links(NavLink $a, NavLink $b) +function sort_nav_links(NavLink $a, NavLink $b): int { return $a->order - $b->order; } diff --git a/core/block.php b/core/block.php index 2fdaa091..771eedc5 100644 --- a/core/block.php +++ b/core/block.php @@ -9,49 +9,37 @@ class Block { /** * The block's title. - * - * @var string */ - public $header; + public ?string $header; /** * The content of the block. - * - * @var string */ - public $body; + public ?string $body; /** * Where the block should be placed. The default theme supports * "main" and "left", other themes can add their own areas. - * - * @var string */ - public $section; + public string $section; /** * How far down the section the block should appear, higher * numbers appear lower. The scale is 0-100 by convention, * though any number will work. - * - * @var int */ - public $position; + public int $position; /** * A unique ID for the block. - * - * @var string */ - public $id; + public string $id; /** * Should this block count as content for the sake of * the 404 handler - * - * @var boolean */ - public $is_content = true; + public bool $is_content = true; public function __construct(string $header=null, string $body=null, string $section="main", int $position=50, string $id=null) { @@ -63,7 +51,9 @@ class Block if (is_null($id)) { $id = (empty($header) ? md5($body ?? '') : $header) . $section; } - $this->id = preg_replace('/[^\w-]/', '', str_replace(' ', '_', $id)); + $str_id = preg_replace('/[^\w-]/', '', str_replace(' ', '_', $id)); + assert(is_string($str_id)); + $this->id = $str_id; } /** diff --git a/core/cacheengine.php b/core/cacheengine.php index 75b7891e..b29039a0 100644 --- a/core/cacheengine.php +++ b/core/cacheengine.php @@ -2,8 +2,8 @@ interface CacheEngine { public function get(string $key); - public function set(string $key, $val, int $time=0); - public function delete(string $key); + public function set(string $key, $val, int $time=0): void; + public function delete(string $key): void; } class NoCache implements CacheEngine @@ -12,18 +12,17 @@ class NoCache implements CacheEngine { return false; } - public function set(string $key, $val, int $time=0) + public function set(string $key, $val, int $time=0): void { } - public function delete(string $key) + public function delete(string $key): void { } } class MemcachedCache implements CacheEngine { - /** @var ?Memcached */ - public $memcache=null; + public ?Memcached $memcache=null; public function __construct(string $args) { @@ -52,7 +51,7 @@ class MemcachedCache implements CacheEngine } } - public function set(string $key, $val, int $time=0) + public function set(string $key, $val, int $time=0): void { $key = urlencode($key); @@ -63,7 +62,7 @@ class MemcachedCache implements CacheEngine } } - public function delete(string $key) + public function delete(string $key): void { $key = urlencode($key); @@ -87,12 +86,12 @@ class APCCache implements CacheEngine return apc_fetch($key); } - public function set(string $key, $val, int $time=0) + public function set(string $key, $val, int $time=0): void { apc_store($key, $val, $time); } - public function delete(string $key) + public function delete(string $key): void { apc_delete($key); } @@ -100,7 +99,7 @@ class APCCache implements CacheEngine class RedisCache implements CacheEngine { - private $redis=null; + private Redis $redis; public function __construct(string $args) { @@ -116,7 +115,7 @@ class RedisCache implements CacheEngine return $this->redis->get($key); } - public function set(string $key, $val, int $time=0) + public function set(string $key, $val, int $time=0): void { if ($time > 0) { $this->redis->setEx($key, $time, $val); @@ -125,7 +124,7 @@ class RedisCache implements CacheEngine } } - public function delete(string $key) + public function delete(string $key): void { $this->redis->del($key); } @@ -134,9 +133,9 @@ class RedisCache implements CacheEngine class Cache { public $engine; - public $hits=0; - public $misses=0; - public $time=0; + public int $hits=0; + public int $misses=0; + public int $time=0; public function __construct(?string $dsn) { diff --git a/core/command_builder.php b/core/command_builder.php index afc1e796..e7500a5b 100644 --- a/core/command_builder.php +++ b/core/command_builder.php @@ -5,9 +5,9 @@ // quotes are only needed if the path to convert contains a space; some other times, quotes break things, see github bug #27 class CommandBuilder { - private $executable; - private $args = []; - public $output; + private string $executable; + private array $args = []; + public array $output; public function __construct(String $executable) { diff --git a/core/config.php b/core/config.php index 1be1e8d0..ae302ac6 100644 --- a/core/config.php +++ b/core/config.php @@ -130,7 +130,7 @@ interface Config */ abstract class BaseConfig implements Config { - public $values = []; + public array $values = []; public function set_int(string $name, ?int $value): void { @@ -256,12 +256,10 @@ abstract class BaseConfig implements Config */ class DatabaseConfig extends BaseConfig { - /** @var Database */ - private $database = null; - - private $table_name; - private $sub_column; - private $sub_value; + private Database $database; + private string $table_name; + private ?string $sub_column; + private ?string $sub_value; public function __construct( Database $database, diff --git a/core/database.php b/core/database.php index 63d05040..e8c6fca0 100644 --- a/core/database.php +++ b/core/database.php @@ -13,30 +13,23 @@ abstract class DatabaseDriver */ class Database { - /** @var string */ - private $dsn; + private string $dsn; /** * The PDO database connection object, for anyone who wants direct access. - * @var null|PDO */ - private $db = null; - - /** - * @var float - */ - public $dbtime = 0.0; + private ?PDO $db = null; + public float $dbtime = 0.0; /** * Meta info about the database engine. - * @var DBEngine|null */ - private $engine = null; + private ?DBEngine $engine = null; /** * How many queries this DB object has run */ - public $query_count = 0; + public int $query_count = 0; public function __construct(string $dsn) { diff --git a/core/dbengine.php b/core/dbengine.php index 0e1a7254..355cd099 100644 --- a/core/dbengine.php +++ b/core/dbengine.php @@ -7,16 +7,15 @@ abstract class SCORE abstract class DBEngine { - /** @var null|string */ - public $name = null; + public ?string $name = null; public function init(PDO $db) { } - public function scoreql_to_sql(string $scoreql): string + public function scoreql_to_sql(string $data): string { - return $scoreql; + return $data; } public function create_table_sql(string $name, string $data): string @@ -33,8 +32,7 @@ abstract class DBEngine class MySQL extends DBEngine { - /** @var string */ - public $name = DatabaseDriver::MYSQL; + public ?string $name = DatabaseDriver::MYSQL; public function init(PDO $db) { @@ -73,8 +71,7 @@ class MySQL extends DBEngine class PostgreSQL extends DBEngine { - /** @var string */ - public $name = DatabaseDriver::PGSQL; + public ?string $name = DatabaseDriver::PGSQL; public function init(PDO $db) { @@ -122,19 +119,19 @@ class PostgreSQL extends DBEngine } // shimmie functions for export to sqlite -function _unix_timestamp($date) +function _unix_timestamp($date): int { return strtotime($date); } -function _now() +function _now(): string { return date("Y-m-d H:i:s"); } -function _floor($a) +function _floor($a): float { return floor($a); } -function _log($a, $b=null) +function _log($a, $b=null): float { if (is_null($b)) { return log($a); @@ -142,35 +139,34 @@ function _log($a, $b=null) return log($a, $b); } } -function _isnull($a) +function _isnull($a): bool { return is_null($a); } -function _md5($a) +function _md5($a): string { return md5($a); } -function _concat($a, $b) +function _concat($a, $b): string { return $a . $b; } -function _lower($a) +function _lower($a): string { return strtolower($a); } -function _rand() +function _rand(): int { return rand(); } -function _ln($n) +function _ln($n): float { return log($n); } class SQLite extends DBEngine { - /** @var string */ - public $name = DatabaseDriver::SQLITE; + public ?string $name = DatabaseDriver::SQLITE; public function init(PDO $db) { diff --git a/core/event.php b/core/event.php index 84804e99..7a563fff 100644 --- a/core/event.php +++ b/core/event.php @@ -6,13 +6,13 @@ */ abstract class Event { - public $stop_processing = false; + public bool $stop_processing = false; public function __construct() { } - public function __toString() + public function __toString(): string { return var_export($this, true); } @@ -42,19 +42,11 @@ class InitExtEvent extends Event class PageRequestEvent extends Event { /** - * @var array + * @var string[] */ public $args; - - /** - * @var int - */ - public $arg_count; - - /** - * @var int - */ - public $part_count; + public int $arg_count; + public int $part_count; public function __construct(string $path) { @@ -179,15 +171,12 @@ class PageRequestEvent extends Event */ class CommandEvent extends Event { - /** - * @var string - */ - public $cmd = "help"; + public string $cmd = "help"; /** - * @var array + * @var string[] */ - public $args = []; + public array $args = []; /** * #param string[] $args @@ -256,24 +245,18 @@ class TextFormattingEvent extends Event { /** * For reference - * - * @var string */ - public $original; + public string $original; /** * with formatting applied - * - * @var string */ - public $formatted; + public string $formatted; /** * with formatting removed - * - * @var string */ - public $stripped; + public string $stripped; public function __construct(string $text) { @@ -296,38 +279,30 @@ class LogEvent extends Event { /** * a category, normally the extension name - * - * @var string */ - public $section; + public string $section; /** * See python... - * - * @var int */ - public $priority = 0; + public int $priority = 0; /** * Free text to be logged - * - * @var string */ - public $message; + public string $message; /** * The time that the event was created - * - * @var int */ - public $time; + public int $time; /** * Extra data to be held separate * - * @var array + * @var string[] */ - public $args; + public array $args; public function __construct(string $section, int $priority, string $message) { diff --git a/core/exceptions.php b/core/exceptions.php index af83415f..fa2e0d07 100644 --- a/core/exceptions.php +++ b/core/exceptions.php @@ -7,11 +7,8 @@ */ class SCoreException extends RuntimeException { - /** @var string|null */ - public $query; - - /** @var string */ - public $error; + public ?string $query; + public string $error; public function __construct(string $msg, ?string $query=null) { @@ -23,21 +20,16 @@ class SCoreException extends RuntimeException class InstallerException extends RuntimeException { - /** @var string */ - public $title; + public string $title; + public string $body; + public int $exit_code; - /** @var string */ - public $body; - - /** @var int */ - public $code; - - public function __construct(string $title, string $body, int $code) + public function __construct(string $title, string $body, int $exit_code) { parent::__construct($body); $this->title = $title; $this->body = $body; - $this->code = $code; + $this->exit_code = $exit_code; } } diff --git a/core/extension.php b/core/extension.php index 55cf3de2..b5a5ed3e 100644 --- a/core/extension.php +++ b/core/extension.php @@ -13,16 +13,11 @@ */ abstract class Extension { - /** @var string */ - public $key; + public string $key; + protected ?Themelet $theme; + public ?ExtensionInfo $info; - /** @var Themelet */ - protected $theme; - - /** @var ExtensionInfo */ - public $info; - - private static $enabled_extensions = []; + private static array $enabled_extensions = []; public function __construct($class = null) { @@ -122,35 +117,31 @@ abstract class ExtensionInfo public const LICENSE_MIT = "MIT"; public const LICENSE_WTFPL = "WTFPL"; + public const VISIBLE_DEFAULT = "default"; public const VISIBLE_ADMIN = "admin"; public const VISIBLE_HIDDEN = "hidden"; - private const VALID_VISIBILITY = [self::VISIBLE_ADMIN, self::VISIBLE_HIDDEN]; + private const VALID_VISIBILITY = [self::VISIBLE_DEFAULT, self::VISIBLE_ADMIN, self::VISIBLE_HIDDEN]; - public $key; + public string $key; - public $core = false; + public bool $core = false; + public bool $beta = false; - public $beta = false; + public string $name; + public string $license; + public string $description; + public array $authors = []; + public array $dependencies = []; + public array $conflicts = []; + public string $visibility = self::VISIBLE_DEFAULT; + public ?string $link = null; + public ?string $version = null; + public ?string $documentation = null; - public $name; - public $authors = []; - public $link; - public $license; - public $version; - public $dependencies = []; - public $conflicts = []; - public $visibility; - public $description; - public $documentation; - - /** @var array which DBs this ext supports (blank for 'all') */ - public $db_support = []; - - /** @var bool */ - private $supported = null; - - /** @var string */ - private $support_info = null; + /** @var string[] which DBs this ext supports (blank for 'all') */ + public array $db_support = []; + private ?bool $supported = null; + private ?string $support_info = null; public function is_supported(): bool { @@ -168,9 +159,9 @@ abstract class ExtensionInfo return $this->support_info; } - private static $all_info_by_key = []; - private static $all_info_by_class = []; - private static $core_extensions = []; + private static array $all_info_by_key = []; + private static array $all_info_by_class = []; + private static array $core_extensions = []; protected function __construct() { @@ -283,7 +274,7 @@ abstract class FormatterExtension extends Extension */ abstract class DataHandlerExtension extends Extension { - protected $SUPPORTED_MIME = []; + protected array $SUPPORTED_MIME = []; protected function move_upload_to_archive(DataUploadEvent $event) { @@ -335,7 +326,9 @@ abstract class DataHandlerExtension extends Extension } send_event(new ImageReplaceEvent($event->replace_id, $image)); - $event->image_id = $event->replace_id; + $_id = $event->replace_id; + assert(!is_null($_id)); + $event->image_id = $_id; } else { $image = $this->create_image_from_data(warehouse_path(Image::IMAGE_DIR, $event->hash), $event->metadata); if (is_null($image)) { diff --git a/core/imageboard/event.php b/core/imageboard/event.php index a6fa55b0..346db5e6 100644 --- a/core/imageboard/event.php +++ b/core/imageboard/event.php @@ -5,13 +5,9 @@ */ class ImageAdditionEvent extends Event { - /** @var User */ - public $user; - - /** @var Image */ - public $image; - - public $merged = false; + public User $user; + public Image $image; + public bool $merged = false; /** * Inserts a new image into the database with its associated @@ -34,11 +30,8 @@ class ImageAdditionException extends SCoreException */ class ImageDeletionEvent extends Event { - /** @var Image */ - public $image; - - /** @var bool */ - public $force = false; + public Image $image; + public bool $force = false; /** * Deletes an image. @@ -59,10 +52,8 @@ class ImageDeletionEvent extends Event */ class ImageReplaceEvent extends Event { - /** @var int */ - public $id; - /** @var Image */ - public $image; + public int $id; + public Image $image; /** * Replaces an image. @@ -88,15 +79,10 @@ class ImageReplaceException extends SCoreException */ class ThumbnailGenerationEvent extends Event { - /** @var string */ - public $hash; - /** @var string */ - public $mime; - /** @var bool */ - public $force; - - /** @var bool */ - public $generated; + public string $hash; + public string $mime; + public bool $force; + public bool $generated; /** * Request a thumbnail be made for an image object @@ -121,14 +107,10 @@ class ThumbnailGenerationEvent extends Event */ class ParseLinkTemplateEvent extends Event { - /** @var string */ - public $link; - /** @var string */ - public $text; - /** @var string */ - public $original; - /** @var Image */ - public $image; + public string $link; + public string $text; + public string $original; + public Image $image; public function __construct(string $link, Image $image) { diff --git a/core/imageboard/image.php b/core/imageboard/image.php index a57d19d2..2a7b7692 100644 --- a/core/imageboard/image.php +++ b/core/imageboard/image.php @@ -13,68 +13,31 @@ class Image public const IMAGE_DIR = "images"; public const THUMBNAIL_DIR = "thumbs"; - /** @var null|int */ - public $id = null; - - /** @var int */ - public $height; - - /** @var int */ - public $width; - - /** @var string */ - public $hash; - - /** @var int */ - public $filesize; - - /** @var string */ - public $filename; - - /** @var string */ - private $ext; - - /** @var string */ - private $mime; + public ?int $id = null; + public int $height; + public int $width; + public string $hash; + public int $filesize; + public string $filename; + private string $ext; + private string $mime; /** @var string[]|null */ - public $tag_array; + public ?array $tag_array; + public int $owner_id; + public string $owner_ip; + public string $posted; + public ?string $source; + public bool $locked = false; + public ?bool $lossless = null; + public ?bool $video = null; + public ?string $video_codec = null; + public ?bool $image = null; + public ?bool $audio = null; + public ?int $length = null; - /** @var int */ - public $owner_id; - - /** @var string */ - public $owner_ip; - - /** @var string */ - public $posted; - - /** @var string */ - public $source; - - /** @var boolean */ - public $locked = false; - - /** @var boolean */ - public $lossless = null; - - /** @var boolean */ - public $video = null; - - /** @var string */ - public $video_codec = null; - - /** @var boolean */ - public $image = null; - - /** @var boolean */ - public $audio = null; - - /** @var int */ - public $length = null; - - public static $bool_props = ["locked", "lossless", "video", "audio"]; - public static $int_props = ["id", "owner_id", "height", "width", "filesize", "length"]; + public static array $bool_props = ["locked", "lossless", "video", "audio", "image"]; + public static array $int_props = ["id", "owner_id", "height", "width", "filesize", "length"]; /** * One will very rarely construct an image directly, more common @@ -145,7 +108,7 @@ class Image private static function find_images_internal(int $start = 0, ?int $limit = null, array $tags=[]): iterable { - global $database, $user, $config; + global $database, $user; if ($start < 0) { $start = 0; @@ -161,9 +124,7 @@ class Image } $querylet = Image::build_search_querylet($tags, $limit, $start); - $result = $database->get_all_iterable($querylet->sql, $querylet->variables); - - return $result; + return $database->get_all_iterable($querylet->sql, $querylet->variables); } /** @@ -625,7 +586,9 @@ class Image public function set_mime($mime): void { $this->mime = $mime; - $this->ext = FileExtension::get_for_mime($this->get_mime()); + $ext = FileExtension::get_for_mime($this->get_mime()); + assert($ext != null); + $this->ext = $ext; } diff --git a/core/imageboard/search.php b/core/imageboard/search.php index 30456459..981cdd23 100644 --- a/core/imageboard/search.php +++ b/core/imageboard/search.php @@ -1,10 +1,8 @@ title, $e->body, $e->code); + die_nicely($e->title, $e->body, $e->exit_code); } } diff --git a/core/polyfills.php b/core/polyfills.php index 33be6cec..a2785f0f 100644 --- a/core/polyfills.php +++ b/core/polyfills.php @@ -246,21 +246,22 @@ function find_header(array $headers, string $name): ?string if (!function_exists('mb_strlen')) { // TODO: we should warn the admin that they are missing multibyte support - function mb_strlen($str, $encoding) + /** @noinspection PhpUnusedParameterInspection */ + function mb_strlen($str, $encoding): int { return strlen($str); } - function mb_internal_encoding($encoding) + function mb_internal_encoding($encoding): void { } - function mb_strtolower($str) + function mb_strtolower($str): string { return strtolower($str); } } /** @noinspection PhpUnhandledExceptionInspection */ -function get_subclasses_of(string $parent) +function get_subclasses_of(string $parent): array { $result = []; foreach (get_declared_classes() as $class) { @@ -327,7 +328,7 @@ function get_base_href(): string /** * The opposite of the standard library's parse_url */ -function unparse_url($parsed_url) +function unparse_url(array $parsed_url): string { $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : ''; $host = isset($parsed_url['host']) ? $parsed_url['host'] : ''; @@ -345,14 +346,14 @@ function unparse_url($parsed_url) if (!function_exists('str_starts_with')) { function str_starts_with(string $haystack, string $needle): bool { - return \strncmp($haystack, $needle, \strlen($needle)) === 0; + return strncmp($haystack, $needle, strlen($needle)) === 0; } } if (!function_exists('str_ends_with')) { function str_ends_with(string $haystack, string $needle): bool { - return $needle === '' || $needle === \substr($haystack, - \strlen($needle)); + return $needle === '' || $needle === substr($haystack, - strlen($needle)); } } @@ -520,13 +521,9 @@ function parse_shorthand_int(string $limit): int /** @noinspection PhpMissingBreakStatementInspection */ case 't': $value *= 1024; // fall through /** @noinspection PhpMissingBreakStatementInspection */ - // no break case 'g': $value *= 1024; // fall through /** @noinspection PhpMissingBreakStatementInspection */ - // no break case 'm': $value *= 1024; // fall through - /** @noinspection PhpMissingBreakStatementInspection */ - // no break case 'k': $value *= 1024; break; default: $value = -1; } @@ -800,7 +797,7 @@ function iterator_map_to_array(callable $callback, iterator $iter): array return iterator_to_array(iterator_map($callback, $iter)); } -function stringer($s) +function stringer($s): string { if (is_array($s)) { if (isset($s[0])) { diff --git a/core/urls.php b/core/urls.php index 1ca3192d..97a0e957 100644 --- a/core/urls.php +++ b/core/urls.php @@ -2,8 +2,8 @@ class Link { - public $page; - public $query; + public ?string $page; + public ?string $query; public function __construct(?string $page=null, ?string $query=null) { diff --git a/core/user.php b/core/user.php index 220e9d57..f9319970 100644 --- a/core/user.php +++ b/core/user.php @@ -15,22 +15,12 @@ function _new_user(array $row): User */ class User { - /** @var int */ - public $id; - - /** @var string */ - public $name; - - /** @var string */ - public $email; - - public $join_date; - - /** @var string */ - public $passhash; - - /** @var UserClass */ - public $class; + public int $id; + public string $name; + public ?string $email; + public string $join_date; + public ?string $passhash; + public UserClass $class; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Initialisation * diff --git a/core/userclass.php b/core/userclass.php index ba77884c..7fd6b7dc 100644 --- a/core/userclass.php +++ b/core/userclass.php @@ -10,21 +10,9 @@ $_shm_user_classes = []; */ class UserClass { - - /** - * @var ?string - */ - public $name = null; - - /** - * @var ?UserClass - */ - public $parent = null; - - /** - * @var array - */ - public $abilities = []; + public ?string $name = null; + public ?UserClass $parent = null; + public array $abilities = []; public function __construct(string $name, string $parent = null, array $abilities = []) { diff --git a/core/util.php b/core/util.php index a6c350f4..03f0b63e 100644 --- a/core/util.php +++ b/core/util.php @@ -12,6 +12,7 @@ use function MicroHTML\TFOOT; use function MicroHTML\TR; use function MicroHTML\TH; use function MicroHTML\TD; +use MicroHTML\HTMLElement; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * Misc * @@ -359,7 +360,7 @@ function path_to_tags(string $path): string } -function join_url(string $base, string ...$paths) +function join_url(string $base, string ...$paths): string { $output = $base; foreach ($paths as $path) { @@ -410,7 +411,7 @@ function remove_empty_dirs(string $dir): bool } } if ($result===true) { - $result = $result && rmdir($dir); + $result = rmdir($dir); } return $result; } @@ -584,7 +585,6 @@ function _get_themelet_files(string $_theme): array /** * Used to display fatal errors to the web user. - * @noinspection PhpPossiblePolymorphicInvocationInspection */ function _fatal_error(Exception $e): void { @@ -703,7 +703,7 @@ function make_form(string $target, string $method="POST", bool $multipart=false, return '