diff --git a/core/basethemelet.class.php b/core/basethemelet.class.php index 71ce4288..6f4b9060 100644 --- a/core/basethemelet.class.php +++ b/core/basethemelet.class.php @@ -13,8 +13,9 @@ class BaseThemelet { * @param int $code * @param string $title * @param string $message + * @return void */ - public function display_error(/*int*/ $code, /*string*/ $title, /*string*/ $message) { + public function display_error(int $code, string $title, string $message) { global $page; $page->set_code($code); $page->set_title($title); @@ -34,6 +35,7 @@ class BaseThemelet { /** * A specific, common error message + * @return void */ public function display_permission_denied() { $this->display_error(403, "Permission Denied", "You do not have permission to access this page"); @@ -47,7 +49,7 @@ class BaseThemelet { * @param Image $image * @return string */ - public function build_thumb_html(Image $image) { + public function build_thumb_html(Image $image): string { global $config; $i_id = (int) $image->id; @@ -75,45 +77,18 @@ class BaseThemelet { "\n"; } - /** - * Add a generic paginator. - * - * @param Page $page - * @param string $base - * @param string $query - * @param int $page_number - * @param int $total_pages - * @param bool $show_random - */ - public function display_paginator(Page $page, $base, $query, $page_number, $total_pages, $show_random = FALSE) { + public function display_paginator(Page $page, string $base, string $query=null, int $page_number, int $total_pages, bool $show_random = FALSE) { if($total_pages == 0) $total_pages = 1; $body = $this->build_paginator($page_number, $total_pages, $base, $query, $show_random); $page->add_block(new Block(null, $body, "main", 90, "paginator")); } - /** - * Generate a single HTML link. - * - * @param string $base_url - * @param string $query - * @param string $page - * @param string $name - * @return string - */ - private function gen_page_link($base_url, $query, $page, $name) { + private function gen_page_link(string $base_url, string $query=null, string $page, string $name): string { $link = make_link($base_url.'/'.$page, $query); return ''.$name.''; } - /** - * @param string $base_url - * @param string $query - * @param string $page - * @param int $current_page - * @param string $name - * @return string - */ - private function gen_page_link_block($base_url, $query, $page, $current_page, $name) { + private function gen_page_link_block(string $base_url, string $query=null, string $page, int $current_page, string $name): string { $paginator = ""; if($page == $current_page) $paginator .= ""; $paginator .= $this->gen_page_link($base_url, $query, $page, $name); @@ -121,17 +96,7 @@ class BaseThemelet { return $paginator; } - /** - * Build the paginator. - * - * @param int $current_page - * @param int $total_pages - * @param string $base_url - * @param string $query - * @param bool $show_random - * @return string - */ - private function build_paginator($current_page, $total_pages, $base_url, $query, $show_random) { + private function build_paginator(int $current_page, int $total_pages, string $base_url, string $query=null, bool $show_random): string { $next = $current_page + 1; $prev = $current_page - 1; @@ -163,4 +128,3 @@ class BaseThemelet { .'
<< '.$pages_html.' >>'; } } - diff --git a/core/block.class.php b/core/block.class.php index 0fffb41f..02eb3484 100644 --- a/core/block.class.php +++ b/core/block.class.php @@ -52,16 +52,7 @@ class Block { */ public $is_content = true; - /** - * Construct a block. - * - * @param string $header - * @param string $body - * @param string $section - * @param int $position - * @param null|int $id A unique ID for the block (generated automatically if null). - */ - public function __construct($header, $body, /*string*/ $section="main", /*int*/ $position=50, $id=null) { + public function __construct(string $header=null, string $body=null, string $section="main", int $position=50, string $id=null) { $this->header = $header; $this->body = $body; $this->section = $section; @@ -79,7 +70,7 @@ class Block { * @param bool $hidable * @return string */ - public function get_html($hidable=false) { + public function get_html(bool $hidable=false): string { $h = $this->header; $b = $this->body; $i = $this->id; diff --git a/core/config.class.php b/core/config.class.php index dc7e85ba..8513f40c 100644 --- a/core/config.class.php +++ b/core/config.class.php @@ -12,9 +12,9 @@ interface Config { * configuration. * * @param null|string $name - * @return mixed|void + * @return void */ - public function save(/*string*/ $name=null); + public function save(string $name=null); //@{ /*--------------------------------- SET ------------------------------------------------------*/ /** @@ -23,7 +23,7 @@ interface Config { * @param null|int $value * @return void */ - public function set_int(/*string*/ $name, $value); + public function set_int(string $name, $value); /** * Set a configuration option to a new value, regardless of what the value is at the moment. @@ -31,7 +31,7 @@ interface Config { * @param null|string $value * @return void */ - public function set_string(/*string*/ $name, $value); + public function set_string(string $name, $value); /** * Set a configuration option to a new value, regardless of what the value is at the moment. @@ -39,7 +39,7 @@ interface Config { * @param null|bool|string $value * @return void */ - public function set_bool(/*string*/ $name, $value); + public function set_bool(string $name, $value); /** * Set a configuration option to a new value, regardless of what the value is at the moment. @@ -47,7 +47,7 @@ interface Config { * @param array $value * @return void */ - public function set_array(/*string*/ $name, $value); + public function set_array(string $name, array $value); //@} /*--------------------------------------------------------------------------------------------*/ //@{ /*-------------------------------- SET DEFAULT -----------------------------------------------*/ @@ -63,7 +63,7 @@ interface Config { * @param int $value * @return void */ - public function set_default_int(/*string*/ $name, $value); + public function set_default_int(string $name, int $value); /** * Set a configuration option to a new value, if there is no value currently. @@ -77,7 +77,7 @@ interface Config { * @param string|null $value * @return void */ - public function set_default_string(/*string*/ $name, $value); + public function set_default_string(string $name, string $value); /** * Set a configuration option to a new value, if there is no value currently. @@ -91,7 +91,7 @@ interface Config { * @param bool $value * @return void */ - public function set_default_bool(/*string*/ $name, /*bool*/ $value); + public function set_default_bool(string $name, bool $value); /** * Set a configuration option to a new value, if there is no value currently. @@ -105,7 +105,7 @@ interface Config { * @param array $value * @return void */ - public function set_default_array(/*string*/ $name, $value); + public function set_default_array(string $name, array $value); //@} /*--------------------------------------------------------------------------------------------*/ //@{ /*--------------------------------- GET ------------------------------------------------------*/ @@ -115,7 +115,7 @@ interface Config { * @param null|int $default * @return int */ - public function get_int(/*string*/ $name, $default=null); + public function get_int(string $name, $default=null); /** * Pick a value out of the table by name, cast to the appropriate data type. @@ -123,7 +123,7 @@ interface Config { * @param null|string $default * @return string */ - public function get_string(/*string*/ $name, $default=null); + public function get_string(string $name, $default=null); /** * Pick a value out of the table by name, cast to the appropriate data type. @@ -131,7 +131,7 @@ interface Config { * @param null|bool|string $default * @return bool */ - public function get_bool(/*string*/ $name, $default=null); + public function get_bool(string $name, $default=null); /** * Pick a value out of the table by name, cast to the appropriate data type. @@ -139,7 +139,7 @@ interface Config { * @param array|null $default * @return array */ - public function get_array(/*string*/ $name, $default=array()); + public function get_array(string $name, array $default=array()); //@} /*--------------------------------------------------------------------------------------------*/ } @@ -153,134 +153,67 @@ interface Config { abstract class BaseConfig implements Config { public $values = array(); - /** - * @param string $name - * @param int|null $value - * @return void - */ - public function set_int(/*string*/ $name, $value) { + public function set_int(string $name, $value) { $this->values[$name] = parse_shorthand_int($value); $this->save($name); } - /** - * @param string $name - * @param null|string $value - * @return void - */ - public function set_string(/*string*/ $name, $value) { + public function set_string(string $name, $value) { $this->values[$name] = $value; $this->save($name); } - /** - * @param string $name - * @param bool|null|string $value - * @return void - */ - public function set_bool(/*string*/ $name, $value) { - $this->values[$name] = (($value == 'on' || $value === true) ? 'Y' : 'N'); + public function set_bool(string $name, $value) { + $this->values[$name] = bool_escape($value) ? 'Y' : 'N'; $this->save($name); } - /** - * @param string $name - * @param array $value - * @return void - */ - public function set_array(/*string*/ $name, $value) { - assert(isset($value) && is_array($value)); + public function set_array(string $name, array $value) { $this->values[$name] = implode(",", $value); $this->save($name); } - /** - * @param string $name - * @param int $value - * @return void - */ - public function set_default_int(/*string*/ $name, $value) { - if(is_null($this->get($name))) { - $this->values[$name] = parse_shorthand_int($value); - } - } - - /** - * @param string $name - * @param null|string $value - * @return void - */ - public function set_default_string(/*string*/ $name, $value) { + public function set_default_int(string $name, int $value) { if(is_null($this->get($name))) { $this->values[$name] = $value; } } - /** - * @param string $name - * @param bool $value - * @return void - */ - public function set_default_bool(/*string*/ $name, /*bool*/ $value) { + public function set_default_string(string $name, string $value) { if(is_null($this->get($name))) { - $this->values[$name] = (($value == 'on' || $value === true) ? 'Y' : 'N'); + $this->values[$name] = $value; } } - /** - * @param string $name - * @param array $value - * @return void - */ - public function set_default_array(/*string*/ $name, $value) { - assert(isset($value) && is_array($value)); + public function set_default_bool(string $name, bool $value) { + if(is_null($this->get($name))) { + $this->values[$name] = $value ? 'Y' : 'N'; + } + } + + public function set_default_array(string $name, array $value) { if(is_null($this->get($name))) { $this->values[$name] = implode(",", $value); } } - /** - * @param string $name - * @param null|int $default - * @return int - */ - public function get_int(/*string*/ $name, $default=null) { + public function get_int(string $name, $default=null) { return (int)($this->get($name, $default)); } - /** - * @param string $name - * @param null|string $default - * @return null|string - */ - public function get_string(/*string*/ $name, $default=null) { + public function get_string(string $name, $default=null) { return $this->get($name, $default); } - /** - * @param string $name - * @param null|bool|string $default - * @return bool - */ - public function get_bool(/*string*/ $name, $default=null) { + public function get_bool(string $name, $default=null) { return bool_escape($this->get($name, $default)); } - /** - * @param string $name - * @param array $default - * @return array - */ - public function get_array(/*string*/ $name, $default=array()) { + public function get_array(string $name, array $default=array()): array { return explode(",", $this->get($name, "")); } - /** - * @param string $name - * @param null|mixed $default - * @return null|mixed - */ - private function get(/*string*/ $name, $default=null) { + private function get(string $name, $default=null) { if(isset($this->values[$name])) { return $this->values[$name]; } @@ -297,15 +230,11 @@ abstract class BaseConfig implements Config { * For testing, mostly. */ class HardcodeConfig extends BaseConfig { - public function __construct($dict) { + public function __construct(array $dict) { $this->values = $dict; } - /** - * @param null|string $name - * @return mixed|void - */ - public function save(/*string*/ $name=null) { + public function save(string $name=null) { // static config is static } } @@ -322,11 +251,7 @@ class HardcodeConfig extends BaseConfig { * ?> */ class StaticConfig extends BaseConfig { - /** - * @param string $filename - * @throws Exception - */ - public function __construct($filename) { + public function __construct(string $filename) { if(file_exists($filename)) { $config = array(); require_once $filename; @@ -342,11 +267,7 @@ class StaticConfig extends BaseConfig { } } - /** - * @param null|string $name - * @return mixed|void - */ - public function save(/*string*/ $name=null) { + public function save(string $name=null) { // static config is static } } @@ -369,11 +290,6 @@ class DatabaseConfig extends BaseConfig { /** @var Database */ private $database = null; - /** - * Load the config table from a database. - * - * @param Database $database - */ public function __construct(Database $database) { $this->database = $database; @@ -390,17 +306,11 @@ class DatabaseConfig extends BaseConfig { } } - /** - * Save the current values as the new config table. - * - * @param null|string $name - * @return mixed|void - */ - public function save(/*string*/ $name=null) { + public function save(string $name=null) { if(is_null($name)) { reset($this->values); // rewind the array to the first element foreach($this->values as $name => $value) { - $this->save(/*string*/ $name); + $this->save($name); } } else { @@ -417,10 +327,7 @@ class DatabaseConfig extends BaseConfig { * Class MockConfig */ class MockConfig extends HardcodeConfig { - /** - * @param array $config - */ - public function __construct($config=array()) { + public function __construct(array $config=array()) { $config["db_version"] = "999"; $config["anon_id"] = "0"; parent::__construct($config); diff --git a/core/database.class.php b/core/database.class.php index ec1a7ce2..7dc46cca 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -7,34 +7,20 @@ class Querylet { /** @var array */ public $variables; - /** - * @param string $sql - * @param array $variables - */ - public function __construct($sql, $variables=array()) { + public function __construct(string $sql, array $variables=array()) { $this->sql = $sql; $this->variables = $variables; } - /** - * @param \Querylet $querylet - */ - public function append($querylet) { - assert('!is_null($querylet)'); + public function append(Querylet $querylet) { $this->sql .= $querylet->sql; $this->variables = array_merge($this->variables, $querylet->variables); } - /** - * @param string $sql - */ - public function append_sql($sql) { + public function append_sql(string $sql) { $this->sql .= $sql; } - /** - * @param mixed $var - */ public function add_variable($var) { $this->variables[] = $var; } @@ -46,11 +32,7 @@ class TagQuerylet { /** @var bool */ public $positive; - /** - * @param string $tag - * @param bool $positive - */ - public function __construct($tag, $positive) { + public function __construct(string $tag, bool $positive) { $this->tag = $tag; $this->positive = $positive; } @@ -62,11 +44,7 @@ class ImgQuerylet { /** @var bool */ public $positive; - /** - * @param \Querylet $qlet - * @param bool $positive - */ - public function __construct($qlet, $positive) { + public function __construct(Querylet $qlet, bool $positive) { $this->qlet = $qlet; $this->positive = $positive; } @@ -77,25 +55,13 @@ class DBEngine { /** @var null|string */ public $name = null; - /** - * @param \PDO $db - */ - public function init($db) {} + public function init(PDO $db) {} - /** - * @param string $scoreql - * @return string - */ - public function scoreql_to_sql($scoreql) { + public function scoreql_to_sql(string $scoreql): string { return $scoreql; } - /** - * @param string $name - * @param string $data - * @return string - */ - public function create_table_sql($name, $data) { + public function create_table_sql(string $name, string $data): string { return 'CREATE TABLE '.$name.' ('.$data.')'; } } @@ -103,18 +69,11 @@ class MySQL extends DBEngine { /** @var string */ public $name = "mysql"; - /** - * @param \PDO $db - */ - public function init($db) { + public function init(PDO $db) { $db->exec("SET NAMES utf8;"); } - /** - * @param string $data - * @return string - */ - public function scoreql_to_sql($data) { + public function scoreql_to_sql(string $data): string { $data = str_replace("SCORE_AIPK", "INTEGER PRIMARY KEY auto_increment", $data); $data = str_replace("SCORE_INET", "VARCHAR(45)", $data); $data = str_replace("SCORE_BOOL_Y", "'Y'", $data); @@ -127,12 +86,7 @@ class MySQL extends DBEngine { return $data; } - /** - * @param string $name - * @param string $data - * @return string - */ - public function create_table_sql($name, $data) { + public function create_table_sql(string $name, string $data): string { $data = $this->scoreql_to_sql($data); $ctes = "ENGINE=InnoDB DEFAULT CHARSET='utf8'"; return 'CREATE TABLE '.$name.' ('.$data.') '.$ctes; @@ -142,10 +96,7 @@ class PostgreSQL extends DBEngine { /** @var string */ public $name = "pgsql"; - /** - * @param \PDO $db - */ - public function init($db) { + public function init(PDO $db) { if(array_key_exists('REMOTE_ADDR', $_SERVER)) { $db->exec("SET application_name TO 'shimmie [{$_SERVER['REMOTE_ADDR']}]';"); } @@ -155,11 +106,7 @@ class PostgreSQL extends DBEngine { $db->exec("SET statement_timeout TO 10000;"); } - /** - * @param string $data - * @return string - */ - public function scoreql_to_sql($data) { + public function scoreql_to_sql(string $data): string { $data = str_replace("SCORE_AIPK", "SERIAL PRIMARY KEY", $data); $data = str_replace("SCORE_INET", "INET", $data); $data = str_replace("SCORE_BOOL_Y", "'t'", $data); @@ -172,12 +119,7 @@ class PostgreSQL extends DBEngine { return $data; } - /** - * @param string $name - * @param string $data - * @return string - */ - public function create_table_sql($name, $data) { + public function create_table_sql(string $name, string $data): string { $data = $this->scoreql_to_sql($data); return "CREATE TABLE $name ($data)"; } @@ -202,10 +144,7 @@ class SQLite extends DBEngine { /** @var string */ public $name = "sqlite"; - /** - * @param \PDO $db - */ - public function init($db) { + public function init(PDO $db) { ini_set('sqlite.assoc_case', 0); $db->exec("PRAGMA foreign_keys = ON;"); $db->sqliteCreateFunction('UNIX_TIMESTAMP', '_unix_timestamp', 1); @@ -220,11 +159,7 @@ class SQLite extends DBEngine { $db->sqliteCreateFunction('ln', '_ln', 1); } - /** - * @param string $data - * @return string - */ - public function scoreql_to_sql($data) { + public function scoreql_to_sql(string $data): string { $data = str_replace("SCORE_AIPK", "INTEGER PRIMARY KEY", $data); $data = str_replace("SCORE_INET", "VARCHAR(45)", $data); $data = str_replace("SCORE_BOOL_Y", "'Y'", $data); @@ -236,12 +171,7 @@ class SQLite extends DBEngine { return $data; } - /** - * @param string $name - * @param string $data - * @return string - */ - public function create_table_sql($name, $data) { + public function create_table_sql(string $name, string $data): string { $data = $this->scoreql_to_sql($data); $cols = array(); $extras = ""; @@ -264,42 +194,19 @@ class SQLite extends DBEngine { // {{{ cache engines interface CacheEngine { - /** - * @param string $key - * @return mixed - */ - public function get($key); - - /** - * @param string $key - * @param mixed $val - * @param integer $time - * @return void - */ - public function set($key, $val, $time=0); - - /** - * @return void - */ - public function delete($key); - - /** - * @return integer - */ - public function get_hits(); - - /** - * @return integer - */ - public function get_misses(); + public function get(string $key); + public function set(string $key, $val, int $time=0); + public function delete(string $key); + public function get_hits(): int; + public function get_misses(): int; } class NoCache implements CacheEngine { - public function get($key) {return false;} - public function set($key, $val, $time=0) {} - public function delete($key) {} + public function get(string $key) {return false;} + public function set(string $key, $val, int $time=0) {} + public function delete(string $key) {} - public function get_hits() {return 0;} - public function get_misses() {return 0;} + public function get_hits(): int {return 0;} + public function get_misses(): int {return 0;} } class MemcacheCache implements CacheEngine { /** @var \Memcache|null */ @@ -309,21 +216,13 @@ class MemcacheCache implements CacheEngine { /** @var int */ private $misses=0; - /** - * @param string $args - */ - public function __construct($args) { + public function __construct(string $args) { $hp = explode(":", $args); $this->memcache = new Memcache; @$this->memcache->pconnect($hp[0], $hp[1]); } - /** - * @param string $key - * @return array|bool|string - */ - public function get($key) { - assert('!is_null($key)'); + public function get(string $key) { $val = $this->memcache->get($key); if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) { $hit = $val === false ? "miss" : "hit"; @@ -339,39 +238,22 @@ class MemcacheCache implements CacheEngine { } } - /** - * @param string $key - * @param mixed $val - * @param integer $time - */ - public function set($key, $val, $time=0) { - assert('!is_null($key)'); + public function set(string $key, $val, int $time=0) { $this->memcache->set($key, $val, false, $time); if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) { file_put_contents("data/cache.log", "Cache set: $key ($time)\n", FILE_APPEND); } } - /** - * @param string $key - */ - public function delete($key) { - assert('!is_null($key)'); + public function delete(string $key) { $this->memcache->delete($key); if((DEBUG_CACHE === true) || (is_null(DEBUG_CACHE) && @$_GET['DEBUG_CACHE'])) { file_put_contents("data/cache.log", "Cache delete: $key\n", FILE_APPEND); } } - /** - * @return int - */ - public function get_hits() {return $this->hits;} - - /** - * @return int - */ - public function get_misses() {return $this->misses;} + public function get_hits(): int {return $this->hits;} + public function get_misses(): int {return $this->misses;} } class MemcachedCache implements CacheEngine { /** @var \Memcached|null */ @@ -381,10 +263,7 @@ class MemcachedCache implements CacheEngine { /** @var int */ private $misses=0; - /** - * @param string $args - */ - public function __construct($args) { + public function __construct(string $args) { $hp = explode(":", $args); $this->memcache = new Memcached; #$this->memcache->setOption(Memcached::OPT_COMPRESSION, False); @@ -393,12 +272,7 @@ class MemcachedCache implements CacheEngine { $this->memcache->addServer($hp[0], $hp[1]); } - /** - * @param string $key - * @return array|bool|string - */ - public function get($key) { - assert('!is_null($key)'); + public function get(string $key) { $key = urlencode($key); $val = $this->memcache->get($key); @@ -418,16 +292,11 @@ class MemcachedCache implements CacheEngine { } else { error_log("Memcached error during get($key): $res"); + return false; } } - /** - * @param string $key - * @param mixed $val - * @param int $time - */ - public function set($key, $val, $time=0) { - assert('!is_null($key)'); + public function set(string $key, $val, int $time=0) { $key = urlencode($key); $this->memcache->set($key, $val, $time); @@ -440,11 +309,7 @@ class MemcachedCache implements CacheEngine { } } - /** - * @param string $key - */ - public function delete($key) { - assert('!is_null($key)'); + public function delete(string $key) { $key = urlencode($key); $this->memcache->delete($key); @@ -457,26 +322,18 @@ class MemcachedCache implements CacheEngine { } } - /** - * @return int - */ - public function get_hits() {return $this->hits;} - - /** - * @return int - */ - public function get_misses() {return $this->misses;} + public function get_hits(): int {return $this->hits;} + public function get_misses(): int {return $this->misses;} } class APCCache implements CacheEngine { public $hits=0, $misses=0; - public function __construct($args) { + public function __construct(string $args) { // $args is not used, but is passed in when APC cache is created. } - public function get($key) { - assert('!is_null($key)'); + public function get(string $key) { $val = apc_fetch($key); if($val) { $this->hits++; @@ -488,18 +345,16 @@ class APCCache implements CacheEngine { } } - public function set($key, $val, $time=0) { - assert('!is_null($key)'); + public function set(string $key, $val, int $time=0) { apc_store($key, $val, $time); } - public function delete($key) { - assert('!is_null($key)'); + public function delete(string $key) { apc_delete($key); } - public function get_hits() {return $this->hits;} - public function get_misses() {return $this->misses;} + public function get_hits(): int {return $this->hits;} + public function get_misses(): int {return $this->misses;} } // }}} /** @publicsection */ @@ -627,11 +482,7 @@ class Database { } } - /** - * @return boolean|null - * @throws SCoreException - */ - public function commit() { + public function commit(): bool { if(!is_null($this->db)) { if ($this->transaction === true) { $this->transaction = false; @@ -641,13 +492,12 @@ class Database { throw new SCoreException("

Database Transaction Error: Unable to call commit() as there is no transaction currently open."); } } + else { + throw new SCoreException("

Database Transaction Error: Unable to call commit() as there is no connection currently open."); + } } - /** - * @return boolean|null - * @throws SCoreException - */ - public function rollback() { + public function rollback(): bool { if(!is_null($this->db)) { if ($this->transaction === true) { $this->transaction = false; @@ -657,39 +507,27 @@ class Database { throw new SCoreException("

Database Transaction Error: Unable to call rollback() as there is no transaction currently open."); } } + else { + throw new SCoreException("

Database Transaction Error: Unable to call rollback() as there is no connection currently open."); + } } - /** - * @param string $input - * @return string - */ - public function escape($input) { + public function escape(string $input): string { if(is_null($this->db)) $this->connect_db(); return $this->db->Quote($input); } - /** - * @param string $input - * @return string - */ - public function scoreql_to_sql($input) { + public function scoreql_to_sql(string $input): string { if(is_null($this->engine)) $this->connect_engine(); return $this->engine->scoreql_to_sql($input); } - /** - * @return null|string - */ - public function get_driver_name() { + public function get_driver_name(): string { if(is_null($this->engine)) $this->connect_engine(); return $this->engine->name; } - /** - * @param null|PDO $db - * @param string $sql - */ - private function count_execs($db, $sql, $inputarray) { + private function count_execs(string $sql, array $inputarray) { if((DEBUG_SQL === true) || (is_null(DEBUG_SQL) && @$_GET['DEBUG_SQL'])) { $sql = trim(preg_replace('/\s+/msi', ' ', $sql)); if(isset($inputarray) && is_array($inputarray) && !empty($inputarray)) { @@ -706,7 +544,7 @@ class Database { else $this->query_count++; } - private function count_time($method, $start) { + private function count_time(string $method, float $start) { if((DEBUG_SQL === true) || (is_null(DEBUG_SQL) && @$_GET['DEBUG_SQL'])) { $text = $method.":".(microtime(true) - $start)."\n"; file_put_contents("data/sql.log", $text, FILE_APPEND); @@ -714,18 +552,10 @@ class Database { $this->dbtime += microtime(true) - $start; } - /** - * Execute an SQL query and return an PDO result-set. - * - * @param string $query - * @param array $args - * @return PDOStatement - * @throws SCoreException - */ - public function execute($query, $args=array()) { + public function execute(string $query, array $args=array()): PDOStatement { try { if(is_null($this->db)) $this->connect_db(); - $this->count_execs($this->db, $query, $args); + $this->count_execs($query, $args); $stmt = $this->db->prepare($query); if (!array_key_exists(0, $args)) { foreach($args as $name=>$value) { @@ -755,7 +585,7 @@ class Database { * @param array $args * @return array */ - public function get_all($query, $args=array()) { + public function get_all(string $query, array $args=array()): array { $_start = microtime(true); $data = $this->execute($query, $args)->fetchAll(); $this->count_time("get_all", $_start); @@ -769,7 +599,7 @@ class Database { * @param array $args * @return array|null */ - public function get_row($query, $args=array()) { + public function get_row(string $query, array $args=array()) { $_start = microtime(true); $row = $this->execute($query, $args)->fetch(); $this->count_time("get_row", $_start); @@ -783,7 +613,7 @@ class Database { * @param array $args * @return array */ - public function get_col($query, $args=array()) { + public function get_col(string $query, array $args=array()): array { $_start = microtime(true); $stmt = $this->execute($query, $args); $res = array(); @@ -795,13 +625,13 @@ class Database { } /** - * Execute an SQL query and return the the first row => the second rown. + * Execute an SQL query and return the the first row => the second row. * * @param string $query * @param array $args * @return array */ - public function get_pairs($query, $args=array()) { + public function get_pairs(string $query, array $args=array()): array { $_start = microtime(true); $stmt = $this->execute($query, $args); $res = array(); @@ -817,9 +647,9 @@ class Database { * * @param string $query * @param array $args - * @return mixed + * @return mixed|null */ - public function get_one($query, $args=array()) { + public function get_one(string $query, array $args=array()) { $_start = microtime(true); $row = $this->execute($query, $args)->fetch(); $this->count_time("get_one", $_start); @@ -832,7 +662,7 @@ class Database { * @param string|null $seq * @return int */ - public function get_last_insert_id($seq) { + public function get_last_insert_id(string $seq): int { if($this->engine->name == "pgsql") { return $this->db->lastInsertId($seq); } @@ -847,7 +677,7 @@ class Database { * @param string $name * @param string $data */ - public function create_table($name, $data) { + public function create_table(string $name, string $data) { if(is_null($this->engine)) { $this->connect_engine(); } $data = trim($data, ", \t\n\r\0\x0B"); // mysql doesn't like trailing commas $this->execute($this->engine->create_table_sql($name, $data)); @@ -856,27 +686,26 @@ class Database { /** * Returns the number of tables present in the current database. * - * @return int|null + * @return int + * @throws SCoreException */ - public function count_tables() { - + public function count_tables(): int { if(is_null($this->db) || is_null($this->engine)) $this->connect_db(); if($this->engine->name === "mysql") { return count( - $this->get_all("SHOW TABLES") - ); + $this->get_all("SHOW TABLES") + ); } else if ($this->engine->name === "pgsql") { return count( - $this->get_all("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'") - ); + $this->get_all("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'") + ); } else if ($this->engine->name === "sqlite") { return count( - $this->get_all("SELECT name FROM sqlite_master WHERE type = 'table'") - ); + $this->get_all("SELECT name FROM sqlite_master WHERE type = 'table'") + ); } else { - // Hard to find a universal way to do this... - return NULL; + throw new SCoreException("Can't count tables for database type {$this->engine->name}"); } } } @@ -889,20 +718,20 @@ class MockDatabase extends Database { /** @var \NoCache|null */ public $cache = null; - /** - * @param array $responses - */ - public function __construct($responses = array()) { + public function __construct(array $responses = array()) { $this->cache = new NoCache(); $this->responses = $responses; } - /** - * @param string $query - * @param array $params - * @return PDOStatement - */ - public function execute($query, $params=array()) { + public function execute(string $query, array $params=array()): PDOStatement { + log_debug("mock-database", + "QUERY: " . $query . + "\nARGS: " . var_export($params, true) . + "\nRETURN: " . var_export($this->responses[$this->query_id], true) + ); + return $this->responses[$this->query_id++]; + } + public function _execute(string $query, array $params=array()) { log_debug("mock-database", "QUERY: " . $query . "\nARGS: " . var_export($params, true) . @@ -911,53 +740,16 @@ class MockDatabase extends Database { return $this->responses[$this->query_id++]; } - /** - * @param string $query - * @param array $args - * @return PDOStatement - */ - public function get_all($query, $args=array()) {return $this->execute($query, $args);} + public function get_all(string $query, array $args=array()): array {return $this->_execute($query, $args);} + public function get_row(string $query, array $args=array()) {return $this->_execute($query, $args);} + public function get_col(string $query, array $args=array()): array {return $this->_execute($query, $args);} + public function get_pairs(string $query, array $args=array()): array {return $this->_execute($query, $args);} + public function get_one(string $query, array $args=array()) {return $this->_execute($query, $args);} - /** - * @param string $query - * @param array $args - * @return PDOStatement - */ - public function get_row($query, $args=array()) {return $this->execute($query, $args);} + public function get_last_insert_id(string $seq): int {return $this->query_id;} - /** - * @param string $query - * @param array $args - * @return PDOStatement - */ - public function get_col($query, $args=array()) {return $this->execute($query, $args);} - - /** - * @param string $query - * @param array $args - * @return PDOStatement - */ - public function get_pairs($query, $args=array()) {return $this->execute($query, $args);} - - /** - * @param string $query - * @param array $args - * @return PDOStatement - */ - public function get_one($query, $args=array()) {return $this->execute($query, $args);} - - /** - * @param null|string $seq - * @return int|string - */ - public function get_last_insert_id($seq) {return $this->query_id;} - - /** - * @param string $sql - * @return string - */ - public function scoreql_to_sql($sql) {return $sql;} - public function create_table($name, $def) {} + public function scoreql_to_sql(string $sql): string {return $sql;} + public function create_table(string $name, string $def) {} public function connect_engine() {} } diff --git a/core/email.class.php b/core/email.class.php index d43e4dc4..eff609f2 100644 --- a/core/email.class.php +++ b/core/email.class.php @@ -29,13 +29,7 @@ class Email { /** @var null|string */ public $footer; - /** - * @param string $to - * @param string $subject - * @param string $header - * @param string $body - */ - public function __construct($to, $subject, $header, $body) { + public function __construct(string $to, string $subject, string $header, string $body) { global $config; $this->to = $to; @@ -60,7 +54,7 @@ class Email { $this->footer = $config->get_string("mail_fot"); } - public function send() { + public function send(): bool { $headers = "From: ".$this->sitename." <".$this->siteemail.">\r\n"; $headers .= "Reply-To: ".$this->siteemail."\r\n"; $headers .= "X-Mailer: PHP/" . phpversion(). "\r\n"; @@ -84,7 +78,7 @@ class Email { - diff --git a/core/event.class.php b/core/event.class.php index 37511e29..1544f920 100644 --- a/core/event.class.php +++ b/core/event.class.php @@ -43,10 +43,7 @@ class PageRequestEvent extends Event { */ public $part_count; - /** - * @param string $path - */ - public function __construct($path) { + public function __construct(string $path) { global $config; // trim starting slashes @@ -82,7 +79,7 @@ class PageRequestEvent extends Event { * @param string $name * @return bool */ - public function page_matches(/*string*/ $name) { + public function page_matches(string $name): bool { $parts = explode("/", $name); $this->part_count = count($parts); @@ -105,7 +102,7 @@ class PageRequestEvent extends Event { * @param int $n * @return string|null The argument (string) or NULL */ - public function get_arg(/*int*/ $n) { + public function get_arg(int $n) { $offset = $this->part_count + $n; if($offset >= 0 && $offset < $this->arg_count) { return $this->args[$offset]; @@ -119,7 +116,7 @@ class PageRequestEvent extends Event { * Returns the number of arguments the page request has. * @return int */ - public function count_args() { + public function count_args(): int { return int_escape($this->arg_count - $this->part_count); } @@ -127,10 +124,7 @@ class PageRequestEvent extends Event { * Many things use these functions */ - /** - * @return array - */ - public function get_search_terms() { + public function get_search_terms(): array { $search_terms = array(); if($this->count_args() === 2) { $search_terms = Tag::explode($this->get_arg(0)); @@ -138,10 +132,7 @@ class PageRequestEvent extends Event { return $search_terms; } - /** - * @return int - */ - public function get_page_number() { + public function get_page_number(): int { $page_number = 1; if($this->count_args() === 1) { $page_number = int_escape($this->get_arg(0)); @@ -153,10 +144,7 @@ class PageRequestEvent extends Event { return $page_number; } - /** - * @return int - */ - public function get_page_size() { + public function get_page_size(): int { global $config; return $config->get_int('index_images'); } @@ -180,7 +168,7 @@ class CommandEvent extends Event { /** * @param string[] $args */ - public function __construct(/*array(string)*/ $args) { + public function __construct(array $args) { global $user; $opts = array(); @@ -257,10 +245,7 @@ class TextFormattingEvent extends Event { */ public $stripped; - /** - * @param string $text - */ - public function __construct(/*string*/ $text) { + public function __construct(string $text) { $h_text = html_escape(trim($text)); $this->original = $h_text; $this->formatted = $h_text; @@ -308,13 +293,7 @@ class LogEvent extends Event { */ public $args; - /** - * @param string $section - * @param int $priority - * @param string $message - * @param array $args - */ - public function __construct($section, $priority, $message, $args) { + public function __construct(string $section, int $priority, string $message, array $args) { $this->section = $section; $this->priority = $priority; $this->message = $message; diff --git a/core/extension.class.php b/core/extension.class.php index dc8a1ccd..f07f074e 100644 --- a/core/extension.class.php +++ b/core/extension.class.php @@ -92,10 +92,7 @@ abstract class Extension { $this->theme = $this->get_theme_object(get_called_class()); } - /** - * @return boolean - */ - public function is_live() { + public function is_live(): bool { global $database; return ( empty($this->db_support) || @@ -107,9 +104,9 @@ abstract class Extension { * Find the theme object for a given extension. * * @param string $base - * @return Themelet + * @return Themelet|null */ - private function get_theme_object($base) { + private function get_theme_object(string $base) { $custom = 'Custom'.$base.'Theme'; $normal = $base.'Theme'; @@ -126,11 +123,10 @@ abstract class Extension { /** * Override this to change the priority of the extension, - * lower numbered ones will recieve events first. - * + * lower numbered ones will receive events first. * @return int */ - public function get_priority() { + public function get_priority(): int { return 50; } } @@ -141,25 +137,13 @@ abstract class Extension { * Several extensions have this in common, make a common API. */ abstract class FormatterExtension extends Extension { - /** - * @param TextFormattingEvent $event - */ public function onTextFormatting(TextFormattingEvent $event) { $event->formatted = $this->format($event->formatted); $event->stripped = $this->strip($event->stripped); } - /** - * @param string $text - * @return string - */ - abstract public function format(/*string*/ $text); - - /** - * @param string $text - * @return string - */ - abstract public function strip(/*string*/ $text); + abstract public function format(string $text): string; + abstract public function strip(string $text): string; } /** @@ -169,10 +153,6 @@ abstract class FormatterExtension extends Extension { * so we have a base class to extend from. */ abstract class DataHandlerExtension extends Extension { - /** - * @param DataUploadEvent $event - * @throws UploadException - */ public function onDataUpload(DataUploadEvent $event) { $supported_ext = $this->supported_ext($event->type); $check_contents = $this->check_contents($event->tmpname); @@ -236,9 +216,6 @@ abstract class DataHandlerExtension extends Extension { } } - /** - * @param ThumbnailGenerationEvent $event - */ public function onThumbnailGeneration(ThumbnailGenerationEvent $event) { if($this->supported_ext($event->type)) { if (method_exists($this, 'create_thumb_force') && $event->force == true) { @@ -250,9 +227,6 @@ abstract class DataHandlerExtension extends Extension { } } - /** - * @param DisplayingImageEvent $event - */ public function onDisplayingImage(DisplayingImageEvent $event) { global $page; if($this->supported_ext($event->image->ext)) { @@ -269,29 +243,9 @@ abstract class DataHandlerExtension extends Extension { protected function setup() {} */ - /** - * @param string $ext - * @return bool - */ - abstract protected function supported_ext($ext); - - /** - * @param string $tmpname - * @return bool - */ - abstract protected function check_contents($tmpname); - - /** - * @param string $filename - * @param array $metadata - * @return Image|null - */ - abstract protected function create_image_from_data($filename, $metadata); - - /** - * @param string $hash - * @return bool - */ - abstract protected function create_thumb($hash); + abstract protected function supported_ext(string $ext): bool; + abstract protected function check_contents(string $tmpname): bool; + abstract protected function create_image_from_data(string $filename, array $metadata); + abstract protected function create_thumb(string $hash): bool; } diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 0ee89a09..0a5924c7 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -72,17 +72,15 @@ class Image { public $source; /** @var boolean */ - public $locked; + public $locked = false; /** * One will very rarely construct an image directly, more common * would be to use Image::by_id, Image::by_hash, etc. * - * @param null|mixed $row + * @param null|mixed[] $row */ - public function __construct($row=null) { - assert('is_null($row) || is_array($row)'); - + public function __construct(array $row=null) { if(!is_null($row)) { foreach($row as $name => $value) { // some databases use table.name rather than name @@ -97,40 +95,19 @@ class Image { } } - /** - * Find an image by ID. - * - * @param int $id - * @return Image - */ - public static function by_id(/*int*/ $id) { - assert('is_numeric($id)'); + public static function by_id(int $id) { global $database; $row = $database->get_row("SELECT * FROM images WHERE images.id=:id", array("id"=>$id)); return ($row ? new Image($row) : null); } - /** - * Find an image by hash. - * - * @param string $hash - * @return Image - */ - public static function by_hash(/*string*/ $hash) { - assert('is_string($hash)'); + public static function by_hash(string $hash) { global $database; $row = $database->get_row("SELECT images.* FROM images WHERE hash=:hash", array("hash"=>$hash)); return ($row ? new Image($row) : null); } - /** - * Pick a random image out of a set. - * - * @param string[] $tags - * @return Image - */ - public static function by_random($tags=array()) { - assert('is_array($tags)'); + public static function by_random(array $tags=array()) { $max = Image::count_images($tags); if ($max < 1) return null; // From Issue #22 - opened by HungryFeline on May 30, 2011. $rand = mt_rand(0, $max-1); @@ -148,10 +125,7 @@ class Image { * @throws SCoreException * @return Image[] */ - public static function find_images(/*int*/ $start, /*int*/ $limit, $tags=array()) { - assert('is_numeric($start)'); - assert('is_numeric($limit)'); - assert('is_array($tags)'); + public static function find_images(int $start, int $limit, array $tags=array()): array { global $database, $user, $config; $images = array(); @@ -185,11 +159,7 @@ class Image { return $images; } - /** - * @param string[] $tags - * @return boolean - */ - public static function validate_accel($tags) { + public static function validate_accel(array $tags): bool { $yays = 0; $nays = 0; foreach($tags as $tag) { @@ -202,14 +172,7 @@ class Image { return ($yays > 1 || $nays > 0); } - /** - * @param string[] $tags - * @param int $offset - * @param int $limit - * @return null|PDOStatement - * @throws SCoreException - */ - public static function get_accelerated_result($tags, $offset, $limit) { + public static function get_accelerated_result(array $tags, int $offset, int $limit) { global $database; if(!Image::validate_accel($tags)) { @@ -262,15 +225,14 @@ class Image { * @param string[] $tags * @return int */ - public static function count_images($tags=array()) { - assert('is_array($tags)'); + public static function count_images(array $tags=array()): int { global $database; $tag_count = count($tags); if($tag_count === 0) { $total = $database->cache->get("image-count"); if(!$total) { - $total = $database->get_one("SELECT COUNT(*) FROM images"); + $total = $database->get_one("SELECT COUNT(*) FROM images") || 0; $database->cache->set("image-count", $total, 600); } return $total; @@ -278,11 +240,11 @@ class Image { else if($tag_count === 1 && !preg_match("/[:=><\*\?]/", $tags[0])) { return $database->get_one( $database->scoreql_to_sql("SELECT count FROM tags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)"), - array("tag"=>$tags[0])); + array("tag"=>$tags[0])) || 0; } else { $querylet = Image::build_search_querylet($tags); - return $database->get_one("SELECT COUNT(*) AS cnt FROM ($querylet->sql) AS tbl", $querylet->variables); + return $database->get_one("SELECT COUNT(*) AS cnt FROM ($querylet->sql) AS tbl", $querylet->variables) || 0; } } @@ -292,8 +254,7 @@ class Image { * @param string[] $tags * @return float */ - public static function count_pages($tags=array()) { - assert('is_array($tags)'); + public static function count_pages(array $tags=array()): float { global $config; return ceil(Image::count_images($tags) / $config->get_int('index_images')); } @@ -312,9 +273,7 @@ class Image { * @param bool $next * @return Image */ - public function get_next($tags=array(), $next=true) { - assert('is_array($tags)'); - assert('is_bool($next)'); + public function get_next(array $tags=array(), bool $next=true) { global $database; if($next) { @@ -351,7 +310,7 @@ class Image { * @param string[] $tags * @return Image */ - public function get_prev($tags=array()) { + public function get_prev(array $tags=array()) { return $this->get_next($tags, false); } @@ -543,7 +502,7 @@ class Image { * * @param string $new_source */ - public function set_source(/*string*/ $new_source) { + public function set_source(string $new_source) { global $database; $old_source = $this->source; if(empty($new_source)) $new_source = null; @@ -617,8 +576,8 @@ class Image { * @param string[] $tags * @throws Exception */ - public function set_tags($tags) { - assert('is_array($tags) && count($tags) > 0', var_export($tags, true)); + public function set_tags(array $tags) { + assert('count($tags) > 0', var_export($tags, true)); global $database; if(count($tags) <= 0) { @@ -792,8 +751,7 @@ class Image { * @param string[] $terms * @return \Querylet */ - private static function build_search_querylet($terms) { - assert('is_array($terms)'); + private static function build_search_querylet(array $terms): Querylet { global $database; $tag_querylets = array(); @@ -935,7 +893,7 @@ class Image { * @param TagQuerylet[] $tag_querylets * @return Querylet */ - private static function build_accurate_search_querylet($tag_querylets) { + private static function build_accurate_search_querylet(array $tag_querylets): Querylet { global $database; $positive_tag_id_array = array(); @@ -1080,13 +1038,7 @@ class Image { * */ class Tag { - /** - * @param string[] $tags - * @return string - */ - public static function implode($tags) { - assert('is_array($tags)'); - + public static function implode(array $tags): string { sort($tags); $tags = implode(' ', $tags); @@ -1100,9 +1052,8 @@ class Tag { * @param bool $tagme add "tagme" if the string is empty * @return string[] */ - public static function explode($tags, $tagme=true) { + public static function explode(string $tags, bool $tagme=true): array { global $database; - assert('is_string($tags)'); $tags = explode(' ', trim($tags)); @@ -1266,7 +1217,7 @@ function add_image($tmpname, $filename, $tags) { * @param int $orig_height * @return integer[] */ -function get_thumbnail_size(/*int*/ $orig_width, /*int*/ $orig_height) { +function get_thumbnail_size(int $orig_width, int $orig_height) { global $config; if($orig_width === 0) $orig_width = 192; diff --git a/core/page.class.php b/core/page.class.php index 3d02bbe6..924f200d 100644 --- a/core/page.class.php +++ b/core/page.class.php @@ -47,7 +47,7 @@ class Page { * Set what this page should do; "page", "data", or "redirect". * @param string $mode */ - public function set_mode($mode) { + public function set_mode(string $mode) { $this->mode = $mode; } @@ -55,7 +55,7 @@ class Page { * Set the page's MIME type. * @param string $type */ - public function set_type($type) { + public function set_type(string $type) { $this->type = $type; } @@ -75,7 +75,7 @@ class Page { * Set the raw data to be sent. * @param string $data */ - public function set_data($data) { + public function set_data(string $data) { $this->data = $data; } @@ -83,7 +83,7 @@ class Page { * Set the recommended download filename. * @param string $filename */ - public function set_filename($filename) { + public function set_filename(string $filename) { $this->filename = $filename; } @@ -101,7 +101,7 @@ class Page { * to a page in the same site). * @param string $redirect */ - public function set_redirect($redirect) { + public function set_redirect(string $redirect) { $this->redirect = $redirect; } @@ -142,31 +142,19 @@ class Page { * Set the HTTP status code * @param int $code */ - public function set_code($code) { + public function set_code(int $code) { $this->code = $code; } - /** - * Set the window title. - * @param string $title - */ - public function set_title($title) { + public function set_title(string $title) { $this->title = $title; } - /** - * Set the main heading. - * @param string $heading - */ - public function set_heading($heading) { + public function set_heading(string $heading) { $this->heading = $heading; } - /** - * Set the sub heading. - * @param string $subheading - */ - public function set_subheading($subheading) { + public function set_subheading(string $subheading) { $this->subheading = $subheading; } @@ -175,7 +163,7 @@ class Page { * @param string $line * @param int $position */ - public function add_html_header($line, $position=50) { + public function add_html_header(string $line, int $position=50) { while(isset($this->html_headers[$position])) $position++; $this->html_headers[$position] = $line; } @@ -185,7 +173,7 @@ class Page { * @param string $line * @param int $position */ - public function add_http_header($line, $position=50) { + public function add_http_header(string $line, int $position=50) { while(isset($this->http_headers[$position])) $position++; $this->http_headers[$position] = $line; } @@ -200,7 +188,7 @@ class Page { * @param int $time * @param string $path */ - public function add_cookie($name, $value, $time, $path) { + public function add_cookie(string $name, $value, $time, $path) { $full_name = COOKIE_PREFIX."_".$name; $this->cookies[] = array($full_name, $value, $time, $path); } @@ -209,7 +197,7 @@ class Page { * @param string $name * @return string|null */ - public function get_cookie(/*string*/ $name) { + public function get_cookie(string $name) { $full_name = COOKIE_PREFIX."_".$name; if(isset($_COOKIE[$full_name])) { return $_COOKIE[$full_name]; @@ -223,7 +211,7 @@ class Page { * Get all the HTML headers that are currently set and return as a string. * @return string */ - public function get_all_html_headers() { + public function get_all_html_headers(): string { $data = ''; ksort($this->html_headers); foreach ($this->html_headers as $line) { diff --git a/core/sys_config.inc.php b/core/sys_config.inc.php index 744ac13f..c91190ac 100644 --- a/core/sys_config.inc.php +++ b/core/sys_config.inc.php @@ -19,8 +19,7 @@ * */ -/** @private */ -function _d($name, $value) {if(!defined($name)) define($name, $value);} +function _d(string $name, $value) {if(!defined($name)) define($name, $value);} _d("DATABASE_DSN", null); // string PDO database connection details _d("DATABASE_KA", true); // string Keep database connection alive _d("CACHE_DSN", null); // string cache connection details diff --git a/core/user.class.php b/core/user.class.php index 662300cd..17953bfa 100644 --- a/core/user.class.php +++ b/core/user.class.php @@ -48,10 +48,10 @@ class User { * One will very rarely construct a user directly, more common * would be to use User::by_id, User::by_session, etc. * - * @param mixed $row + * @param mixed[] $row * @throws SCoreException */ - public function __construct($row) { + public function __construct(array $row) { global $_shm_user_classes; $this->id = int_escape($row['id']); @@ -68,14 +68,7 @@ class User { } } - /** - * Construct a User by session. - * - * @param string $name - * @param string $session - * @return null|User - */ - public static function by_session(/*string*/ $name, /*string*/ $session) { + public static function by_session(string $name, string $session) { global $config, $database; $row = $database->cache->get("user-session:$name-$session"); if(!$row) { @@ -91,13 +84,7 @@ class User { return is_null($row) ? null : new User($row); } - /** - * Construct a User by session. - * @param int $id - * @return null|User - */ - public static function by_id(/*int*/ $id) { - assert('is_numeric($id)', var_export($id, true)); + public static function by_id(int $id) { global $database; if($id === 1) { $cached = $database->cache->get('user-id:'.$id); @@ -108,27 +95,13 @@ class User { return is_null($row) ? null : new User($row); } - /** - * Construct a User by name. - * @param string $name - * @return null|User - */ - public static function by_name(/*string*/ $name) { - assert('is_string($name)', var_export($name, true)); + public static function by_name(string $name) { global $database; $row = $database->get_row($database->scoreql_to_sql("SELECT * FROM users WHERE SCORE_STRNORM(name) = SCORE_STRNORM(:name)"), array("name"=>$name)); return is_null($row) ? null : new User($row); } - /** - * Construct a User by name and password. - * @param string $name - * @param string $pass - * @return null|User - */ - public static function by_name_and_pass(/*string*/ $name, /*string*/ $pass) { - assert('is_string($name)', var_export($name, true)); - assert('is_string($pass)', var_export($pass, true)); + public static function by_name_and_pass(string $name, string $pass) { $user = User::by_name($name); if($user) { if($user->passhash == md5(strtolower($name) . $pass)) { @@ -138,65 +111,38 @@ class User { return $user; } } + return null; } /* useful user object functions start here */ - - /** - * @param string $ability - * @return bool - */ - public function can($ability) { + public function can(string $ability): bool { return $this->class->can($ability); } - /** - * Test if this user is anonymous (not logged in). - * - * @return bool - */ - public function is_anonymous() { + public function is_anonymous(): bool { global $config; return ($this->id === $config->get_int('anon_id')); } - /** - * Test if this user is logged in. - * - * @return bool - */ - public function is_logged_in() { + public function is_logged_in(): bool { global $config; return ($this->id !== $config->get_int('anon_id')); } - /** - * Test if this user is an administrator. - * - * @return bool - */ - public function is_admin() { + public function is_admin(): bool { return ($this->class->name === "admin"); } - /** - * @param string $class - */ - public function set_class(/*string*/ $class) { - assert('is_string($class)', var_export($class, true)); + public function set_class(string $class) { global $database; $database->Execute("UPDATE users SET class=:class WHERE id=:id", array("class"=>$class, "id"=>$this->id)); log_info("core-user", 'Set class for '.$this->name.' to '.$class); } - /** - * @param string $name - * @throws Exception - */ - public function set_name(/*string*/ $name) { + public function set_name(string $name) { global $database; if(User::by_name($name)) { throw new Exception("Desired username is already in use"); @@ -207,10 +153,7 @@ class User { log_info("core-user", "Changed username for {$old_name} to {$this->name}"); } - /** - * @param string $password - */ - public function set_password(/*string*/ $password) { + public function set_password(string $password) { global $database; $hash = password_hash($password, PASSWORD_BCRYPT); if(is_string($hash)) { @@ -223,10 +166,7 @@ class User { } } - /** - * @param string $address - */ - public function set_email(/*string*/ $address) { + public function set_email(string $address) { global $database; $database->Execute("UPDATE users SET email=:email WHERE id=:id", array("email"=>$address, "id"=>$this->id)); log_info("core-user", 'Set email for '.$this->name); @@ -238,7 +178,7 @@ class User { * * @return String of HTML */ - public function get_avatar_html() { + public function get_avatar_html(): string { // FIXME: configurable global $config; if($config->get_string("avatar_host") === "gravatar") { @@ -267,25 +207,25 @@ class User { * * @return string A string containing auth token (MD5sum) */ - public function get_auth_token() { + public function get_auth_token(): string { global $config; $salt = DATABASE_DSN; $addr = get_session_ip($config); return md5(md5($this->passhash . $addr) . "salty-csrf-" . $salt); } - public function get_auth_html() { + public function get_auth_html(): string { $at = $this->get_auth_token(); return ''; } - public function check_auth_token() { + public function check_auth_token(): bool { return (isset($_POST["auth_token"]) && $_POST["auth_token"] == $this->get_auth_token()); } } class MockUser extends User { - public function __construct($name) { + public function __construct(string $name) { $row = array( "name" => $name, "id" => 1, diff --git a/core/userclass.class.php b/core/userclass.class.php index 5780b3fe..a8cbe49b 100644 --- a/core/userclass.class.php +++ b/core/userclass.class.php @@ -25,12 +25,7 @@ class UserClass { */ public $abilities = array(); - /** - * @param string $name - * @param null|string $parent - * @param array $abilities - */ - public function __construct($name, $parent=null, $abilities=array()) { + public function __construct(string $name, string $parent=null, array $abilities=array()) { global $_shm_user_classes; $this->name = $name; @@ -50,7 +45,7 @@ class UserClass { * @return bool * @throws SCoreException */ - public function can(/*string*/ $ability) { + public function can(string $ability): bool { if(array_key_exists($ability, $this->abilities)) { $val = $this->abilities[$ability]; return $val; diff --git a/core/util.inc.php b/core/util.inc.php index bd425d89..f60c263e 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -11,7 +11,7 @@ require_once "vendor/shish/libcontext-php/context.php"; * @param string $input * @return string */ -function html_escape($input) { +function html_escape($input): string { return htmlentities($input, ENT_QUOTES, "UTF-8"); } @@ -21,7 +21,7 @@ function html_escape($input) { * @param string $input * @return string */ -function html_unescape($input) { +function html_unescape($input): string { return html_entity_decode($input, ENT_QUOTES, "UTF-8"); } @@ -31,7 +31,7 @@ function html_unescape($input) { * @param string $input * @return int */ -function int_escape($input) { +function int_escape($input): int { /* Side note, Casting to an integer is FASTER than using intval. http://hakre.wordpress.com/2010/05/13/php-casting-vs-intval/ @@ -45,7 +45,7 @@ function int_escape($input) { * @param string $input * @return string */ -function url_escape($input) { +function url_escape($input): string { /* Shish: I have a feeling that these three lines are important, possibly for searching for tags with slashes in them like fate/stay_night green-ponies: indeed~ @@ -80,7 +80,7 @@ function url_escape($input) { * @param string $input * @return string */ -function sql_escape($input) { +function sql_escape($input): string { global $database; return $database->escape($input); } @@ -92,7 +92,7 @@ function sql_escape($input) { * @param mixed $input * @return boolean */ -function bool_escape($input) { +function bool_escape($input): bool { /* Sometimes, I don't like PHP -- this, is one of those times... "a boolean FALSE is not considered a valid boolean value by this function." @@ -132,13 +132,7 @@ function no_escape($input) { return $input; } -/** - * @param int $val - * @param int|null $min - * @param int|null $max - * @return int - */ -function clamp($val, $min, $max) { +function clamp(int $val, int $min=null, int $max=null): int { if(!is_numeric($val) || (!is_null($min) && $val < $min)) { $val = $min; } @@ -151,13 +145,7 @@ function clamp($val, $min, $max) { return $val; } -/** - * @param string $name - * @param array $attrs - * @param array $children - * @return string - */ -function xml_tag($name, $attrs=array(), $children=array()) { +function xml_tag(string $name, array $attrs=array(), array $children=array()): string { $xml = "<$name "; foreach($attrs as $k => $v) { $xv = str_replace(''', ''', htmlspecialchars($v, ENT_QUOTES)); @@ -184,6 +172,7 @@ function xml_tag($name, $attrs=array(), $children=array()) { * @param int $limit how long the string should be * @param string $break where to break the string * @param string $pad what to add to the end of the string after truncating + * @return string */ function truncate($string, $limit, $break=" ", $pad="...") { // return with no change if string is shorter than $limit @@ -202,14 +191,10 @@ function truncate($string, $limit, $break=" ", $pad="...") { /** * Turn a human readable filesize into an integer, eg 1KB -> 1024 * - * @param string|integer $limit + * @param string $limit * @return int */ -function parse_shorthand_int($limit) { - if(is_numeric($limit)) { - return (int)$limit; - } - +function parse_shorthand_int(string $limit): int { if(preg_match('/^([\d\.]+)([gmk])?b?$/i', (string)$limit, $m)) { $value = $m[1]; if (isset($m[2])) { @@ -235,7 +220,7 @@ function parse_shorthand_int($limit) { * @param integer $int * @return string */ -function to_shorthand_int($int) { +function to_shorthand_int(int $int): string { if($int >= pow(1024, 3)) { return sprintf("%.1fGB", $int / pow(1024, 3)); } @@ -258,7 +243,7 @@ function to_shorthand_int($int) { * @param bool $html * @return string */ -function autodate($date, $html=true) { +function autodate(string $date, bool $html=true): string { $cpu = date('c', strtotime($date)); $hum = date('F j, Y; H:i', strtotime($date)); return ($html ? "" : $hum); @@ -270,7 +255,7 @@ function autodate($date, $html=true) { * @param string $dateTime * @return bool */ -function isValidDateTime($dateTime) { +function isValidDateTime(string $dateTime): bool { if (preg_match("/^(\d{4})-(\d{2})-(\d{2}) ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/", $dateTime, $matches)) { if (checkdate($matches[2], $matches[3], $matches[1])) { return true; @@ -286,7 +271,7 @@ function isValidDateTime($dateTime) { * @param string $date * @return bool */ -function isValidDate($date) { +function isValidDate(string $date): bool { if (preg_match("/^(\d{4})-(\d{2})-(\d{2})$/", $date, $matches)) { // checkdate wants (month, day, year) if (checkdate($matches[2], $matches[3], $matches[1])) { @@ -297,10 +282,7 @@ function isValidDate($date) { return false; } -/** - * @param string[] $inputs - */ -function validate_input($inputs) { +function validate_input(array $inputs): array { $outputs = array(); foreach($inputs as $key => $validations) { @@ -398,7 +380,7 @@ function validate_input($inputs) { * @param string $ban_reason * @return string */ -function show_ip($ip, $ban_reason) { +function show_ip(string $ip, string $ban_reason): string { global $user; $u_reason = url_escape($ban_reason); $u_end = url_escape("+1 week"); @@ -407,26 +389,12 @@ function show_ip($ip, $ban_reason) { return $ip; } -/** - * Checks if a given string contains another at the beginning. - * - * @param string $haystack String to examine. - * @param string $needle String to look for. - * @return bool - */ -function startsWith(/*string*/ $haystack, /*string*/ $needle) { +function startsWith(string $haystack, string $needle): bool { $length = strlen($needle); return (substr($haystack, 0, $length) === $needle); } -/** - * Checks if a given string contains another at the end. - * - * @param string $haystack String to examine. - * @param string $needle String to look for. - * @return bool - */ -function endsWith(/*string*/ $haystack, /*string*/ $needle) { +function endsWith(string $haystack, string $needle): bool { $length = strlen($needle); $start = $length * -1; //negative return (substr($haystack, $start) === $needle); @@ -446,7 +414,7 @@ function endsWith(/*string*/ $haystack, /*string*/ $needle) { * @param null|string $query * @return string */ -function make_link($page=null, $query=null) { +function make_link(string $page=null, string $query=null): string { global $config; if(is_null($page)) $page = $config->get_string('main_page'); @@ -481,14 +449,14 @@ function make_link($page=null, $query=null) { /** * Take the current URL and modify some parameters * - * @param $changes + * @param array $changes * @return string */ -function modify_current_url($changes) { +function modify_current_url(array $changes): string { return modify_url($_SERVER['QUERY_STRING'], $changes); } -function modify_url($url, $changes) { +function modify_url(string $url, array $changes): string { // SHIT: PHP is officially the worst web API ever because it does not // have a built-in function to do this. @@ -526,7 +494,7 @@ function modify_url($url, $changes) { * @param string $link * @return string */ -function make_http(/*string*/ $link) { +function make_http(string $link) { if(strpos($link, "://") > 0) { return $link; } @@ -553,7 +521,7 @@ function make_http(/*string*/ $link) { * * @return string */ -function make_form($target, $method="POST", $multipart=False, $form_id="", $onsubmit="") { +function make_form(string $target, string $method="POST", bool $multipart=False, string $form_id="", string $onsubmit=""): string { global $user; if($method == "GET") { $link = html_escape($target); @@ -578,7 +546,7 @@ function make_form($target, $method="POST", $multipart=False, $form_id="", $onsu * @param string $file The filename * @return string */ -function mtimefile($file) { +function mtimefile(string $file): string { $data_href = get_base_href(); $mtime = filemtime($file); return "$data_href/$file?$mtime"; @@ -589,7 +557,7 @@ function mtimefile($file) { * * @return string */ -function get_theme() { +function get_theme(): string { global $config; $theme = $config->get_string("theme", "default"); if(!file_exists("themes/$theme")) $theme = "default"; @@ -602,7 +570,7 @@ function get_theme() { * @param string $pattern * @return array */ -function zglob($pattern) { +function zglob(string $pattern): array { $results = array(); if(preg_match('/(.*)\{(.*)\}(.*)/', $pattern, $matches)) { $braced = explode(",", $matches[2]); @@ -621,11 +589,13 @@ function zglob($pattern) { /** * Gets contact link as mailto: or http: - * @return string + * @return string|null */ function contact_link() { global $config; $text = $config->get_string('contact_link'); + if(is_null($text)) return null; + if( startsWith($text, "http:") || startsWith($text, "https:") || @@ -650,10 +620,7 @@ function contact_link() { * CAPTCHA abstraction * \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/** - * @return string - */ -function captcha_get_html() { +function captcha_get_html(): string { global $config, $user; if(DEBUG && ip_in_range($_SERVER['REMOTE_ADDR'], "127.0.0.0/8")) return ""; @@ -673,10 +640,7 @@ function captcha_get_html() { return $captcha; } -/** - * @return bool - */ -function captcha_check() { +function captcha_check(): bool { global $config, $user; if(DEBUG && ip_in_range($_SERVER['REMOTE_ADDR'], "127.0.0.0/8")) return true; @@ -715,10 +679,27 @@ function captcha_check() { * * @return bool True if HTTPS is enabled */ -function is_https_enabled() { +function is_https_enabled(): bool { return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'); } +define("MIME_TYPE_MAP", [ + 'jpg' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', + 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'ico' => 'image/x-icon', + 'swf' => 'application/x-shockwave-flash', 'video/x-flv' => 'flv', + 'svg' => 'image/svg+xml', 'pdf' => 'application/pdf', + 'zip' => 'application/zip', 'gz' => 'application/x-gzip', + 'tar' => 'application/x-tar', 'bz' => 'application/x-bzip', + 'bz2' => 'application/x-bzip2', 'txt' => 'text/plain', + 'asc' => 'text/plain', 'htm' => 'text/html', 'html' => 'text/html', + 'css' => 'text/css', 'js' => 'text/javascript', + 'xml' => 'text/xml', 'xsl' => 'application/xsl+xml', + 'ogg' => 'application/ogg', 'mp3' => 'audio/mpeg', 'wav' => 'audio/x-wav', + 'avi' => 'video/x-msvideo', 'mpg' => 'video/mpeg', 'mpeg' => 'video/mpeg', + 'mov' => 'video/quicktime', 'flv' => 'video/x-flv', 'php' => 'text/x-php', + 'mp4' => 'video/mp4', 'ogv' => 'video/ogg', 'webm' => 'video/webm' +]); + /** * Get MIME type for file * @@ -728,33 +709,13 @@ function is_https_enabled() { * * @param string $file File path * @param string $ext - * @param bool $list * @return string */ -function getMimeType($file, $ext="", $list=false) { - +function getMimeType(string $file, string $ext=""): string { // Static extension lookup $ext = strtolower($ext); - static $exts = array( - 'jpg' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', - 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'ico' => 'image/x-icon', - 'swf' => 'application/x-shockwave-flash', 'video/x-flv' => 'flv', - 'svg' => 'image/svg+xml', 'pdf' => 'application/pdf', - 'zip' => 'application/zip', 'gz' => 'application/x-gzip', - 'tar' => 'application/x-tar', 'bz' => 'application/x-bzip', - 'bz2' => 'application/x-bzip2', 'txt' => 'text/plain', - 'asc' => 'text/plain', 'htm' => 'text/html', 'html' => 'text/html', - 'css' => 'text/css', 'js' => 'text/javascript', - 'xml' => 'text/xml', 'xsl' => 'application/xsl+xml', - 'ogg' => 'application/ogg', 'mp3' => 'audio/mpeg', 'wav' => 'audio/x-wav', - 'avi' => 'video/x-msvideo', 'mpg' => 'video/mpeg', 'mpeg' => 'video/mpeg', - 'mov' => 'video/quicktime', 'flv' => 'video/x-flv', 'php' => 'text/x-php', - 'mp4' => 'video/mp4', 'ogv' => 'video/ogg', 'webm' => 'video/webm' - ); - if ($list === true){ return $exts; } - - if (isset($exts[$ext])) { return $exts[$ext]; } + if (isset($exts[$ext])) { return MIME_TYPE_MAP[$ext]; } $type = false; // Fileinfo documentation says fileinfo_open() will use the @@ -785,13 +746,12 @@ function getMimeType($file, $ext="", $list=false) { * @param string $mime_type * @return bool|string */ -function getExtension ($mime_type){ +function getExtension(string $mime_type) { if(empty($mime_type)){ return false; } - $extensions = getMimeType(null, null, true); - $ext = array_search($mime_type, $extensions); + $ext = array_search($mime_type, MIME_TYPE_MAP); return ($ext ? $ext : false); } @@ -816,7 +776,7 @@ function blockcmp(Block $a, Block $b) { * * @return int */ -function get_memory_limit() { +function get_memory_limit(): int { global $config; // thumbnail generation requires lots of memory @@ -866,7 +826,7 @@ function get_memory_limit() { * @param Config $config * @return string */ -function get_session_ip(Config $config) { +function get_session_ip(Config $config): string { $mask = $config->get_string("session_hash_mask", "255.255.0.0"); $addr = $_SERVER['REMOTE_ADDR']; $addr = inet_ntop(inet_pton($addr) & inet_pton($mask)); @@ -886,7 +846,7 @@ function get_session_ip(Config $config) { * @param string $text * @param string $type */ -function flash_message(/*string*/ $text, /*string*/ $type="info") { +function flash_message(string $text, string $type="info") { global $page; $current = $page->get_cookie("flash_message"); if($current) { @@ -907,7 +867,7 @@ function flash_message(/*string*/ $text, /*string*/ $type="info") { * * @return string */ -function get_base_href() { +function get_base_href(): string { if(defined("BASE_HREF")) return BASE_HREF; $possible_vars = array('SCRIPT_NAME', 'PHP_SELF', 'PATH_INFO', 'ORIG_PATH_INFO'); $ok_var = null; @@ -931,19 +891,13 @@ function get_base_href() { * @param string $string * @return string */ -function format_text(/*string*/ $string) { +function format_text(string $string): string { $tfe = new TextFormattingEvent($string); send_event($tfe); return $tfe->formatted; } -/** - * @param string $base - * @param string $hash - * @param bool $create - * @return string - */ -function warehouse_path(/*string*/ $base, /*string*/ $hash, /*bool*/ $create=true) { +function warehouse_path(string $base, string $hash, bool $create=true): string { $ab = substr($hash, 0, 2); $cd = substr($hash, 2, 2); if(WH_SPLITS == 2) { @@ -956,11 +910,7 @@ function warehouse_path(/*string*/ $base, /*string*/ $hash, /*bool*/ $create=tru return $pa; } -/** - * @param string $filename - * @return string - */ -function data_path($filename) { +function data_path(string $filename): string { $filename = "data/" . $filename; if(!file_exists(dirname($filename))) mkdir(dirname($filename), 0755, true); return $filename; @@ -982,7 +932,7 @@ if (!function_exists('mb_strlen')) { * @param string $mfile * @return array|bool */ -function transload($url, $mfile) { +function transload(string $url, string $mfile) { global $config; if($config->get_string("transload_engine") === "curl" && function_exists("curl_init")) { @@ -1076,7 +1026,7 @@ if (!function_exists('http_parse_headers')) { #http://www.php.net/manual/en/func * @param string $name * @return string|bool */ -function findHeader ($headers, $name) { +function findHeader(array $headers, string $name) { if (!is_array($headers)) { return false; } @@ -1103,7 +1053,7 @@ function findHeader ($headers, $name) { * @param string $fname * @return string|null */ -function manual_include($fname) { +function manual_include(string $fname) { static $included = array(); if(!file_exists($fname)) return null; @@ -1159,7 +1109,7 @@ define("SCORE_LOG_NOTSET", 0); * @param bool|string $flash * @param array $args */ -function log_msg(/*string*/ $section, /*int*/ $priority, /*string*/ $message, $flash=false, $args=array()) { +function log_msg(string $section, int $priority, string $message, $flash=false, $args=array()) { send_event(new LogEvent($section, $priority, $message, $args)); $threshold = defined("CLI_LOG_LEVEL") ? CLI_LOG_LEVEL : 0; @@ -1181,43 +1131,43 @@ function log_msg(/*string*/ $section, /*int*/ $priority, /*string*/ $message, $f * @param bool|string $flash * @param array $args */ -function log_debug( /*string*/ $section, /*string*/ $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_DEBUG, $message, $flash, $args);} +function log_debug( string $section, string $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_DEBUG, $message, $flash, $args);} /** * @param string $section * @param string $message * @param bool|string $flash * @param array $args */ -function log_info( /*string*/ $section, /*string*/ $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_INFO, $message, $flash, $args);} +function log_info( string $section, string $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_INFO, $message, $flash, $args);} /** * @param string $section * @param string $message * @param bool|string $flash * @param array $args */ -function log_warning( /*string*/ $section, /*string*/ $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_WARNING, $message, $flash, $args);} +function log_warning( string $section, string $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_WARNING, $message, $flash, $args);} /** * @param string $section * @param string $message * @param bool|string $flash * @param array $args */ -function log_error( /*string*/ $section, /*string*/ $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_ERROR, $message, $flash, $args);} +function log_error( string $section, string $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_ERROR, $message, $flash, $args);} /** * @param string $section * @param string $message * @param bool|string $flash * @param array $args */ -function log_critical(/*string*/ $section, /*string*/ $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_CRITICAL, $message, $flash, $args);} +function log_critical(string $section, string $message, $flash=false, $args=array()) {log_msg($section, SCORE_LOG_CRITICAL, $message, $flash, $args);} /** * Get a unique ID for this request, useful for grouping log messages. * - * @return null|string + * @return string */ -function get_request_id() { +function get_request_id(): string { static $request_id = null; if(!$request_id) { // not completely trustworthy, as a user can spoof this @@ -1243,7 +1193,7 @@ function get_request_id() { * @param mixed $to_remove * @return array */ -function array_remove($array, $to_remove) { +function array_remove(array $array, $to_remove): array { $array = array_unique($array); $a2 = array(); foreach($array as $existing) { @@ -1263,7 +1213,7 @@ function array_remove($array, $to_remove) { * @param mixed $element * @return array */ -function array_add($array, $element) { +function array_add(array $array, $element): array { // Could we just use array_push() ? // http://www.php.net/manual/en/function.array-push.php $array[] = $element; @@ -1277,7 +1227,7 @@ function array_add($array, $element) { * @param array $array * @return array */ -function array_iunique($array) { +function array_iunique(array $array): array { $ok = array(); foreach($array as $element) { $found = false; @@ -1302,7 +1252,7 @@ function array_iunique($array) { * @param string $CIDR * @return bool */ -function ip_in_range($IP, $CIDR) { +function ip_in_range(string $IP, string $CIDR): bool { list ($net, $mask) = explode("/", $CIDR); $ip_net = ip2long ($net); @@ -1323,7 +1273,7 @@ function ip_in_range($IP, $CIDR) { * * @param string $f */ -function deltree($f) { +function deltree(string $f) { //Because Windows (I know, bad excuse) if(PHP_OS === 'WINNT') { $real = realpath($f); @@ -1369,7 +1319,7 @@ function deltree($f) { * @param string $source * @param string $target */ -function full_copy($source, $target) { +function full_copy(string $source, string $target) { if(is_dir($source)) { @mkdir($target); @@ -1401,7 +1351,7 @@ function full_copy($source, $target) { * @param string $_sub_dir * @return array file list */ -function list_files(/*string*/ $base, $_sub_dir="") { +function list_files(string $base, string $_sub_dir=""): array { assert(is_dir($base)); $file_list = array(); @@ -1438,11 +1388,7 @@ function list_files(/*string*/ $base, $_sub_dir="") { return $file_list; } -/** - * @param string $path - * @return string - */ -function path_to_tags($path) { +function path_to_tags(string $path): string { $matches = array(); if(preg_match("/\d+ - (.*)\.([a-zA-Z]+)/", basename($path), $matches)) { $tags = $matches[1]; @@ -1548,7 +1494,7 @@ function _dump_event_listeners($event_listeners, $path) { * @param string $ext_name Main class name (eg ImageIO as opposed to ImageIOTheme or ImageIOTest) * @return bool */ -function ext_is_live($ext_name) { +function ext_is_live(string $ext_name): bool { if (class_exists($ext_name)) { /** @var Extension $ext */ $ext = new $ext_name(); @@ -1607,7 +1553,7 @@ $_shm_load_start = microtime(true); * * @return string debug info to add to the page. */ -function get_debug_info() { +function get_debug_info(): string { global $config, $_shm_event_count, $database, $_shm_load_start; $i_mem = sprintf("%5.2f", ((memory_get_peak_usage(true)+512)/1024)/1024); @@ -1705,9 +1651,9 @@ function _sanitise_environment() { /** * @param string $_theme - * @return array + * @return string[] */ -function _get_themelet_files($_theme) { +function _get_themelet_files(string $_theme): array { $base_themelets = array(); if(file_exists('themes/'.$_theme.'/custompage.class.php')) $base_themelets[] = 'themes/'.$_theme.'/custompage.class.php'; $base_themelets[] = 'themes/'.$_theme.'/layout.class.php'; @@ -1758,7 +1704,7 @@ function _fatal_error(Exception $e) { * @param string $str * @return string */ -function _decaret($str) { +function _decaret(string $str): string { $out = ""; $length = strlen($str); for($i=0; $i<$length; $i++) { @@ -1775,10 +1721,7 @@ function _decaret($str) { return $out; } -/** - * @return User - */ -function _get_user() { +function _get_user(): User { global $config, $page; $user = null; if($page->get_cookie("user") && $page->get_cookie("session")) { @@ -1796,7 +1739,7 @@ function _get_user() { } /** - * @return string + * @return string|null */ function _get_query() { return @$_POST["q"]?:@$_GET["q"]; diff --git a/ext/admin/main.php b/ext/admin/main.php index 446a984c..ec7843c2 100644 --- a/ext/admin/main.php +++ b/ext/admin/main.php @@ -27,9 +27,6 @@ class AdminBuildingEvent extends Event { /** @var \Page */ public $page; - /** - * @param Page $page - */ public function __construct(Page $page) { $this->page = $page; } @@ -41,10 +38,7 @@ class AdminActionEvent extends Event { /** @var bool */ public $redirect = true; - /** - * @param string $action - */ - public function __construct(/*string*/ $action) { + public function __construct(string $action) { $this->action = $action; } } diff --git a/ext/admin/theme.php b/ext/admin/theme.php index 64ee1a92..6cd83736 100644 --- a/ext/admin/theme.php +++ b/ext/admin/theme.php @@ -12,13 +12,7 @@ class AdminPageTheme extends Themelet { $page->add_block(new NavBlock()); } - /** - * @param string $name - * @param string $action - * @param bool $protected - * @return string - */ - protected function button(/*string*/ $name, /*string*/ $action, /*boolean*/ $protected=false) { + protected function button(string $name, string $action, bool $protected=false): string { $c_protected = $protected ? " protected" : ""; $html = make_form(make_link("admin/$action"), "POST", false, "admin$c_protected"); if($protected) { diff --git a/ext/alias_editor/main.php b/ext/alias_editor/main.php index d6923693..b3f5fb6b 100644 --- a/ext/alias_editor/main.php +++ b/ext/alias_editor/main.php @@ -16,11 +16,7 @@ class AddAliasEvent extends Event { /** @var string */ public $newtag; - /** - * @param string $oldtag - * @param string $newtag - */ - public function __construct($oldtag, $newtag) { + public function __construct(string $oldtag, string $newtag) { $this->oldtag = trim($oldtag); $this->newtag = trim($newtag); } @@ -131,11 +127,7 @@ class AliasEditor extends Extension { } } - /** - * @param Database $database - * @return string - */ - private function get_alias_csv(Database $database) { + private function get_alias_csv(Database $database): string { $csv = ""; $aliases = $database->get_pairs("SELECT oldtag, newtag FROM aliases ORDER BY newtag"); foreach($aliases as $old => $new) { @@ -144,11 +136,7 @@ class AliasEditor extends Extension { return $csv; } - /** - * @param Database $database - * @param string $csv - */ - private function add_alias_csv(Database $database, /*string*/ $csv) { + private function add_alias_csv(Database $database, string $csv) { $csv = str_replace("\r", "\n", $csv); foreach(explode("\n", $csv) as $line) { $parts = str_getcsv($line); @@ -170,9 +158,8 @@ class AliasEditor extends Extension { * Add alias *after* mass tag editing, else the MTE will * search for the images and be redirected to the alias, * missing out the images tagged with the old tag. - * * @return int */ - public function get_priority() {return 60;} + public function get_priority(): int {return 60;} } diff --git a/ext/artists/main.php b/ext/artists/main.php index 5276881f..c2f0da73 100644 --- a/ext/artists/main.php +++ b/ext/artists/main.php @@ -16,12 +16,7 @@ class AuthorSetEvent extends Event { /** @var string */ public $author; - /** - * @param Image $image - * @param User $user - * @param string $author - */ - public function __construct(Image $image, User $user, /*string*/ $author) { + public function __construct(Image $image, User $user, string $author) { $this->image = $image; $this->user = $user; $this->author = $author; @@ -407,57 +402,32 @@ class Artists extends Extension { } } - /** - * @param int $imageID - * @return string - */ - private function get_artistName_by_imageID($imageID) { - assert(is_numeric($imageID)); - + private function get_artistName_by_imageID(int $imageID): string { global $database; $result = $database->get_row("SELECT author FROM images WHERE id = ?", array($imageID)); return stripslashes($result['author']); } - /** - * @param string $url - * @return bool - */ - private function url_exists_by_url($url) { + private function url_exists_by_url(string $url): bool { global $database; $result = $database->get_one("SELECT COUNT(1) FROM artist_urls WHERE url = ?", array($url)); return ($result != 0); } - /** - * @param string $member - * @return bool - */ - private function member_exists_by_name($member) { + private function member_exists_by_name(string $member): bool { global $database; $result = $database->get_one("SELECT COUNT(1) FROM artist_members WHERE name = ?", array($member)); return ($result != 0); } - /** - * @param string $alias - * @return bool - */ - private function alias_exists_by_name($alias) { + private function alias_exists_by_name(string $alias): bool { global $database; $result = $database->get_one("SELECT COUNT(1) FROM artist_alias WHERE alias = ?", array($alias)); return ($result != 0); } - /** - * @param int $artistID - * @param string $alias - * @return bool - */ - private function alias_exists($artistID, $alias) { - assert(is_numeric($artistID)); - + private function alias_exists(int $artistID, string $alias): bool { global $database; $result = $database->get_one( "SELECT COUNT(1) FROM artist_alias WHERE artist_id = ? AND alias = ?", @@ -466,131 +436,66 @@ class Artists extends Extension { return ($result != 0); } - /** - * @param string $url - * @return int - */ - private function get_artistID_by_url($url) { + private function get_artistID_by_url(string $url): int { global $database; return $database->get_one("SELECT artist_id FROM artist_urls WHERE url = ?", array($url)); } - /** - * @param string $member - * @return int - */ - private function get_artistID_by_memberName($member) { + private function get_artistID_by_memberName(string $member): int { global $database; return $database->get_one("SELECT artist_id FROM artist_members WHERE name = ?", array($member)); } - /** - * @param int $artistID - * @return string - */ - private function get_artistName_by_artistID($artistID) { - assert(is_numeric($artistID)); - + private function get_artistName_by_artistID(int $artistID): string { global $database; return $database->get_one("SELECT name FROM artists WHERE id = ?", array($artistID)); } - /** - * @param int $aliasID - * @return int - */ - private function get_artistID_by_aliasID($aliasID) { - assert(is_numeric($aliasID)); - + private function get_artistID_by_aliasID(int $aliasID): int { global $database; return $database->get_one("SELECT artist_id FROM artist_alias WHERE id = ?", array($aliasID)); } - /** - * @param int $memberID - * @return int - */ - private function get_artistID_by_memberID($memberID) { - assert(is_numeric($memberID)); - + private function get_artistID_by_memberID(int $memberID): int { global $database; return $database->get_one("SELECT artist_id FROM artist_members WHERE id = ?", array($memberID)); } - /** - * @param int $urlID - * @return int - */ - private function get_artistID_by_urlID($urlID) { - assert(is_numeric($urlID)); - + private function get_artistID_by_urlID(int $urlID): int { global $database; return $database->get_one("SELECT artist_id FROM artist_urls WHERE id = ?", array($urlID)); } - /** - * @param int $aliasID - */ - private function delete_alias($aliasID) { - assert(is_numeric($aliasID)); - + private function delete_alias(int $aliasID) { global $database; $database->execute("DELETE FROM artist_alias WHERE id = ?", array($aliasID)); } - /** - * @param int $urlID - */ - private function delete_url($urlID) { - assert(is_numeric($urlID)); - + private function delete_url(int $urlID) { global $database; $database->execute("DELETE FROM artist_urls WHERE id = ?", array($urlID)); } - /** - * @param int $memberID - */ - private function delete_member($memberID) { - assert(is_numeric($memberID)); - + private function delete_member(int $memberID) { global $database; $database->execute("DELETE FROM artist_members WHERE id = ?", array($memberID)); } - /** - * @param int $aliasID - * @return array - */ - private function get_alias_by_id($aliasID) { - assert(is_numeric($aliasID)); - + private function get_alias_by_id(int $aliasID): array { global $database; $result = $database->get_row("SELECT * FROM artist_alias WHERE id = ?", array($aliasID)); $result["alias"] = stripslashes($result["alias"]); return $result; } - /** - * @param int $urlID - * @return array - */ - private function get_url_by_id($urlID) { - assert(is_numeric($urlID)); - + private function get_url_by_id(int $urlID): array { global $database; $result = $database->get_row("SELECT * FROM artist_urls WHERE id = ?", array($urlID)); $result["url"] = stripslashes($result["url"]); return $result; } - /** - * @param int $memberID - * @return array - */ - private function get_member_by_id($memberID) { - assert(is_numeric($memberID)); - + private function get_member_by_id(int $memberID): array { global $database; $result = $database->get_row("SELECT * FROM artist_members WHERE id = ?", array($memberID)); $result["name"] = stripslashes($result["name"]); @@ -701,15 +606,7 @@ class Artists extends Extension { $this->save_existing_alias($inputs['aliasID'], $inputs['alias'], $user->id); } - /** - * @param int $aliasID - * @param string $alias - * @param int $userID - */ - private function save_existing_alias($aliasID, $alias, $userID) { - assert(is_numeric($userID)); - assert(is_numeric($aliasID)); - + private function save_existing_alias(int $aliasID, string $alias, int $userID) { global $database; $database->execute( "UPDATE artist_alias SET alias = ?, updated = now(), user_id = ? WHERE id = ? ", @@ -726,15 +623,7 @@ class Artists extends Extension { $this->save_existing_url($inputs['urlID'], $inputs['url'], $user->id); } - /** - * @param int $urlID - * @param string $url - * @param int $userID - */ - private function save_existing_url($urlID, $url, $userID) { - assert(is_numeric($userID)); - assert(is_numeric($urlID)); - + private function save_existing_url(int $urlID, string $url, int $userID) { global $database; $database->execute( "UPDATE artist_urls SET url = ?, updated = now(), user_id = ? WHERE id = ?", @@ -751,15 +640,7 @@ class Artists extends Extension { $this->save_existing_member($inputs['memberID'], $inputs['name'], $user->id); } - /** - * @param int $memberID - * @param string $memberName - * @param int $userID - */ - private function save_existing_member($memberID, $memberName, $userID) { - assert(is_numeric($memberID)); - assert(is_numeric($userID)); - + private function save_existing_member(int $memberID, string $memberName, int $userID) { global $database; $database->execute( "UPDATE artist_members SET name = ?, updated = now(), user_id = ? WHERE id = ?", @@ -826,12 +707,7 @@ class Artists extends Extension { return $artistID; } - /** - * @param string $name - * @param string $notes - * @return int - */ - private function save_new_artist($name, $notes) { + private function save_new_artist(string $name, string $notes): int { global $database, $user; $database->execute(" INSERT INTO artists (user_id, name, notes, created, updated) @@ -840,11 +716,7 @@ class Artists extends Extension { return $database->get_last_insert_id('artists_id_seq'); } - /** - * @param string $name - * @return bool - */ - private function artist_exists($name) { + private function artist_exists(string $name): bool { global $database; $result = $database->get_one( "SELECT COUNT(1) FROM artists WHERE name = ?", @@ -853,13 +725,7 @@ class Artists extends Extension { return ($result != 0); } - /** - * @param int $artistID - * @return array - */ - private function get_artist($artistID){ - assert(is_numeric($artistID)); - + private function get_artist(int $artistID): array { global $database; $result = $database->get_row( "SELECT * FROM artists WHERE id = ?", @@ -872,13 +738,7 @@ class Artists extends Extension { return $result; } - /** - * @param int $artistID - * @return array - */ - private function get_members($artistID) { - assert(is_numeric($artistID)); - + private function get_members(int $artistID): array { global $database; $result = $database->get_all( "SELECT * FROM artist_members WHERE artist_id = ?", @@ -893,13 +753,7 @@ class Artists extends Extension { return $result; } - /** - * @param int $artistID - * @return array - */ - private function get_urls($artistID) { - assert(is_numeric($artistID)); - + private function get_urls(int $artistID): array { global $database; $result = $database->get_all( "SELECT id, url FROM artist_urls WHERE artist_id = ?", @@ -914,11 +768,7 @@ class Artists extends Extension { return $result; } - /** - * @param string $name - * @return int - */ - private function get_artist_id($name) { + private function get_artist_id(string $name): int { global $database; return (int)$database->get_one( "SELECT id FROM artists WHERE name = ?", @@ -926,11 +776,7 @@ class Artists extends Extension { ); } - /** - * @param string $alias - * @return int - */ - private function get_artistID_by_aliasName($alias) { + private function get_artistID_by_aliasName(string $alias): int { global $database; return (int)$database->get_one( @@ -939,13 +785,7 @@ class Artists extends Extension { ); } - - /** - * @param int $artistID - */ - private function delete_artist($artistID) { - assert(is_numeric($artistID)); - + private function delete_artist(int $artistID) { global $database; $database->execute( "DELETE FROM artists WHERE id = ? ", @@ -1055,17 +895,9 @@ class Artists extends Extension { $this->save_new_url($artistID, $url, $user->id); } - /** - * @param int $artistID - * @param string $url - * @param int $userID - */ - private function save_new_url($artistID, $url, $userID) { + private function save_new_url(int $artistID, string $url, int $userID) { global $database; - assert(is_numeric($artistID)); - assert(is_numeric($userID)); - $database->execute( "INSERT INTO artist_urls (artist_id, created, updated, url, user_id) VALUES (?, now(), now(), ?, ?)", array($artistID, $url, $userID) @@ -1086,17 +918,9 @@ class Artists extends Extension { $this->save_new_alias($artistID, $alias, $user->id); } - /** - * @param int $artistID - * @param string $alias - * @param int $userID - */ - private function save_new_alias($artistID, $alias, $userID) { + private function save_new_alias(int $artistID, string $alias, int $userID) { global $database; - assert(is_numeric($artistID)); - assert(is_numeric($userID)); - $database->execute( "INSERT INTO artist_alias (artist_id, created, updated, alias, user_id) VALUES (?, now(), now(), ?, ?)", array($artistID, $alias, $userID) @@ -1117,33 +941,18 @@ class Artists extends Extension { $this->save_new_member($artistID, $member, $user->id); } - /** - * @param int $artistID - * @param string $member - * @param int $userID - */ - private function save_new_member($artistID, $member, $userID) { + private function save_new_member(int $artistID, string $member, int $userID) { global $database; - assert(is_numeric($artistID)); - assert(is_numeric($userID)); - $database->execute( "INSERT INTO artist_members (artist_id, name, created, updated, user_id) VALUES (?, ?, now(), now(), ?)", array($artistID, $member, $userID) ); } - /** - * @param int $artistID - * @param string $member - * @return bool - */ - private function member_exists($artistID, $member) { + private function member_exists(int $artistID, string $member): bool { global $database; - assert(is_numeric($artistID)); - $result = $database->get_one( "SELECT COUNT(1) FROM artist_members WHERE artist_id = ? AND name = ?", array($artistID, $member) @@ -1151,16 +960,9 @@ class Artists extends Extension { return ($result != 0); } - /** - * @param int $artistID - * @param string $url - * @return bool - */ - private function url_exists($artistID, $url) { + private function url_exists(int $artistID, string $url): bool { global $database; - assert(is_numeric($artistID)); - $result = $database->get_one( "SELECT COUNT(1) FROM artist_urls WHERE artist_id = ? AND url = ?", array($artistID, $url) @@ -1170,15 +972,10 @@ class Artists extends Extension { /** * HERE WE GET THE INFO OF THE ALIAS - * - * @param int $artistID - * @return array */ - private function get_alias($artistID) { + private function get_alias(int $artistID): array { global $database; - assert(is_numeric($artistID)); - $result = $database->get_all(" SELECT id AS alias_id, alias AS alias_name FROM artist_alias diff --git a/ext/artists/theme.php b/ext/artists/theme.php index cc30e6bd..fc32e19f 100644 --- a/ext/artists/theme.php +++ b/ext/artists/theme.php @@ -5,7 +5,7 @@ class ArtistsTheme extends Themelet { * @param string $author * @return string */ - public function get_author_editor_html(/*string*/ $author) { + public function get_author_editor_html(string $author) { $h_author = html_escape($author); return " @@ -23,7 +23,7 @@ class ArtistsTheme extends Themelet { * @param null|int $artistID * @param bool $is_admin */ - public function sidebar_options(/*string*/ $mode, $artistID=NULL, $is_admin=FALSE) { + public function sidebar_options(string $mode, $artistID=NULL, $is_admin=FALSE) { global $page, $user; $html = ""; diff --git a/ext/autocomplete/main.php b/ext/autocomplete/main.php index 24e1e87f..af6ad166 100644 --- a/ext/autocomplete/main.php +++ b/ext/autocomplete/main.php @@ -6,7 +6,7 @@ */ class AutoComplete extends Extension { - public function get_priority() {return 30;} // before Home + public function get_priority(): int {return 30;} // before Home public function onPageRequest(PageRequestEvent $event) { global $page, $database; diff --git a/ext/ban_words/main.php b/ext/ban_words/main.php index 9d9493d4..99d168aa 100644 --- a/ext/ban_words/main.php +++ b/ext/ban_words/main.php @@ -111,10 +111,7 @@ xanax } } - /** - * @return string[] - */ - private function get_words() { + private function get_words(): array { global $config; $words = array(); @@ -131,6 +128,6 @@ xanax return $words; } - public function get_priority() {return 30;} + public function get_priority(): int {return 30;} } diff --git a/ext/bbcode/main.php b/ext/bbcode/main.php index ee20fa7c..e1c284d1 100644 --- a/ext/bbcode/main.php +++ b/ext/bbcode/main.php @@ -26,11 +26,7 @@ */ class BBCode extends FormatterExtension { - /** - * @param string $text - * @return string - */ - public function format(/*string*/ $text) { + public function format(string $text): string { $text = $this->extract_code($text); foreach(array( "b", "i", "u", "s", "sup", "sub", "h1", "h2", "h3", "h4", @@ -67,11 +63,7 @@ class BBCode extends FormatterExtension { return $text; } - /** - * @param string $text - * @return string - */ - public function strip(/*string*/ $text) { + public function strip(string $text): string { foreach(array( "b", "i", "u", "s", "sup", "sub", "h1", "h2", "h3", "h4", "code", "url", "email", "li", @@ -91,22 +83,14 @@ class BBCode extends FormatterExtension { return $text; } - /** - * @param string $text - * @return string - */ - private function filter_spoiler(/*string*/ $text) { + private function filter_spoiler(string $text): string { return str_replace( array("[spoiler]","[/spoiler]"), array("",""), $text); } - /** - * @param string $text - * @return string - */ - private function strip_spoiler(/*string*/ $text) { + private function strip_spoiler(string $text): string { $l1 = strlen("[spoiler]"); $l2 = strlen("[/spoiler]"); while(true) { @@ -127,11 +111,7 @@ class BBCode extends FormatterExtension { return $text; } - /** - * @param string $text - * @return string - */ - private function extract_code(/*string*/ $text) { + private function extract_code(string $text): string { # at the end of this function, the only code! blocks should be # the ones we've added -- others may contain malicious content, # which would only appear after decoding @@ -158,11 +138,7 @@ class BBCode extends FormatterExtension { return $text; } - /** - * @param string $text - * @return string - */ - private function insert_code(/*string*/ $text) { + private function insert_code(string $text): string { $l1 = strlen("[code!]"); $l2 = strlen("[/code!]"); while(true) { @@ -181,4 +157,3 @@ class BBCode extends FormatterExtension { return $text; } } - diff --git a/ext/bulk_add/main.php b/ext/bulk_add/main.php index fa532526..b86f5ef8 100644 --- a/ext/bulk_add/main.php +++ b/ext/bulk_add/main.php @@ -18,7 +18,7 @@ class BulkAddEvent extends Event { public $dir, $results; - public function __construct($dir) { + public function __construct(string $dir) { $this->dir = $dir; $this->results = array(); } diff --git a/ext/bulk_add_csv/main.php b/ext/bulk_add_csv/main.php index a5b999e7..b045124a 100644 --- a/ext/bulk_add_csv/main.php +++ b/ext/bulk_add_csv/main.php @@ -90,7 +90,7 @@ class BulkAddCSV extends Extension { } } - private function add_csv(/*string*/ $csvfile) { + private function add_csv(string $csvfile) { if(!file_exists($csvfile)) { $this->theme->add_status("Error", "$csvfile not found"); return; diff --git a/ext/comment/main.php b/ext/comment/main.php index dfb769e0..fc3ceb48 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -19,13 +19,7 @@ class CommentPostingEvent extends Event { /** @var string */ public $comment; - /** - * @param int $image_id - * @param \User $user - * @param string $comment - */ - public function __construct($image_id, $user, $comment) { - assert('is_numeric($image_id)'); + public function __construct(int $image_id, User $user, string $comment) { $this->image_id = $image_id; $this->user = $user; $this->comment = $comment; @@ -41,11 +35,7 @@ class CommentDeletionEvent extends Event { /** @var int */ public $comment_id; - /** - * @param int $comment_id - */ - public function __construct($comment_id) { - assert('is_numeric($comment_id)'); + public function __construct(int $comment_id) { $this->comment_id = $comment_id; } } @@ -339,7 +329,7 @@ class CommentList extends Extension { /** * @param int $current_page */ - private function build_page(/*int*/ $current_page) { + private function build_page(int $current_page) { global $database, $user; $where = SPEED_HAX ? "WHERE posted > now() - interval '24 hours'" : ""; @@ -429,7 +419,7 @@ class CommentList extends Extension { * @param int $offset * @return Comment[] */ - private function get_user_comments(/*int*/ $user_id, /*int*/ $count, /*int*/ $offset=0) { + private function get_user_comments(int $user_id, int $count, int $offset=0) { return $this->get_generic_comments(" SELECT users.id as user_id, users.name as user_name, users.email as user_email, users.class as user_class, @@ -448,7 +438,7 @@ class CommentList extends Extension { * @param int $image_id * @return Comment[] */ - private function get_comments(/*int*/ $image_id) { + private function get_comments(int $image_id) { return $this->get_generic_comments(" SELECT users.id as user_id, users.name as user_name, users.email as user_email, users.class as user_class, @@ -513,7 +503,7 @@ class CommentList extends Extension { * @param string $text * @return bool */ - private function is_spam_akismet(/*string*/ $text) { + private function is_spam_akismet(string $text) { global $config, $user; if(strlen($config->get_string('comment_wordpress_key')) > 0) { $comment = array( @@ -556,7 +546,7 @@ class CommentList extends Extension { * @param int $comment * @return null */ - private function is_dupe(/*int*/ $image_id, /*string*/ $comment) { + private function is_dupe(int $image_id, string $comment) { global $database; return $database->get_row(" SELECT * @@ -572,7 +562,7 @@ class CommentList extends Extension { * @param string $comment * @throws CommentPostingException */ - private function add_comment_wrapper(/*int*/ $image_id, User $user, /*string*/ $comment) { + private function add_comment_wrapper(int $image_id, User $user, string $comment) { global $database, $page; if(!$user->can("bypass_comment_checks")) { @@ -601,7 +591,7 @@ class CommentList extends Extension { * @param string $comment * @throws CommentPostingException */ - private function comment_checks(/*int*/ $image_id, User $user, /*string*/ $comment) { + private function comment_checks(int $image_id, User $user, string $comment) { global $config, $page; // basic sanity checks diff --git a/ext/comment/theme.php b/ext/comment/theme.php index f017bdb3..2209b9fb 100644 --- a/ext/comment/theme.php +++ b/ext/comment/theme.php @@ -303,7 +303,7 @@ class CommentListTheme extends Themelet { * @param int $image_id * @return string */ - protected function build_postbox(/*int*/ $image_id) { + protected function build_postbox(int $image_id) { global $config; $i_image_id = int_escape($image_id); diff --git a/ext/downtime/main.php b/ext/downtime/main.php index 3eb44164..20fa4918 100644 --- a/ext/downtime/main.php +++ b/ext/downtime/main.php @@ -13,7 +13,7 @@ */ class Downtime extends Extension { - public function get_priority() {return 10;} + public function get_priority(): int {return 10;} public function onSetupBuilding(SetupBuildingEvent $event) { $sb = new SetupBlock("Downtime"); diff --git a/ext/downtime/theme.php b/ext/downtime/theme.php index 965b10b2..2444dbd6 100644 --- a/ext/downtime/theme.php +++ b/ext/downtime/theme.php @@ -16,7 +16,7 @@ class DowntimeTheme extends Themelet { * * @param string $message */ - public function display_message(/*string*/ $message) { + public function display_message(string $message) { global $config, $user, $page; $theme_name = $config->get_string('theme'); $data_href = get_base_href(); diff --git a/ext/emoticons/main.php b/ext/emoticons/main.php index e6245daf..0738c817 100644 --- a/ext/emoticons/main.php +++ b/ext/emoticons/main.php @@ -17,21 +17,13 @@ * Class Emoticons */ class Emoticons extends FormatterExtension { - /** - * @param string $text - * @return string - */ - public function format(/*string*/ $text) { + public function format(string $text): string { $data_href = get_base_href(); $text = preg_replace("/:([a-z]*?):/s", "", $text); return $text; } - /** - * @param string $text - * @return string - */ - public function strip(/*string*/ $text) { + public function strip(string $text): string { return $text; } } diff --git a/ext/emoticons/theme.php b/ext/emoticons/theme.php index 07f033dd..659d0621 100644 --- a/ext/emoticons/theme.php +++ b/ext/emoticons/theme.php @@ -3,7 +3,7 @@ class EmoticonListTheme extends Themelet { /** * @param array $list */ - public function display_emotes(/*array*/ $list) { + public function display_emotes(array $list) { global $page; $data_href = get_base_href(); $html = "Emoticon list"; diff --git a/ext/ext_manager/main.php b/ext/ext_manager/main.php index 3a19809d..903d6e0d 100644 --- a/ext/ext_manager/main.php +++ b/ext/ext_manager/main.php @@ -87,7 +87,7 @@ class ExtensionInfo { * @param string $fname * @return bool|null */ - private function is_enabled(/*string*/ $fname) { + private function is_enabled(string $fname) { $core = explode(",", CORE_EXTS); $extra = explode(",", EXTRA_EXTS); @@ -160,7 +160,7 @@ class ExtManager extends Extension { * @param bool $all * @return ExtensionInfo[] */ - private function get_extensions(/*bool*/ $all) { + private function get_extensions(bool $all) { $extensions = array(); if($all) { $exts = zglob("ext/*/main.php"); diff --git a/ext/ext_manager/theme.php b/ext/ext_manager/theme.php index 53732529..1c7f0245 100644 --- a/ext/ext_manager/theme.php +++ b/ext/ext_manager/theme.php @@ -6,7 +6,7 @@ class ExtManagerTheme extends Themelet { * @param ExtensionInfo[] $extensions * @param bool $editable */ - public function display_table(Page $page, /*array*/ $extensions, /*bool*/ $editable) { + public function display_table(Page $page, array $extensions, bool $editable) { $h_en = $editable ? "" : ""; $html = " ".make_form(make_link("ext_manager/set"))." diff --git a/ext/favorites/main.php b/ext/favorites/main.php index 8e6af251..41917599 100644 --- a/ext/favorites/main.php +++ b/ext/favorites/main.php @@ -21,12 +21,7 @@ class FavoriteSetEvent extends Event { /** @var bool */ public $do_set; - /** - * @param int $image_id - * @param User $user - * @param bool $do_set - */ - public function __construct(/*int*/ $image_id, User $user, /*boolean*/ $do_set) { + public function __construct(int $image_id, User $user, bool $do_set) { assert(is_int($image_id)); assert(is_bool($do_set)); @@ -181,12 +176,7 @@ class Favorites extends Extension { } } - /** - * @param int $image_id - * @param int $user_id - * @param bool $do_set - */ - private function add_vote(/*int*/ $image_id, /*int*/ $user_id, /*bool*/ $do_set) { + private function add_vote(int $image_id, int $user_id, bool $do_set) { global $database; if ($do_set) { $database->Execute( @@ -206,7 +196,7 @@ class Favorites extends Extension { * @param Image $image * @return string[] */ - private function list_persons_who_have_favorited(Image $image) { + private function list_persons_who_have_favorited(Image $image): array { global $database; return $database->get_col( diff --git a/ext/featured/main.php b/ext/featured/main.php index 85e2459e..59a3745a 100644 --- a/ext/featured/main.php +++ b/ext/featured/main.php @@ -50,7 +50,7 @@ class Featured extends Extension { if($event->get_arg(0) == "view") { $image = Image::by_id($config->get_int("featured_id")); if(!is_null($image)) { - send_event(new DisplayingImageEvent($image, $page)); + send_event(new DisplayingImageEvent($image)); } } } diff --git a/ext/featured/theme.php b/ext/featured/theme.php index 9fc6a74f..bfb53d7a 100644 --- a/ext/featured/theme.php +++ b/ext/featured/theme.php @@ -15,7 +15,7 @@ class FeaturedTheme extends Themelet { * @param int $image_id * @return string */ - public function get_buttons_html(/*int*/ $image_id) { + public function get_buttons_html(int $image_id) { global $user; return " ".make_form(make_link("featured_image/set"))." diff --git a/ext/forum/main.php b/ext/forum/main.php index 7432225c..ab235b9a 100644 --- a/ext/forum/main.php +++ b/ext/forum/main.php @@ -179,10 +179,7 @@ class Forum extends Extension { } } - /** - * @param int $threadID - */ - private function get_total_pages_for_thread($threadID) + private function get_total_pages_for_thread(int $threadID) { global $database, $config; $result = $database->get_row("SELECT COUNT(1) AS count FROM forum_posts WHERE thread_id = ?", array($threadID)); @@ -243,10 +240,7 @@ class Forum extends Extension { return array($errors); } - /** - * @param int $threadID - */ - private function sanity_check_viewed_thread($threadID) + private function sanity_check_viewed_thread(int $threadID) { $errors = null; if (!$this->threadExists($threadID)) @@ -256,10 +250,7 @@ class Forum extends Extension { return array($errors); } - /** - * @param int $threadID - */ - private function get_thread_title($threadID) + private function get_thread_title(int $threadID) { global $database; $result = $database->get_row("SELECT t.title FROM forum_threads AS t WHERE t.id = ? ", array($threadID)); @@ -352,10 +343,7 @@ class Forum extends Extension { return $threadID; } - /** - * @param int $threadID - */ - private function save_new_post($threadID, User $user) + private function save_new_post(int $threadID, User $user) { global $config; $userID = $user->id; @@ -378,11 +366,7 @@ class Forum extends Extension { $database->execute("UPDATE forum_threads SET uptodate=now() WHERE id=?", array ($threadID)); } - /** - * @param int $threadID - * @param int $pageNumber - */ - private function retrieve_posts($threadID, $pageNumber) + private function retrieve_posts(int $threadID, int $pageNumber) { global $database, $config; $postsPerPage = $config->get_int('forumPostsPerPage', 15); @@ -398,29 +382,20 @@ class Forum extends Extension { , array("thread_id"=>$threadID, "offset"=>($pageNumber - 1) * $postsPerPage, "limit"=>$postsPerPage)); } - /** - * @param int $threadID - */ - private function delete_thread($threadID) + private function delete_thread(int $threadID) { global $database; $database->execute("DELETE FROM forum_threads WHERE id = ?", array($threadID)); $database->execute("DELETE FROM forum_posts WHERE thread_id = ?", array($threadID)); } - /** - * @param int $postID - */ - private function delete_post($postID) + private function delete_post(int $postID) { global $database; $database->execute("DELETE FROM forum_posts WHERE id = ?", array($postID)); } - /** - * @param int $threadID - */ - private function threadExists($threadID) + private function threadExists(int $threadID) { global $database; $result=$database->get_one("SELECT EXISTS (SELECT * FROM forum_threads WHERE id= ?)", array($threadID)); diff --git a/ext/handle_404/main.php b/ext/handle_404/main.php index a17e80f7..4c3eafdf 100644 --- a/ext/handle_404/main.php +++ b/ext/handle_404/main.php @@ -48,6 +48,6 @@ class Handle404 extends Extension { return $n; } - public function get_priority() {return 99;} + public function get_priority(): int {return 99;} } diff --git a/ext/handle_archive/main.php b/ext/handle_archive/main.php index ad43c4ac..346f062e 100644 --- a/ext/handle_archive/main.php +++ b/ext/handle_archive/main.php @@ -45,10 +45,6 @@ class ArchiveFileHandler extends Extension { } } - /** - * @param string $ext - * @return bool - */ private function supported_ext($ext) { $exts = array("zip"); return in_array(strtolower($ext), $exts); diff --git a/ext/handle_flash/main.php b/ext/handle_flash/main.php index 719648d4..2e076739 100644 --- a/ext/handle_flash/main.php +++ b/ext/handle_flash/main.php @@ -7,30 +7,17 @@ */ class FlashFileHandler extends DataHandlerExtension { - /** - * @param string $hash - * @return bool - */ - protected function create_thumb($hash) { + protected function create_thumb(string $hash): bool { copy("ext/handle_flash/thumb.jpg", warehouse_path("thumbs", $hash)); return true; } - /** - * @param string $ext - * @return bool - */ - protected function supported_ext($ext) { + protected function supported_ext(string $ext): bool { $exts = array("swf"); return in_array(strtolower($ext), $exts); } - /** - * @param string $filename - * @param array $metadata - * @return Image|null - */ - protected function create_image_from_data(/*string*/ $filename, /*array*/ $metadata) { + protected function create_image_from_data(string $filename, array $metadata) { $image = new Image(); $image->filesize = $metadata['size']; @@ -49,14 +36,10 @@ class FlashFileHandler extends DataHandlerExtension { return $image; } - /** - * @param string $file - * @return bool - */ - protected function check_contents(/*string*/ $file) { - if (!file_exists($file)) return false; + protected function check_contents(string $tmpname): bool { + if (!file_exists($tmpname)) return false; - $fp = fopen($file, "r"); + $fp = fopen($tmpname, "r"); $head = fread($fp, 3); fclose($fp); if (!in_array($head, array("CWS", "FWS"))) return false; diff --git a/ext/handle_ico/main.php b/ext/handle_ico/main.php index 31d5e337..43d7e144 100644 --- a/ext/handle_ico/main.php +++ b/ext/handle_ico/main.php @@ -35,21 +35,12 @@ class IcoFileHandler extends Extension { } } - /** - * @param string $ext - * @return bool - */ - private function supported_ext($ext) { + private function supported_ext(string $ext): bool { $exts = array("ico", "ani", "cur"); return in_array(strtolower($ext), $exts); } - /** - * @param string $filename - * @param mixed[] $metadata - * @return Image - */ - private function create_image_from_data($filename, $metadata) { + private function create_image_from_data(string $filename, array $metadata) { $image = new Image(); $fp = fopen($filename, "r"); @@ -73,11 +64,7 @@ class IcoFileHandler extends Extension { return $image; } - /** - * @param string $file - * @return bool - */ - private function check_contents($file) { + private function check_contents(string $file): bool { if(!file_exists($file)) return false; $fp = fopen($file, "r"); $header = unpack("Snull/Stype/Scount", fread($fp, 6)); @@ -85,11 +72,7 @@ class IcoFileHandler extends Extension { return ($header['null'] == 0 && ($header['type'] == 0 || $header['type'] == 1)); } - /** - * @param string $hash - * @return bool - */ - private function create_thumb($hash) { + private function create_thumb(string $hash): bool { global $config; $inname = warehouse_path("images", $hash); diff --git a/ext/handle_mp3/main.php b/ext/handle_mp3/main.php index 4f0eae9e..792f047c 100644 --- a/ext/handle_mp3/main.php +++ b/ext/handle_mp3/main.php @@ -6,30 +6,17 @@ */ class MP3FileHandler extends DataHandlerExtension { - /** - * @param string $hash - * @return bool - */ - protected function create_thumb($hash) { + protected function create_thumb(string $hash): bool { copy("ext/handle_mp3/thumb.jpg", warehouse_path("thumbs", $hash)); return true; } - /** - * @param string $ext - * @return bool - */ - protected function supported_ext($ext) { + protected function supported_ext(string $ext): bool { $exts = array("mp3"); return in_array(strtolower($ext), $exts); } - /** - * @param string $filename - * @param mixed[] $metadata - * @return Image|null - */ - protected function create_image_from_data($filename, $metadata) { + protected function create_image_from_data(string $filename, array $metadata) { $image = new Image(); //NOTE: No need to set width/height as we don't use it. @@ -49,15 +36,11 @@ class MP3FileHandler extends DataHandlerExtension { return $image; } - /** - * @param $file - * @return bool - */ - protected function check_contents($file) { + protected function check_contents(string $tmpname): bool { $success = FALSE; - if (file_exists($file)) { - $mimeType = mime_content_type($file); + if (file_exists($tmpname)) { + $mimeType = mime_content_type($tmpname); $success = ($mimeType == 'audio/mpeg'); } @@ -65,4 +48,3 @@ class MP3FileHandler extends DataHandlerExtension { return $success; } } - diff --git a/ext/handle_pixel/main.php b/ext/handle_pixel/main.php index 149677eb..8ff1264d 100644 --- a/ext/handle_pixel/main.php +++ b/ext/handle_pixel/main.php @@ -7,22 +7,13 @@ */ class PixelFileHandler extends DataHandlerExtension { - /** - * @param string $ext - * @return bool - */ - protected function supported_ext($ext) { + protected function supported_ext(string $ext): bool { $exts = array("jpg", "jpeg", "gif", "png"); $ext = (($pos = strpos($ext,'?')) !== false) ? substr($ext,0,$pos) : $ext; return in_array(strtolower($ext), $exts); } - /** - * @param string $filename - * @param array $metadata - * @return Image|null - */ - protected function create_image_from_data(/*string*/ $filename, /*array*/ $metadata) { + protected function create_image_from_data(string $filename, array $metadata) { $image = new Image(); $info = getimagesize($filename); @@ -41,24 +32,16 @@ class PixelFileHandler extends DataHandlerExtension { return $image; } - /** - * @param string $file - * @return bool - */ - protected function check_contents(/*string*/ $file) { + protected function check_contents(string $tmpname): bool { $valid = Array(IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_JPEG); - if(!file_exists($file)) return false; - $info = getimagesize($file); + if(!file_exists($tmpname)) return false; + $info = getimagesize($tmpname); if(is_null($info)) return false; if(in_array($info[2], $valid)) return true; return false; } - /** - * @param string $hash - * @return bool - */ - protected function create_thumb(/*string*/ $hash) { + protected function create_thumb(string $hash): bool { $outname = warehouse_path("thumbs", $hash); if(file_exists($outname)) { return true; @@ -66,11 +49,7 @@ class PixelFileHandler extends DataHandlerExtension { return $this->create_thumb_force($hash); } - /** - * @param string $hash - * @return bool - */ - protected function create_thumb_force(/*string*/ $hash) { + protected function create_thumb_force(string $hash): bool { global $config; $inname = warehouse_path("images", $hash); @@ -114,13 +93,7 @@ class PixelFileHandler extends DataHandlerExtension { } // IM thumber {{{ - - /** - * @param string $inname - * @param string $outname - * @return bool - */ - private function make_thumb_convert(/*string*/ $inname, /*string*/ $outname) { + private function make_thumb_convert(string $inname, string $outname): bool { global $config; $w = $config->get_int("thumb_width"); @@ -153,12 +126,7 @@ class PixelFileHandler extends DataHandlerExtension { } // }}} // epeg thumber {{{ - /** - * @param string $inname - * @param string $outname - * @return bool - */ - private function make_thumb_epeg(/*string*/ $inname, /*string*/ $outname) { + private function make_thumb_epeg(string $inname, string $outname): bool { global $config; $w = $config->get_int("thumb_width"); exec("epeg $inname -c 'Created by EPEG' --max $w $outname"); @@ -166,12 +134,7 @@ class PixelFileHandler extends DataHandlerExtension { } // }}} // GD thumber {{{ - /** - * @param string $inname - * @param string $outname - * @return bool - */ - private function make_thumb_gd(/*string*/ $inname, /*string*/ $outname) { + private function make_thumb_gd(string $inname, string $outname): bool { global $config; $thumb = $this->get_thumb($inname); $ok = imagejpeg($thumb, $outname, $config->get_int('thumb_quality')); @@ -179,11 +142,7 @@ class PixelFileHandler extends DataHandlerExtension { return $ok; } - /** - * @param string $tmpname - * @return resource - */ - private function get_thumb(/*string*/ $tmpname) { + private function get_thumb(string $tmpname) { global $config; $info = getimagesize($tmpname); @@ -220,4 +179,3 @@ class PixelFileHandler extends DataHandlerExtension { } // }}} } - diff --git a/ext/handle_video/main.php b/ext/handle_video/main.php index a31ac781..bb191896 100644 --- a/ext/handle_video/main.php +++ b/ext/handle_video/main.php @@ -82,7 +82,7 @@ class VideoFileHandler extends DataHandlerExtension { * @param string $hash * @return bool Returns true on successful thumbnail creation. */ - protected function create_thumb($hash) { + protected function create_thumb(string $hash): bool { global $config; $ok = false; @@ -132,7 +132,7 @@ class VideoFileHandler extends DataHandlerExtension { * @param string $ext * @return bool */ - protected function supported_ext($ext) { + protected function supported_ext(string $ext): bool { $exts = array("flv", "mp4", "m4v", "ogv", "webm"); return in_array(strtolower($ext), $exts); } @@ -142,7 +142,7 @@ class VideoFileHandler extends DataHandlerExtension { * @param mixed[] $metadata * @return Image */ - protected function create_image_from_data($filename, $metadata) { + protected function create_image_from_data(string $filename, array $metadata) { $image = new Image(); //NOTE: No need to set width/height as we don't use it. @@ -177,13 +177,13 @@ class VideoFileHandler extends DataHandlerExtension { } /** - * @param string $file + * @param string $tmpname * @return bool */ - protected function check_contents($file) { + protected function check_contents(string $tmpname): bool { $success = FALSE; - if (file_exists($file)) { - $mimeType = mime_content_type($file); + if (file_exists($tmpname)) { + $mimeType = mime_content_type($tmpname); $success = in_array($mimeType, [ 'video/webm', diff --git a/ext/home/main.php b/ext/home/main.php index 566c1d6e..ecffe8a9 100644 --- a/ext/home/main.php +++ b/ext/home/main.php @@ -49,7 +49,7 @@ class Home extends Extension { global $config; $base_href = get_base_href(); $sitename = $config->get_string('title'); - $contact_link = contact_link(); + $contact_link = contact_link() || ""; $counter_dir = $config->get_string('home_counter', 'default'); $total = Image::count_images(); @@ -74,7 +74,7 @@ class Home extends Extension { $main_links .= ' [url=site://ext_doc]Documentation[/url]'; } $main_links = format_text($main_links); - $main_text = $config->get_string('home_text'); + $main_text = $config->get_string('home_text', ''); return $this->theme->build_body($sitename, $main_links, $main_text, $contact_link, $num_comma, $counter_text); } diff --git a/ext/home/theme.php b/ext/home/theme.php index 07ef10a2..ff67af22 100644 --- a/ext/home/theme.php +++ b/ext/home/theme.php @@ -22,7 +22,7 @@ EOD ); } - public function build_body(/*string*/ $sitename, /*string*/ $main_links, /*string*/ $main_text, /*string*/ $contact_link, $num_comma, /*string*/ $counter_text) { + public function build_body(string $sitename, string $main_links, string $main_text, string $contact_link, $num_comma, string $counter_text) { $main_links_html = empty($main_links) ? "" : ""; $message_html = empty($main_text) ? "" : "
$main_text
"; $counter_html = empty($counter_text) ? "" : "
$counter_text
"; diff --git a/ext/image/main.php b/ext/image/main.php index fde7b727..3d88fce7 100644 --- a/ext/image/main.php +++ b/ext/image/main.php @@ -34,10 +34,7 @@ class ImageAdditionEvent extends Event { class ImageAdditionException extends SCoreException { public $error; - /** - * @param string $error - */ - public function __construct($error) { + public function __construct(string $error) { $this->error = $error; } } @@ -81,7 +78,7 @@ class ImageReplaceEvent extends Event { * @param int $id The ID of the image to replace. * @param Image $image The image object of the new image to use. */ - public function __construct(/*int*/ $id, Image $image) { + public function __construct(int $id, Image $image) { $this->id = $id; $this->image = $image; } @@ -91,10 +88,7 @@ class ImageReplaceException extends SCoreException { /** @var string */ public $error; - /** - * @param string $error - */ - public function __construct(/*string*/ $error) { + public function __construct(string $error) { $this->error = $error; } } @@ -117,7 +111,7 @@ class ThumbnailGenerationEvent extends Event { * @param string $type The type of the image * @param bool $force Regenerate the thumbnail even if one already exists */ - public function __construct($hash, $type, $force=false) { + public function __construct(string $hash, string $type, bool $force=false) { $this->hash = $hash; $this->type = $type; $this->force = $force; @@ -143,17 +137,13 @@ class ParseLinkTemplateEvent extends Event { * @param string $link The formatted link * @param Image $image The image who's link is being parsed */ - public function __construct($link, Image $image) { + public function __construct(string $link, Image $image) { $this->link = $link; $this->original = $link; $this->image = $image; } - /** - * @param string $needle - * @param string $replace - */ - public function replace($needle, $replace) { + public function replace(string $needle, string $replace) { $this->link = str_replace($needle, $replace, $this->link); } } @@ -309,11 +299,6 @@ class ImageIO extends Extension { // add image {{{ - /** - * @param Image $image - * @return null - * @throws ImageAdditionException - */ private function add_image(Image $image) { global $user, $database, $config; @@ -383,11 +368,7 @@ class ImageIO extends Extension { // }}} end add // fetch image {{{ - /** - * @param int $image_id - * @param string $type - */ - private function send_file($image_id, $type) { + private function send_file(int $image_id, string $type) { global $config; $image = Image::by_id($image_id); @@ -438,12 +419,7 @@ class ImageIO extends Extension { // }}} end fetch // replace image {{{ - /** - * @param int $id - * @param Image $image - * @throws ImageReplaceException - */ - private function replace_image($id, $image) { + private function replace_image(int $id, Image $image) { global $database; /* Check to make sure the image exists. */ diff --git a/ext/image/theme.php b/ext/image/theme.php index 96f23501..54e88d6a 100644 --- a/ext/image/theme.php +++ b/ext/image/theme.php @@ -7,7 +7,7 @@ class ImageIOTheme extends Themelet { * @param $image_id integer The image to delete * @return string */ - public function get_deleter_html(/*int*/ $image_id) { + public function get_deleter_html(int $image_id) { $html = " ".make_form(make_link("image/delete"))." @@ -24,7 +24,7 @@ class ImageIOTheme extends Themelet { * @param $image_id integer The image to replace * @return string */ - public function get_replace_html(/*int*/ $image_id) { + public function get_replace_html(int $image_id) { $html = make_form(make_link("image/replace"))." diff --git a/ext/image_hash_ban/main.php b/ext/image_hash_ban/main.php index 431d2cf7..644dcf23 100644 --- a/ext/image_hash_ban/main.php +++ b/ext/image_hash_ban/main.php @@ -13,10 +13,7 @@ class RemoveImageHashBanEvent extends Event { public $hash; - /** - * @param string $hash - */ - public function __construct($hash) { + public function __construct(string $hash) { $this->hash = $hash; } } @@ -26,11 +23,7 @@ class AddImageHashBanEvent extends Event { public $hash; public $reason; - /** - * @param string $hash - * @param string $reason - */ - public function __construct($hash, $reason) { + public function __construct(string $hash, string $reason) { $this->hash = $hash; $this->reason = $reason; } @@ -168,6 +161,6 @@ class ImageBan extends Extension { } // in before resolution limit plugin - public function get_priority() {return 30;} + public function get_priority(): int {return 30;} } diff --git a/ext/index/main.php b/ext/index/main.php index 29d225ea..55b81e79 100644 --- a/ext/index/main.php +++ b/ext/index/main.php @@ -166,33 +166,20 @@ class SearchTermParseEvent extends Event { /** @var \Querylet[] */ public $querylets = array(); - /** - * @param string|null $term - * @param string[] $context - */ - public function __construct($term, array $context) { + public function __construct(string $term=null, array $context=array()) { $this->term = $term; $this->context = $context; } - /** - * @return bool - */ - public function is_querylet_set() { + public function is_querylet_set(): bool { return (count($this->querylets) > 0); } - /** - * @return \Querylet[] - */ - public function get_querylets() { + public function get_querylets(): array { return $this->querylets; } - /** - * @param \Querylet $q - */ - public function add_querylet($q) { + public function add_querylet(Querylet $q) { $this->querylets[] = $q; } } @@ -214,11 +201,7 @@ class PostListBuildingEvent extends Event { $this->search_terms = $search; } - /** - * @param string $html - * @param int $position - */ - public function add_control(/*string*/ $html, /*int*/ $position=50) { + public function add_control(string $html, int $position=50) { while(isset($this->parts[$position])) $position++; $this->parts[$position] = $html; } diff --git a/ext/ipban/main.php b/ext/ipban/main.php index 0469e593..c9e1b387 100644 --- a/ext/ipban/main.php +++ b/ext/ipban/main.php @@ -16,7 +16,7 @@ class RemoveIPBanEvent extends Event { public $id; - public function __construct($id) { + public function __construct(int $id) { $this->id = $id; } } @@ -27,7 +27,7 @@ class AddIPBanEvent extends Event { public $reason; public $end; - public function __construct(/*string(ip)*/ $ip, /*string*/ $reason, /*string*/ $end) { + public function __construct(string $ip, string $reason, string $end) { $this->ip = trim($ip); $this->reason = trim($reason); $this->end = trim($end); @@ -36,7 +36,7 @@ class AddIPBanEvent extends Event { // }}} class IPBan extends Extension { - public function get_priority() {return 10;} + public function get_priority(): int {return 10;} public function onInitExt(InitExtEvent $event) { global $config; @@ -202,7 +202,7 @@ class IPBan extends Extension { } } - private function block(/*string*/ $remote) { + private function block(string $remote) { global $config, $database; $prefix = ($database->get_driver_name() == "sqlite" ? "bans." : ""); diff --git a/ext/link_image/theme.php b/ext/link_image/theme.php index 213311dc..1eb7c48e 100644 --- a/ext/link_image/theme.php +++ b/ext/link_image/theme.php @@ -51,7 +51,7 @@ class LinkImageTheme extends Themelet { 50)); } - protected function url (/*string*/ $url, /*string*/ $content, /*string*/ $type) { + protected function url (string $url, string $content, string $type) { if ($content == NULL) {$content=$url;} switch ($type) { @@ -67,7 +67,7 @@ class LinkImageTheme extends Themelet { return $text; } - protected function img (/*string*/ $src, /*string*/ $type) { + protected function img (string $src, string $type) { switch ($type) { case "html": $text = ""; @@ -81,7 +81,7 @@ class LinkImageTheme extends Themelet { return $text; } - protected function link_code(/*string*/ $label, /*string*/ $content, $id=NULL) { + protected function link_code(string $label, string $content, $id=NULL) { return " diff --git a/ext/livefeed/main.php b/ext/livefeed/main.php index a6c281ad..5e58226e 100644 --- a/ext/livefeed/main.php +++ b/ext/livefeed/main.php @@ -46,7 +46,7 @@ class LiveFeed extends Extension { # $this->msg("Image info set"); } - public function get_priority() {return 99;} + public function get_priority(): int {return 99;} /** * @param string $data diff --git a/ext/mass_tagger/theme.php b/ext/mass_tagger/theme.php index abce598b..cc1783e9 100644 --- a/ext/mass_tagger/theme.php +++ b/ext/mass_tagger/theme.php @@ -1,9 +1,6 @@ image_id = $image_id; $this->user = $user; $this->score = $score; diff --git a/ext/pm/main.php b/ext/pm/main.php index 6de56ad7..a5fc3e8f 100644 --- a/ext/pm/main.php +++ b/ext/pm/main.php @@ -21,7 +21,7 @@ class SendPMEvent extends Event { class PM { public $id, $from_id, $from_ip, $to_id, $sent_date, $subject, $message, $is_read; - public function __construct($from_id=0, $from_ip="0.0.0.0", $to_id=0, $subject="A Message", $message="Some Text", $read=False) { + public function __construct($from_id=0, string $from_ip="0.0.0.0", int $to_id=0, string $subject="A Message", string $message="Some Text", bool $read=False) { # PHP: the P stands for "really", the H stands for "awful" and the other P stands for "language" if(is_array($from_id)) { $a = $from_id; diff --git a/ext/pools/main.php b/ext/pools/main.php index 4788de9e..3bb90cb9 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -373,7 +373,7 @@ class Pools extends Extension { * @param \Page $page * @param int $pageNumber */ - private function list_pools(Page $page, /*int*/ $pageNumber) { + private function list_pools(Page $page, int $pageNumber) { global $config, $database; $pageNumber = clamp($pageNumber, 1, null) - 1; @@ -446,7 +446,7 @@ class Pools extends Extension { * @param int $poolID Array of integers * @return array */ - private function get_pool(/*int*/ $poolID) { + private function get_pool(int $poolID) { global $database; return $database->get_all("SELECT * FROM pools WHERE id=:id", array("id"=>$poolID)); } @@ -456,7 +456,7 @@ class Pools extends Extension { * @param int $poolID the pool id * @return array Array with only 1 element in the one dimension */ - private function get_single_pool(/*int*/ $poolID) { + private function get_single_pool(int $poolID) { global $database; return $database->get_row("SELECT * FROM pools WHERE id=:id", array("id"=>$poolID)); } @@ -466,7 +466,7 @@ class Pools extends Extension { * @param string $poolTitle * @return array Array (with only 1 element in the one dimension) */ - private function get_single_pool_from_title(/*string*/ $poolTitle) { + private function get_single_pool_from_title(string $poolTitle) { global $database; return $database->get_row("SELECT * FROM pools WHERE title=:title", array("title"=>$poolTitle)); } @@ -476,7 +476,7 @@ class Pools extends Extension { * @param int $imageID Integer ID for the image * @return int[] */ - private function get_pool_ids(/*int*/ $imageID) { + private function get_pool_ids(int $imageID) { global $database; return $database->get_col("SELECT pool_id FROM pool_images WHERE image_id=:iid", array("iid"=>$imageID)); } @@ -486,7 +486,7 @@ class Pools extends Extension { * @param int $userID * @return array */ - private function get_last_userpool(/*int*/ $userID){ + private function get_last_userpool(int $userID){ global $database; return $database->get_row("SELECT * FROM pools WHERE user_id=:uid ORDER BY id DESC", array("uid"=>$userID)); } @@ -495,7 +495,7 @@ class Pools extends Extension { * HERE WE GET THE IMAGES FROM THE TAG ON IMPORT * @param int $pool_id */ - private function import_posts(/*int*/ $pool_id) { + private function import_posts(int $pool_id) { global $page, $config; $poolsMaxResults = $config->get_int("poolsMaxImportResults", 1000); @@ -610,7 +610,7 @@ class Pools extends Extension { * @param int $imageID * @return bool */ - private function check_post(/*int*/ $poolID, /*int*/ $imageID) { + private function check_post(int $poolID, int $imageID) { global $database; $result = $database->get_one("SELECT COUNT(*) FROM pool_images WHERE pool_id=:pid AND image_id=:iid", array("pid"=>$poolID, "iid"=>$imageID)); return ($result != 0); @@ -623,7 +623,7 @@ class Pools extends Extension { * @param int $imageID Integer * @return array Array returning two elements (prev, next) in 1 dimension. Each returns ImageID or NULL if none. */ - private function get_nav_posts(/*array*/ $pool, /*int*/ $imageID) { + private function get_nav_posts(array $pool, int $imageID) { global $database; if (empty($pool) || empty($imageID)) @@ -674,7 +674,7 @@ class Pools extends Extension { * @param PageRequestEvent $event * @param int $poolID */ - private function get_posts($event, /*int*/ $poolID) { + private function get_posts($event, int $poolID) { global $config, $user, $database; $pageNumber = int_escape($event->get_arg(2)); @@ -739,7 +739,7 @@ class Pools extends Extension { * @param int $poolID * @return \Image[] Array of image objects. */ - private function edit_posts(/*int*/ $poolID) { + private function edit_posts(int $poolID) { global $database; $result = $database->Execute("SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order ASC", array("pid"=>$poolID)); @@ -760,7 +760,7 @@ class Pools extends Extension { * @param int $poolID * @return \Image[] */ - private function edit_order(/*int*/ $poolID) { + private function edit_order(int $poolID) { global $database; $result = $database->Execute("SELECT image_id FROM pool_images WHERE pool_id=:pid ORDER BY image_order ASC", array("pid"=>$poolID)); @@ -786,7 +786,7 @@ class Pools extends Extension { * * @param int $poolID */ - private function nuke_pool(/*int*/ $poolID) { + private function nuke_pool(int $poolID) { global $user, $database; $p_id = $database->get_one("SELECT user_id FROM pools WHERE id = :pid", array("pid"=>$poolID)); @@ -809,7 +809,7 @@ class Pools extends Extension { * @param string $images * @param int $count */ - private function add_history(/*int*/ $poolID, $action, $images, $count) { + private function add_history(int $poolID, $action, $images, $count) { global $user, $database; $database->execute(" @@ -822,7 +822,7 @@ class Pools extends Extension { * HERE WE GET THE HISTORY LIST. * @param int $pageNumber */ - private function get_history(/*int*/ $pageNumber) { + private function get_history(int $pageNumber) { global $config, $database; if(is_null($pageNumber) || !is_numeric($pageNumber)) @@ -855,7 +855,7 @@ class Pools extends Extension { * HERE GO BACK IN HISTORY AND ADD OR REMOVE POSTS TO POOL. * @param int $historyID */ - private function revert_history(/*int*/ $historyID) { + private function revert_history(int $historyID) { global $database; $status = $database->get_all("SELECT * FROM pool_history WHERE id=:hid", array("hid"=>$historyID)); @@ -905,7 +905,7 @@ class Pools extends Extension { * @param bool $history * @param int $imageOrder */ - private function add_post(/*int*/ $poolID, /*int*/ $imageID, $history=false, $imageOrder=0) { + private function add_post(int $poolID, int $imageID, $history=false, $imageOrder=0) { global $database, $config; if(!$this->check_post($poolID, $imageID)) { @@ -939,7 +939,7 @@ class Pools extends Extension { * @param int $imageID * @param bool $history */ - private function delete_post(/*int*/ $poolID, /*int*/ $imageID, $history=false) { + private function delete_post(int $poolID, int $imageID, $history=false) { global $database; $database->execute("DELETE FROM pool_images WHERE pool_id = :pid AND image_id = :iid", array("pid"=>$poolID, "iid"=>$imageID)); diff --git a/ext/pools/theme.php b/ext/pools/theme.php index 32c5f0f0..2a96436c 100644 --- a/ext/pools/theme.php +++ b/ext/pools/theme.php @@ -5,7 +5,7 @@ class PoolsTheme extends Themelet { * Adds a block to the panel with information on the pool(s) the image is in. * @param array Multidimensional array containing pool id, info & nav IDs. */ - public function pool_info(/*array*/ $navIDs) { + public function pool_info(array $navIDs) { global $page; $linksPools = array(); @@ -37,7 +37,7 @@ class PoolsTheme extends Themelet { * @param array $pools * @return string */ - public function get_adder_html(Image $image, /*array*/ $pools) { + public function get_adder_html(Image $image, array $pools) { $h = ""; foreach($pools as $pool) { $h .= ""; @@ -61,7 +61,7 @@ class PoolsTheme extends Themelet { * @param int $pageNumber * @param int $totalPages */ - public function list_pools(Page $page, /*array*/ $pools, /*int*/ $pageNumber, /*int*/ $totalPages) { + public function list_pools(Page $page, array $pools, int $pageNumber, int $totalPages) { $html = '
'.$this->sitename.' +
'.$this->sitename.'
Enabled
@@ -125,12 +125,7 @@ class PoolsTheme extends Themelet { $page->add_block(new Block("Create Pool", $create_html, "main", 20)); } - /** - * @param array $pools - * @param string $heading - * @param bool $check_all - */ - private function display_top(/*array*/ $pools, /*string*/ $heading, $check_all=false) { + private function display_top(array $pools=null, string $heading, bool $check_all=false) { global $page, $user; $page->set_title($heading); @@ -167,7 +162,7 @@ class PoolsTheme extends Themelet { * @param int $pageNumber * @param int $totalPages */ - public function view_pool(/*array*/ $pools, /*array*/ $images, /*int*/ $pageNumber, /*int*/ $totalPages) { + public function view_pool(array $pools, array $images, int $pageNumber, int $totalPages) { global $page; $this->display_top($pools, "Pool: ".html_escape($pools[0]['title'])); @@ -190,7 +185,7 @@ class PoolsTheme extends Themelet { * @param array $pool * @param bool $check_all */ - public function sidebar_options(Page $page, $pool, /*bool*/ $check_all) { + public function sidebar_options(Page $page, $pool, bool $check_all) { global $user; $editor = "\n".make_form( make_link('pool/import') ).' @@ -253,7 +248,7 @@ class PoolsTheme extends Themelet { * @param array $images * @param array $pool */ - public function pool_result(Page $page, /*array*/ $images, /*array*/ $pool) { + public function pool_result(Page $page, array $images, array $pool) { $this->display_top($pool, "Importing Posts", true); $pool_images = " @@ -293,7 +288,7 @@ class PoolsTheme extends Themelet { * @param array $pools * @param array $images */ - public function edit_order(Page $page, /*array*/ $pools, /*array*/ $images) { + public function edit_order(Page $page, array $pools, array $images) { $this->display_top($pools, "Sorting Pool"); $pool_images = "\n"; @@ -326,7 +321,7 @@ class PoolsTheme extends Themelet { * @param array $pools * @param array $images */ - public function edit_pool(Page $page, /*array*/ $pools, /*array*/ $images) { + public function edit_pool(Page $page, array $pools, array $images) { /* EDIT POOL DESCRIPTION */ $desc_html = " ".make_form(make_link("pool/edit_description"))." @@ -368,7 +363,7 @@ class PoolsTheme extends Themelet { * @param int $pageNumber * @param int $totalPages */ - public function show_history($histories, /*int*/ $pageNumber, /*int*/ $totalPages) { + public function show_history($histories, int $pageNumber, int $totalPages) { global $page; $html = '
diff --git a/ext/random_image/main.php b/ext/random_image/main.php index f8b18e80..aaf07f0f 100644 --- a/ext/random_image/main.php +++ b/ext/random_image/main.php @@ -47,7 +47,7 @@ class RandomImage extends Extension { } else if($action === "view") { if(!is_null($image)) { - send_event(new DisplayingImageEvent($image, $page)); + send_event(new DisplayingImageEvent($image)); } } else if($action === "widget") { diff --git a/ext/random_list/theme.php b/ext/random_list/theme.php index dd0f1d25..7d68223c 100644 --- a/ext/random_list/theme.php +++ b/ext/random_list/theme.php @@ -35,11 +35,7 @@ class RandomListTheme extends Themelet { $page->add_block(new Block("Navigation", $nav, "left", 0)); } - /** - * @param string[] $search_terms - * @return string - */ - protected function build_navigation($search_terms) { + protected function build_navigation(array $search_terms): string { $h_search_string = html_escape(implode(" ", $search_terms)); $h_search_link = make_link("random"); $h_search = " diff --git a/ext/rating/main.php b/ext/rating/main.php index fffb60f0..60868393 100644 --- a/ext/rating/main.php +++ b/ext/rating/main.php @@ -25,11 +25,7 @@ class RatingSetEvent extends Event { /** @var string */ public $rating; - /** - * @param Image $image - * @param string $rating - */ - public function __construct(Image $image, /*char*/ $rating) { + public function __construct(Image $image, string $rating) { assert(in_array($rating, array("s", "q", "e", "u"))); $this->image = $image; @@ -43,7 +39,7 @@ class Ratings extends Extension { /** * @return int */ - public function get_priority() {return 50;} + public function get_priority(): int {return 50;} public function onInitExt(InitExtEvent $event) { global $config; @@ -189,7 +185,7 @@ class Ratings extends Extension { * @param string $sqes * @return string */ - public static function privs_to_sql(/*string*/ $sqes) { + public static function privs_to_sql(string $sqes) { $arr = array(); $length = strlen($sqes); for($i=0; $i<$length; $i++) { @@ -203,7 +199,7 @@ class Ratings extends Extension { * @param string $rating * @return string */ - public static function rating_to_human(/*string*/ $rating) { + public static function rating_to_human(string $rating) { switch($rating) { case "s": return "Safe"; case "q": return "Questionable"; @@ -216,7 +212,7 @@ class Ratings extends Extension { * @param string $rating * @return bool */ - public static function rating_is_valid(/*string*/ $rating) { + public static function rating_is_valid(string $rating) { switch($rating) { case "s": case "q": @@ -279,7 +275,7 @@ class Ratings extends Extension { * @param string $rating * @param string $old_rating */ - private function set_rating(/*int*/ $image_id, /*string*/ $rating, /*string*/ $old_rating) { + private function set_rating(int $image_id, string $rating, string $old_rating) { global $database; if($old_rating != $rating){ $database->Execute("UPDATE images SET rating=? WHERE id=?", array($rating, $image_id)); diff --git a/ext/rating/theme.php b/ext/rating/theme.php index d3836c5d..3bcd32d2 100644 --- a/ext/rating/theme.php +++ b/ext/rating/theme.php @@ -6,7 +6,7 @@ class RatingsTheme extends Themelet { * @param string $rating * @return string */ - public function get_rater_html(/*int*/ $image_id, /*string*/ $rating, /*bool*/ $can_rate) { + public function get_rater_html(int $image_id, string $rating, bool $can_rate) { $s_checked = $rating == 's' ? " checked" : ""; $q_checked = $rating == 'q' ? " checked" : ""; $e_checked = $rating == 'e' ? " checked" : ""; diff --git a/ext/relatationships/main.php b/ext/relatationships/main.php index e81aefbb..46b15a27 100644 --- a/ext/relatationships/main.php +++ b/ext/relatationships/main.php @@ -103,7 +103,7 @@ class Relationships extends Extension { * @param int $imageID * @param int $parentID */ - private function set_parent(/*int*/ $imageID, /*int*/ $parentID){ + private function set_parent(int $imageID, int $parentID){ global $database; if($database->get_row("SELECT 1 FROM images WHERE id = :pid", array("pid"=>$parentID))){ @@ -116,7 +116,7 @@ class Relationships extends Extension { * @param int $parentID * @param int $childID */ - private function set_child(/*int*/ $parentID, /*int*/ $childID){ + private function set_child(int $parentID, int $childID){ global $database; if($database->get_row("SELECT 1 FROM images WHERE id = :cid", array("cid"=>$childID))){ @@ -128,7 +128,7 @@ class Relationships extends Extension { /** * @param int $imageID */ - private function remove_parent(/*int*/ $imageID){ + private function remove_parent(int $imageID){ global $database; $parentID = $database->get_one("SELECT parent_id FROM images WHERE id = :iid", array("iid"=>$imageID)); diff --git a/ext/report_image/main.php b/ext/report_image/main.php index 65ffad39..8cf510f4 100644 --- a/ext/report_image/main.php +++ b/ext/report_image/main.php @@ -13,10 +13,7 @@ class RemoveReportedImageEvent extends Event { /** @var int */ public $id; - /** - * @param int $id - */ - public function __construct($id) { + public function __construct(int $id) { $this->id = $id; } } @@ -25,10 +22,7 @@ class AddReportedImageEvent extends Event { /** @var ImageReport */ public $report; - /** - * @param ImageReport $report - */ - public function __construct($report) { + public function __construct(ImageReport $report) { $this->report = $report; } } @@ -41,7 +35,7 @@ class ImageReport { /** @var string */ public $reason; - public function __construct($image_id, $user_id, $reason) { + public function __construct(int $image_id, int $user_id, string $reason) { $this->image_id = $image_id; $this->user_id = $user_id; $this->reason = $reason; diff --git a/ext/report_image/theme.php b/ext/report_image/theme.php index 251bc49e..8861382c 100644 --- a/ext/report_image/theme.php +++ b/ext/report_image/theme.php @@ -66,7 +66,7 @@ class ReportImageTheme extends Themelet { * @param Image $image * @param ImageReport[] $reports */ - public function display_image_banner(Image $image, /*array*/ $reports) { + public function display_image_banner(Image $image, array $reports) { global $config, $page; $i_image = int_escape($image->id); diff --git a/ext/res_limit/main.php b/ext/res_limit/main.php index 34b0f90d..82cb40c1 100644 --- a/ext/res_limit/main.php +++ b/ext/res_limit/main.php @@ -7,7 +7,7 @@ * Description: Allows the admin to set min / max image dimentions */ class ResolutionLimit extends Extension { - public function get_priority() {return 40;} // early, to veto ImageUploadEvent + public function get_priority(): int {return 40;} // early, to veto ImageUploadEvent public function onImageAddition(ImageAdditionEvent $event) { global $config; diff --git a/ext/resize/main.php b/ext/resize/main.php index 70e34f27..c265e0ab 100644 --- a/ext/resize/main.php +++ b/ext/resize/main.php @@ -164,7 +164,7 @@ class ResizeImage extends Extension { * @param int $height * @throws ImageResizeException */ - private function resize_image(Image $image_obj, /*int*/ $width, /*int*/ $height) { + private function resize_image(Image $image_obj, int $width, int $height) { global $database; if ( ($height <= 0) && ($width <= 0) ) { diff --git a/ext/resize/theme.php b/ext/resize/theme.php index cad3b85c..331386d5 100644 --- a/ext/resize/theme.php +++ b/ext/resize/theme.php @@ -28,7 +28,7 @@ class ResizeImageTheme extends Themelet { return $html; } - public function display_resize_error(Page $page, /*string*/ $title, /*string*/ $message) { + public function display_resize_error(Page $page, string $title, string $message) { $page->set_title("Resize Image"); $page->set_heading("Resize Image"); $page->add_block(new NavBlock()); diff --git a/ext/rotate/main.php b/ext/rotate/main.php index 94793dd4..ace91dc5 100644 --- a/ext/rotate/main.php +++ b/ext/rotate/main.php @@ -113,7 +113,7 @@ class RotateImage extends Extension { * @param int $deg * @throws ImageRotateException */ - private function rotate_image(/*int*/ $image_id, /*int*/ $deg) { + private function rotate_image(int $image_id, int $deg) { global $database; if ( ($deg <= -360) || ($deg >= 360) ) { diff --git a/ext/rotate/theme.php b/ext/rotate/theme.php index 813efebe..c979e005 100644 --- a/ext/rotate/theme.php +++ b/ext/rotate/theme.php @@ -7,7 +7,7 @@ class RotateImageTheme extends Themelet { * @param int $image_id * @return string */ - public function get_rotate_html(/*int*/ $image_id) { + public function get_rotate_html(int $image_id) { $html = " ".make_form(make_link('rotate/'.$image_id), 'POST')." @@ -26,7 +26,7 @@ class RotateImageTheme extends Themelet { * @param string $title * @param string $message */ - public function display_rotate_error(Page $page, /*string*/ $title, /*string*/ $message) { + public function display_rotate_error(Page $page, string $title, string $message) { $page->set_title("Rotate Image"); $page->set_heading("Rotate Image"); $page->add_block(new NavBlock()); diff --git a/ext/rss_images/main.php b/ext/rss_images/main.php index 5edffddf..7e213a4c 100644 --- a/ext/rss_images/main.php +++ b/ext/rss_images/main.php @@ -38,7 +38,7 @@ class RSS_Images extends Extension { * @param array $search_terms * @param int $page_number */ - private function do_rss($images, $search_terms, /*int*/ $page_number) { + private function do_rss($images, $search_terms, int $page_number) { global $page; global $config; $page->set_mode("data"); @@ -83,11 +83,7 @@ class RSS_Images extends Extension { $page->set_data($xml); } - /** - * @param Image $image - * @return string - */ - private function thumb(Image $image) { + private function thumb(Image $image): string { global $database; $cached = $database->cache->get("rss-thumb:{$image->id}"); diff --git a/ext/setup/main.php b/ext/setup/main.php index 96eaff9f..ae0c467a 100644 --- a/ext/setup/main.php +++ b/ext/setup/main.php @@ -63,28 +63,18 @@ class SetupBlock extends Block { /** @var string */ public $body; - /** - * @param string $title - */ - public function __construct($title) { + public function __construct(string $title) { $this->header = $title; $this->section = "main"; $this->position = 50; $this->body = ""; } - /** - * @param string $text - */ - public function add_label($text) { + public function add_label(string $text) { $this->body .= $text; } - /** - * @param string $name - * @param null|string $label - */ - public function add_text_option($name, $label=null) { + public function add_text_option(string $name, string $label=null) { global $config; $val = html_escape($config->get_string($name)); if(!is_null($label)) { @@ -94,11 +84,7 @@ class SetupBlock extends Block { $this->body .= "\n"; } - /** - * @param string $name - * @param null|string $label - */ - public function add_longtext_option($name, $label=null) { + public function add_longtext_option(string $name, string $label=null) { global $config; $val = html_escape($config->get_string($name)); if(!is_null($label)) { @@ -109,11 +95,7 @@ class SetupBlock extends Block { $this->body .= "\n"; } - /** - * @param string $name - * @param null|string $label - */ - public function add_bool_option($name, $label=null) { + public function add_bool_option(string $name, string $label=null) { global $config; $checked = $config->get_bool($name) ? " checked" : ""; if(!is_null($label)) { @@ -129,11 +111,7 @@ class SetupBlock extends Block { // $this->body .= ""; // } - /** - * @param string $name - * @param null|string $label - */ - public function add_int_option($name, $label=null) { + public function add_int_option(string $name, string $label=null) { global $config; $val = html_escape($config->get_string($name)); if(!is_null($label)) { @@ -143,11 +121,7 @@ class SetupBlock extends Block { $this->body .= "\n"; } - /** - * @param string $name - * @param null|string $label - */ - public function add_shorthand_int_option($name, $label=null) { + public function add_shorthand_int_option(string $name, string $label=null) { global $config; $val = to_shorthand_int($config->get_string($name)); if(!is_null($label)) { @@ -157,12 +131,7 @@ class SetupBlock extends Block { $this->body .= "\n"; } - /** - * @param string $name - * @param string[] $options - * @param null|string $label - */ - public function add_choice_option($name, $options, $label=null) { + public function add_choice_option(string $name, array $options, string $label=null) { global $config; $current = $config->get_string($name); @@ -181,12 +150,7 @@ class SetupBlock extends Block { $this->body .= $html; } - /** - * @param string $name - * @param string[] $options - * @param null|string $label - */ - public function add_multichoice_option($name, $options, $label=null) { + public function add_multichoice_option(string $name, array $options, string $label=null) { global $config; $current = $config->get_array($name); diff --git a/ext/shimmie_api/main.php b/ext/shimmie_api/main.php index a672f85b..b1b55075 100644 --- a/ext/shimmie_api/main.php +++ b/ext/shimmie_api/main.php @@ -127,12 +127,7 @@ class ShimmieApi extends Extension { return $res; } - /** - * @param string $type - * @param string $query - * @return array - */ - private function api_get_user($type, $query) { + private function api_get_user(string $type, string $query): array { global $database; $all = $database->get_row( "SELECT id, name, joindate, class FROM users WHERE $type=?", diff --git a/ext/sitemap/main.php b/ext/sitemap/main.php index 9c34890a..08ca96f4 100644 --- a/ext/sitemap/main.php +++ b/ext/sitemap/main.php @@ -122,8 +122,8 @@ class XMLSitemap extends Extension * @param string $priority * @param string $date */ - private function add_sitemap_queue( /*array(urls)*/ $urls, $changefreq = "monthly", - $priority = "0.5", $date = "2013-02-01") + private function add_sitemap_queue(array $urls, $changefreq = "monthly", + $priority = "0.5", $date = "2013-02-01") { foreach ($urls as $url) { $link = make_http(make_link("$url")); diff --git a/ext/source_history/main.php b/ext/source_history/main.php index 12d7af55..977450ef 100644 --- a/ext/source_history/main.php +++ b/ext/source_history/main.php @@ -7,7 +7,7 @@ class Source_History extends Extension { // in before source are actually set, so that "get current source" works - public function get_priority() {return 40;} + public function get_priority(): int {return 40;} public function onInitExt(InitExtEvent $event) { global $config; @@ -207,7 +207,7 @@ class Source_History extends Extension { * @param int $revert_id * @return mixed|null */ - public function get_source_history_from_revert(/*int*/ $revert_id) { + public function get_source_history_from_revert(int $revert_id) { global $database; $row = $database->get_row(" SELECT source_histories.*, users.name @@ -221,7 +221,7 @@ class Source_History extends Extension { * @param int $image_id * @return array */ - public function get_source_history_from_id(/*int*/ $image_id) { + public function get_source_history_from_id(int $image_id) { global $database; $row = $database->get_all(" SELECT source_histories.*, users.name diff --git a/ext/source_history/theme.php b/ext/source_history/theme.php index c02ee222..357912fb 100644 --- a/ext/source_history/theme.php +++ b/ext/source_history/theme.php @@ -7,7 +7,7 @@ class Source_HistoryTheme extends Themelet { * @param int $image_id * @param array $history */ - public function display_history_page(Page $page, /*int*/ $image_id, /*array*/ $history) { + public function display_history_page(Page $page, int $image_id, array $history) { global $user; $start_string = "
@@ -60,7 +60,7 @@ class Source_HistoryTheme extends Themelet { * @param array $history * @param int $page_number */ - public function display_global_page(Page $page, /*array*/ $history, /*int*/ $page_number) { + public function display_global_page(Page $page, array $history, int $page_number) { $start_string = "
".make_form(make_link("source_history/revert"))." @@ -112,7 +112,7 @@ class Source_HistoryTheme extends Themelet { * Add a section to the admin page. * @param string $validation_msg */ - public function display_admin_block(/*string*/ $validation_msg='') { + public function display_admin_block(string $validation_msg='') { global $page; if (!empty($validation_msg)) { @@ -150,7 +150,7 @@ class Source_HistoryTheme extends Themelet { * @param string $title * @param string $body */ - public function add_status(/*string*/ $title, /*string*/ $body) { + public function add_status(string $title, string $body) { $this->messages[] = '

'. $title .'
'. $body .'

'; } } diff --git a/ext/statsd/main.php b/ext/statsd/main.php index 79fe7030..01cbb757 100644 --- a/ext/statsd/main.php +++ b/ext/statsd/main.php @@ -84,7 +84,7 @@ class StatsDInterface extends Extension { /** * @return int */ - public function get_priority() {return 99;} + public function get_priority(): int {return 99;} /** * @param array $data diff --git a/ext/tag_edit/main.php b/ext/tag_edit/main.php index 2f270fd0..c90420c1 100644 --- a/ext/tag_edit/main.php +++ b/ext/tag_edit/main.php @@ -52,10 +52,6 @@ class OwnerSetEvent extends Event { /** @var \User */ public $owner; - /** - * @param Image $image - * @param User $owner - */ public function __construct(Image $image, User $owner) { $this->image = $image; $this->owner = $owner; @@ -63,35 +59,19 @@ class OwnerSetEvent extends Event { } -/* - * SourceSetEvent: - * $image_id - * $source - * - */ class SourceSetEvent extends Event { /** @var \Image */ public $image; /** @var string */ public $source; - /** - * @param Image $image - * @param string $source - */ - public function __construct(Image $image, $source) { + public function __construct(Image $image, string $source=null) { $this->image = $image; $this->source = $source; } } -/* - * TagSetEvent: - * $image_id - * $tags - * - */ class TagSetEvent extends Event { /** @var \Image */ public $image; @@ -135,13 +115,7 @@ class LockSetEvent extends Event { /** @var bool */ public $locked; - /** - * @param Image $image - * @param bool $locked - */ - public function __construct(Image $image, $locked) { - assert('is_bool($locked)'); - + public function __construct(Image $image, bool $locked) { $this->image = $image; $this->locked = $locked; } @@ -159,25 +133,13 @@ class TagTermParseEvent extends Event { /** @var bool */ public $parse = TRUE; //marks the tag to be parsed, and not just checked if valid metatag - /** - * @param string $term - * @param int $id - * @param bool $parse - */ - public function __construct($term, $id, $parse) { - assert('is_string($term)'); - assert('is_int($id)'); - assert('is_bool($parse)'); - + public function __construct(string $term, int $id, bool $parse) { $this->term = $term; $this->id = $id; $this->parse = $parse; } - /** - * @return bool - */ - public function is_metatag() { + public function is_metatag(): bool { return $this->metatag; } } diff --git a/ext/tag_edit/theme.php b/ext/tag_edit/theme.php index 498cfcd1..59675d17 100644 --- a/ext/tag_edit/theme.php +++ b/ext/tag_edit/theme.php @@ -19,7 +19,7 @@ class TagEditTheme extends Themelet { $page->add_block(new Block("Mass Tag Edit", $html)); } - public function mss_html($terms) { + public function mss_html($terms): string { $h_terms = html_escape($terms); $html = make_form(make_link("tag_edit/mass_source_set"), "POST") . " @@ -30,7 +30,7 @@ class TagEditTheme extends Themelet { return $html; } - public function get_tag_editor_html(Image $image) { + public function get_tag_editor_html(Image $image): string { global $user; $tag_links = array(); @@ -58,7 +58,7 @@ class TagEditTheme extends Themelet { "; } - public function get_user_editor_html(Image $image) { + public function get_user_editor_html(Image $image): string { global $user; $h_owner = html_escape($image->get_owner()->name); $h_av = $image->get_owner()->get_avatar_html(); @@ -80,7 +80,7 @@ class TagEditTheme extends Themelet { "; } - public function get_source_editor_html(Image $image) { + public function get_source_editor_html(Image $image): string { global $user; $h_source = html_escape($image->get_source()); $f_source = $this->format_source($image->get_source()); @@ -100,11 +100,7 @@ class TagEditTheme extends Themelet { "; } - /** - * @param string $source - * @return string - */ - protected function format_source(/*string*/ $source) { + protected function format_source(string $source=null): string { if(!empty($source)) { if(!startsWith($source, "http://") && !startsWith($source, "https://")) { $source = "http://" . $source; @@ -120,7 +116,7 @@ class TagEditTheme extends Themelet { return "Unknown"; } - public function get_lock_editor_html(Image $image) { + public function get_lock_editor_html(Image $image): string { global $user; $b_locked = $image->is_locked() ? "Yes (Only admins may edit these details)" : "No"; $h_locked = $image->is_locked() ? " checked" : ""; diff --git a/ext/tag_history/main.php b/ext/tag_history/main.php index 19dd7fea..75b19403 100644 --- a/ext/tag_history/main.php +++ b/ext/tag_history/main.php @@ -7,7 +7,7 @@ class Tag_History extends Extension { // in before tags are actually set, so that "get current tags" works - public function get_priority() {return 40;} + public function get_priority(): int {return 40;} public function onInitExt(InitExtEvent $event) { global $config; @@ -206,7 +206,7 @@ class Tag_History extends Extension { * @param int $revert_id * @return mixed|null */ - public function get_tag_history_from_revert(/*int*/ $revert_id) { + public function get_tag_history_from_revert(int $revert_id) { global $database; $row = $database->get_row(" SELECT tag_histories.*, users.name @@ -220,7 +220,7 @@ class Tag_History extends Extension { * @param int $image_id * @return array */ - public function get_tag_history_from_id(/*int*/ $image_id) { + public function get_tag_history_from_id(int $image_id) { global $database; $row = $database->get_all(" SELECT tag_histories.*, users.name diff --git a/ext/tag_history/theme.php b/ext/tag_history/theme.php index 7e6bb78c..be8cf7aa 100644 --- a/ext/tag_history/theme.php +++ b/ext/tag_history/theme.php @@ -12,7 +12,7 @@ class Tag_HistoryTheme extends Themelet { * @param int $image_id * @param array $history */ - public function display_history_page(Page $page, /*int*/ $image_id, /*array*/ $history) { + public function display_history_page(Page $page, int $image_id, array $history) { global $user; $start_string = "
@@ -72,7 +72,7 @@ class Tag_HistoryTheme extends Themelet { * @param array $history * @param int $page_number */ - public function display_global_page(Page $page, /*array*/ $history, /*int*/ $page_number) { + public function display_global_page(Page $page, array $history, int $page_number) { $start_string = "
".make_form(make_link("tag_history/revert"))." @@ -125,7 +125,7 @@ class Tag_HistoryTheme extends Themelet { * * @param string $validation_msg */ - public function display_admin_block(/*string*/ $validation_msg='') { + public function display_admin_block(string $validation_msg='') { global $page; if (!empty($validation_msg)) { @@ -163,7 +163,7 @@ class Tag_HistoryTheme extends Themelet { * @param string $title * @param string $body */ - public function add_status(/*string*/ $title, /*string*/ $body) { + public function add_status(string $title, string $body) { $this->messages[] = '

'. $title .'
'. $body .'

'; } } diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index 8649a18a..81b7f3a6 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -137,7 +137,7 @@ class TagList extends Extension { * @param string $tag * @return string */ - private function tag_link(/*string*/ $tag) { + private function tag_link(string $tag) { $u_tag = url_escape($tag); return make_link("post/list/$u_tag/1"); } diff --git a/ext/tag_list/theme.php b/ext/tag_list/theme.php index 5ca82bde..d044676a 100644 --- a/ext/tag_list/theme.php +++ b/ext/tag_list/theme.php @@ -241,14 +241,7 @@ class TagListTheme extends Themelet { return array($category, $display_html); } - /** - * @param string $tag - * @param string[] $tags - * @return string - */ - protected function ars(/*string*/ $tag, /*array(string)*/ $tags) { - assert(is_array($tags)); - + protected function ars(string $tag, array $tags): string { // FIXME: a better fix would be to make sure the inputs are correct $tag = strtolower($tag); $tags = array_map("strtolower", $tags); @@ -261,12 +254,7 @@ class TagListTheme extends Themelet { return $html; } - /** - * @param array $tags - * @param string $tag - * @return string - */ - protected function get_remove_link($tags, $tag) { + protected function get_remove_link(array $tags, string $tag): string { if(!in_array($tag, $tags) && !in_array("-$tag", $tags)) { return ""; } @@ -277,12 +265,7 @@ class TagListTheme extends Themelet { } } - /** - * @param array $tags - * @param string $tag - * @return string - */ - protected function get_add_link($tags, $tag) { + protected function get_add_link(array $tags, string $tag): string { if(in_array($tag, $tags)) { return ""; } @@ -293,12 +276,7 @@ class TagListTheme extends Themelet { } } - /** - * @param array $tags - * @param string $tag - * @return string - */ - protected function get_subtract_link($tags, $tag) { + protected function get_subtract_link(array $tags, string $tag): string { if(in_array("-$tag", $tags)) { return ""; } @@ -309,11 +287,7 @@ class TagListTheme extends Themelet { } } - /** - * @param string $tag - * @return string - */ - protected function tag_link($tag) { + protected function tag_link(string $tag): string { $u_tag = url_escape($tag); return make_link("post/list/$u_tag/1"); } diff --git a/ext/tagger/main.php b/ext/tagger/main.php index 42d9e01a..941ac28b 100644 --- a/ext/tagger/main.php +++ b/ext/tagger/main.php @@ -29,7 +29,7 @@ class Tagger extends Extension { // Tagger AJAX back-end class TaggerXML extends Extension { - public function get_priority() {return 10;} + public function get_priority(): int {return 10;} public function onPageRequest(PageRequestEvent $event) { if($event->page_matches("tagger/tags")) { diff --git a/ext/tips/main.php b/ext/tips/main.php index 079e53fb..da13eda5 100644 --- a/ext/tips/main.php +++ b/ext/tips/main.php @@ -134,10 +134,7 @@ class Tips extends Extension { $this->theme->showAll($url, $tips); } - /** - * @param int $tipID - */ - private function setStatus($tipID) { + private function setStatus(int $tipID) { global $database; $tip = $database->get_row("SELECT * FROM tips WHERE id = ? ", array(int_escape($tipID))); @@ -151,10 +148,7 @@ class Tips extends Extension { $database->execute("UPDATE tips SET enable = ? WHERE id = ?", array ($enable, int_escape($tipID))); } - /** - * @param int $tipID - */ - private function deleteTip($tipID) { + private function deleteTip(int $tipID) { global $database; $database->execute("DELETE FROM tips WHERE id = ?", array(int_escape($tipID))); } diff --git a/ext/upgrade/main.php b/ext/upgrade/main.php index 8f4b7dc5..ea586b7d 100644 --- a/ext/upgrade/main.php +++ b/ext/upgrade/main.php @@ -129,7 +129,9 @@ class Upgrade extends Extension { } } - /** @return int */ - public function get_priority() {return 5;} + /** + * @return int + */ + public function get_priority(): int {return 5;} } diff --git a/ext/upload/main.php b/ext/upload/main.php index 376d9212..7fe8ee8d 100644 --- a/ext/upload/main.php +++ b/ext/upload/main.php @@ -28,7 +28,7 @@ class DataUploadEvent extends Event { * @param string $tmpname The temporary file used for upload. * @param array $metadata Info about the file, should contain at least "filename", "extension", "tags" and "source". */ - public function __construct(/*string*/ $tmpname, /*array*/ $metadata) { + public function __construct(string $tmpname, array $metadata) { assert('file_exists($tmpname)'); assert('is_string($metadata["filename"])'); assert('is_string($metadata["extension"])'); @@ -60,16 +60,15 @@ class Upload extends Extension { /** * Early, so it can stop the DataUploadEvent before any data handlers see it. - * * @return int */ - public function get_priority() {return 40;} + public function get_priority(): int {return 40;} public function onInitExt(InitExtEvent $event) { global $config; $config->set_default_int('upload_count', 3); - $config->set_default_int('upload_size', '1MB'); - $config->set_default_int('upload_min_free_space', '100MB'); + $config->set_default_int('upload_size', parse_shorthand_int('1MB')); + $config->set_default_int('upload_min_free_space', parse_shorthand_int('100MB')); $config->set_default_bool('upload_tlsource', TRUE); $this->is_full = false; diff --git a/ext/upload/theme.php b/ext/upload/theme.php index 3dba5c72..fa826114 100644 --- a/ext/upload/theme.php +++ b/ext/upload/theme.php @@ -248,7 +248,7 @@ class UploadTheme extends Themelet { * @param Page $page * @param int $image_id */ - public function display_replace_page(Page $page, /*int*/ $image_id) { + public function display_replace_page(Page $page, int $image_id) { global $config, $page; $tl_enabled = ($config->get_string("transload_engine", "none") != "none"); @@ -295,7 +295,7 @@ class UploadTheme extends Themelet { * @param Page $page * @param bool $ok */ - public function display_upload_status(Page $page, /*bool*/ $ok) { + public function display_upload_status(Page $page, bool $ok) { if($ok) { $page->set_mode("redirect"); $page->set_redirect(make_link()); @@ -312,7 +312,7 @@ class UploadTheme extends Themelet { * @param string $title * @param string $message */ - public function display_upload_error(Page $page, /*string*/ $title, /*string*/ $message) { + public function display_upload_error(Page $page, string $title, string $message) { $page->add_block(new Block($title, $message)); } diff --git a/ext/user/main.php b/ext/user/main.php index 12d279d9..7d4a6428 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -9,12 +9,7 @@ class UserBlockBuildingEvent extends Event { /** @var array */ public $parts = array(); - /** - * @param string $name - * @param string $link - * @param int $position - */ - public function add_link($name, $link, $position=50) { + public function add_link(string $name, string $link, int $position=50) { while(isset($this->parts[$position])) $position++; $this->parts[$position] = array("name" => $name, "link" => $link); } @@ -26,18 +21,11 @@ class UserPageBuildingEvent extends Event { /** @var array */ public $stats = array(); - /** - * @param User $display_user - */ public function __construct(User $display_user) { $this->display_user = $display_user; } - /** - * @param string $html - * @param int $position - */ - public function add_stats($html, $position=50) { + public function add_stats(string $html, int $position=50) { while(isset($this->stats[$position])) { $position++; } $this->stats[$position] = $html; } @@ -51,12 +39,7 @@ class UserCreationEvent extends Event { /** @var string */ public $email; - /** - * @param string $name - * @param string $pass - * @param string $email - */ - public function __construct($name, $pass, $email) { + public function __construct(string $name, string $pass, string $email) { $this->username = $name; $this->password = $pass; $this->email = $email; @@ -67,10 +50,7 @@ class UserDeletionEvent extends Event { /** @var int */ public $id; - /** - * @param int $id - */ - public function __construct($id) { + public function __construct(int $id) { $this->id = $id; } } @@ -207,9 +187,6 @@ class UserPage extends Extension { } } - /** - * @param UserPageBuildingEvent $event - */ public function onUserPageBuilding(UserPageBuildingEvent $event) { global $user, $config; @@ -240,9 +217,6 @@ class UserPage extends Extension { } } - /** - * @param UserPageBuildingEvent $event - */ private function display_stats(UserPageBuildingEvent $event) { global $user, $page, $config; @@ -265,9 +239,6 @@ class UserPage extends Extension { } } - /** - * @param SetupBuildingEvent $event - */ public function onSetupBuilding(SetupBuildingEvent $event) { global $config; @@ -303,9 +274,6 @@ class UserPage extends Extension { $event->panel->add_block($sb); } - /** - * @param UserBlockBuildingEvent $event - */ public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; $event->add_link("My Profile", make_link("user")); @@ -315,17 +283,11 @@ class UserPage extends Extension { $event->add_link("Log Out", make_link("user_admin/logout"), 99); } - /** - * @param UserCreationEvent $event - */ public function onUserCreation(UserCreationEvent $event) { $this->check_user_creation($event); $this->create_user($event); } - /** - * @param SearchTermParseEvent $event - */ public function onSearchTermParse(SearchTermParseEvent $event) { global $user; @@ -418,10 +380,7 @@ class UserPage extends Extension { } } - /** - * @param string $username - */ - private function page_recover($username) { + private function page_recover(string $username) { $user = User::by_name($username); if (is_null($user)) { $this->theme->display_error(404, "Error", "There's no user with that name"); @@ -457,10 +416,6 @@ class UserPage extends Extension { } } - /** - * @param UserCreationEvent $event - * @throws UserCreationException - */ private function check_user_creation(UserCreationEvent $event) { $name = $event->username; //$pass = $event->password; @@ -497,11 +452,7 @@ class UserPage extends Extension { log_info("user", "Created User #$uid ({$event->username})"); } - /** - * @param string $name - * @param string $pass - */ - private function set_login_cookie(/*string*/ $name, /*string*/ $pass) { + private function set_login_cookie(string $name, string $pass) { global $config, $page; $addr = get_session_ip($config); @@ -514,12 +465,7 @@ class UserPage extends Extension { } //}}} // Things done *to* the user {{{ - /** - * @param User $a - * @param User $b - * @return bool - */ - private function user_can_edit_user(User $a, User $b) { + private function user_can_edit_user(User $a, User $b): bool { if($a->is_anonymous()) { $this->theme->display_error(401, "Error", "You aren't logged in"); return false; @@ -565,12 +511,7 @@ class UserPage extends Extension { } } - /** - * @param User $duser - * @param string $pass1 - * @param string $pass2 - */ - private function change_password_wrapper(User $duser, $pass1, $pass2) { + private function change_password_wrapper(User $duser, string $pass1, string $pass2) { global $user; if($this->user_can_edit_user($user, $duser)) { @@ -591,11 +532,7 @@ class UserPage extends Extension { } } - /** - * @param User $duser - * @param string $address - */ - private function change_email_wrapper(User $duser, /*string(email)*/ $address) { + private function change_email_wrapper(User $duser, string $address) { global $user; if($this->user_can_edit_user($user, $duser)) { @@ -606,12 +543,7 @@ class UserPage extends Extension { } } - /** - * @param User $duser - * @param string $class - * @throws NullUserException - */ - private function change_class_wrapper(User $duser, /*string(class)*/ $class) { + private function change_class_wrapper(User $duser, string $class) { global $user; if($user->class->name == "admin") { @@ -622,11 +554,7 @@ class UserPage extends Extension { } // }}} // ips {{{ - /** - * @param User $duser - * @return array - */ - private function count_upload_ips(User $duser) { + private function count_upload_ips(User $duser): array { global $database; $rows = $database->get_pairs(" SELECT @@ -640,11 +568,7 @@ class UserPage extends Extension { return $rows; } - /** - * @param User $duser - * @return array - */ - private function count_comment_ips(User $duser) { + private function count_comment_ips(User $duser): array { global $database; $rows = $database->get_pairs(" SELECT @@ -658,12 +582,7 @@ class UserPage extends Extension { return $rows; } - /** - * @param Page $page - * @param bool $with_images - * @param bool $with_comments - */ - private function delete_user(Page $page, /*boolean*/ $with_images=false, /*boolean*/ $with_comments=false) { + private function delete_user(Page $page, bool $with_images=false, bool $with_comments=false) { global $user, $config, $database; $page->set_title("Error"); diff --git a/ext/user/theme.php b/ext/user/theme.php index 6f16a86c..93a8e3a0 100644 --- a/ext/user/theme.php +++ b/ext/user/theme.php @@ -14,7 +14,7 @@ class UserPageTheme extends Themelet { * @param User[] $users * @param User $user */ - public function display_user_list(Page $page, $users, User $user) { + public function display_user_list(Page $page, array $users, User $user) { $page->set_title("User List"); $page->set_heading("User List"); $page->add_block(new NavBlock()); @@ -148,12 +148,7 @@ class UserPageTheme extends Themelet { $page->add_block(new Block("Login", $html, "left", 90)); } - /** - * @param Page $page - * @param array $uploads - * @param array $comments - */ - public function display_ip_list(Page $page, $uploads, $comments) { + public function display_ip_list(Page $page, array $uploads, array $comments) { $html = "
"; $html .= "
Uploaded from: "; $n = 0; diff --git a/ext/varnish/main.php b/ext/varnish/main.php index bb3882f1..825d43e1 100644 --- a/ext/varnish/main.php +++ b/ext/varnish/main.php @@ -38,5 +38,5 @@ class VarnishPurger extends Extension { /** * @return int */ - public function get_priority() {return 99;} + public function get_priority(): int {return 99;} } diff --git a/ext/view/main.php b/ext/view/main.php index 2c80e4a4..2f7b7837 100644 --- a/ext/view/main.php +++ b/ext/view/main.php @@ -17,19 +17,12 @@ class DisplayingImageEvent extends Event { /** @var \Image */ public $image; - public $page, $context; - /** - * @param Image $image - */ public function __construct(Image $image) { $this->image = $image; } - /** - * @return Image - */ - public function get_image() { + public function get_image(): Image { return $this->image; } } @@ -42,20 +35,12 @@ class ImageInfoBoxBuildingEvent extends Event { /** @var \User */ public $user; - /** - * @param Image $image - * @param User $user - */ public function __construct(Image $image, User $user) { $this->image = $image; $this->user = $user; } - /** - * @param string $html - * @param int $position - */ - public function add_part($html, $position=50) { + public function add_part(string $html, int $position=50) { while(isset($this->parts[$position])) $position++; $this->parts[$position] = $html; } @@ -65,9 +50,6 @@ class ImageInfoSetEvent extends Event { /** @var \Image */ public $image; - /** - * @param Image $image - */ public function __construct(Image $image) { $this->image = $image; } @@ -81,20 +63,12 @@ class ImageAdminBlockBuildingEvent extends Event { /** @var null|\User */ public $user = null; - /** - * @param Image $image - * @param User $user - */ public function __construct(Image $image, User $user) { $this->image = $image; $this->user = $user; } - /** - * @param string $html - * @param int $position - */ - public function add_part(/*string*/ $html, /*int*/ $position=50) { + public function add_part(string $html, int $position=50) { while(isset($this->parts[$position])) $position++; $this->parts[$position] = $html; } diff --git a/ext/wiki/main.php b/ext/wiki/main.php index 5d5d28da..98f29f04 100644 --- a/ext/wiki/main.php +++ b/ext/wiki/main.php @@ -14,10 +14,6 @@ class WikiUpdateEvent extends Event { /** @var \WikiPage */ public $wikipage; - /** - * @param User $user - * @param WikiPage $wikipage - */ public function __construct(User $user, WikiPage $wikipage) { $this->user = $user; $this->wikipage = $wikipage; @@ -52,10 +48,7 @@ class WikiPage { /** @var string */ public $body; - /** - * @param mixed $row - */ - public function __construct($row=null) { + public function __construct(array $row=null) { //assert(!empty($row)); if (!is_null($row)) { @@ -77,10 +70,7 @@ class WikiPage { return User::by_id($this->owner_id); } - /** - * @return bool - */ - public function is_locked() { + public function is_locked(): bool { return $this->locked; } } @@ -205,7 +195,7 @@ class Wiki extends Extension { * @param WikiPage $page * @return bool */ - public static function can_edit(User $user, WikiPage $page) { + public static function can_edit(User $user, WikiPage $page): bool { // admins can edit everything if($user->is_admin()) return true; @@ -218,12 +208,7 @@ class Wiki extends Extension { return false; } - /** - * @param string $title - * @param integer $revision - * @return WikiPage - */ - private function get_page($title, $revision=-1) { + private function get_page(string $title, int $revision=-1): WikiPage { global $database; // first try and get the actual page $row = $database->get_row($database->scoreql_to_sql(" diff --git a/ext/wiki/theme.php b/ext/wiki/theme.php index 662159fb..db1073ca 100644 --- a/ext/wiki/theme.php +++ b/ext/wiki/theme.php @@ -8,7 +8,7 @@ class WikiTheme extends Themelet { * @param WikiPage $wiki_page The wiki page, has ->title and ->body * @param WikiPage|null $nav_page A wiki page object with navigation, has ->body */ - public function display_page(Page $page, WikiPage $wiki_page, $nav_page) { + public function display_page(Page $page, WikiPage $wiki_page, WikiPage $nav_page=null) { global $user; if(is_null($nav_page)) { diff --git a/ext/word_filter/main.php b/ext/word_filter/main.php index 9a12b4fa..e0002543 100644 --- a/ext/word_filter/main.php +++ b/ext/word_filter/main.php @@ -9,7 +9,7 @@ class WordFilter extends Extension { // before emoticon filter - public function get_priority() {return 40;} + public function get_priority(): int {return 40;} public function onTextFormatting(TextFormattingEvent $event) { $event->formatted = $this->filter($event->formatted); @@ -27,7 +27,7 @@ class WordFilter extends Extension { * @param string $text * @return string */ - private function filter(/*string*/ $text) { + private function filter(string $text) { $map = $this->get_map(); foreach($map as $search => $replace) { $search = trim($search); diff --git a/install.php b/install.php index 1efe82ac..8584a9ac 100644 --- a/install.php +++ b/install.php @@ -114,10 +114,7 @@ do_install(); // utilities {{{ // TODO: Can some of these be pushed into "core/util.inc.php" ? -/** - * @return int - */ -function check_gd_version() { +function check_gd_version(): int { $gdversion = 0; if (function_exists('gd_info')){ @@ -132,10 +129,7 @@ function check_gd_version() { return $gdversion; } -/** - * @return int - */ -function check_im_version() { +function check_im_version(): int { $convert_check = exec("convert"); return (empty($convert_check) ? 0 : 1); @@ -475,13 +469,7 @@ EOD; echo "\n"; } // }}} -/** - * @param boolean $isPDO - * @param string $errorMessage1 - * @param string $errorMessage2 - * @param integer $exitCode - */ -function handle_db_errors(/*bool*/ $isPDO, /*str*/ $errorMessage1, /*str*/ $errorMessage2, /*int*/ $exitCode) { +function handle_db_errors(bool $isPDO, string $errorMessage1, string $errorMessage2, int $exitCode) { $errorMessage1Extra = ($isPDO ? "Please check and ensure that the database configuration options are all correct." : "Please check the server log files for more information."); print << diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 2ea48b43..cb44abf5 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -66,25 +66,22 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase { } // page things - protected function assert_title($title) { + protected function assert_title(string $title) { global $page; $this->assertContains($title, $page->title); } - protected function assert_no_title($title) { + protected function assert_no_title(string $title) { global $page; $this->assertNotContains($title, $page->title); } - /** - * @param integer $code - */ - protected function assert_response($code) { + protected function assert_response(int $code) { global $page; $this->assertEquals($code, $page->code); } - protected function page_to_text($section=null) { + protected function page_to_text(string $section=null) { global $page; $text = $page->title . "\n"; foreach($page->blocks as $block) { @@ -96,29 +93,20 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase { return $text; } - protected function assert_text($text, $section=null) { + protected function assert_text(string $text, string $section=null) { $this->assertContains($text, $this->page_to_text($section)); } - /** - * @param string $text - */ - protected function assert_no_text($text, $section=null) { + protected function assert_no_text(string $text, string $section=null) { $this->assertNotContains($text, $this->page_to_text($section)); } - /** - * @param string $content - */ - protected function assert_content($content) { + protected function assert_content(string $content) { global $page; $this->assertContains($content, $page->data); } - /** - * @param string $content - */ - protected function assert_no_content($content) { + protected function assert_no_content(string $content) { global $page; $this->assertNotContains($content, $page->data); } @@ -143,12 +131,7 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase { } // post things - /** - * @param string $filename - * @param string $tags - * @return int - */ - protected function post_image($filename, $tags) { + protected function post_image(string $filename, string $tags): int { $dae = new DataUploadEvent($filename, array( "filename" => $filename, "extension" => pathinfo($filename, PATHINFO_EXTENSION), @@ -160,10 +143,7 @@ abstract class ShimmiePHPUnitTestCase extends \PHPUnit\Framework\TestCase { return $dae->image_id; } - /** - * @param int $image_id - */ - protected function delete_image($image_id) { + protected function delete_image(int $image_id) { $img = Image::by_id($image_id); if($img) { $ide = new ImageDeletionEvent($img); diff --git a/themes/danbooru2/ext_manager.theme.php b/themes/danbooru2/ext_manager.theme.php index 86afd724..bb486025 100644 --- a/themes/danbooru2/ext_manager.theme.php +++ b/themes/danbooru2/ext_manager.theme.php @@ -6,7 +6,7 @@ class CustomExtManagerTheme extends ExtManagerTheme { * @param array $extensions * @param bool $editable */ - public function display_table(Page $page, /*array*/ $extensions, /*bool*/ $editable) { + public function display_table(Page $page, array $extensions, bool $editable) { $page->disable_left(); parent::display_table($page, $extensions, $editable); } diff --git a/themes/material/home.theme.php b/themes/material/home.theme.php index b8d050b8..8c7f7a7c 100644 --- a/themes/material/home.theme.php +++ b/themes/material/home.theme.php @@ -25,7 +25,7 @@ EOD ); } - public function build_body(/*string*/ $sitename, /*string*/ $main_links, /*string*/ $main_text, /*string*/ $contact_link, $num_comma, /*string*/ $counter_text) { + public function build_body(string $sitename, string $main_links, string $main_text, string $contact_link, $num_comma, string $counter_text) { $message_html = empty($main_text) ? "" : "
$main_text
"; $counter_html = empty($counter_text) ? "" : "
$counter_text
"; $contact_link = empty($contact_link) ? "" : "
Contact -";