From 6d3c5a68b98c9c36e119cd7a10192252d58607b7 Mon Sep 17 00:00:00 2001 From: Banana Date: Sat, 9 Oct 2021 10:32:32 +0200 Subject: [PATCH] some php syntax stuff --- CHANGELOG | 1 + webroot/lib/entry.class.php | 20 ++++---- webroot/lib/summoner.class.php | 92 +++++++++++++++++----------------- webroot/view/entry/entry.php | 18 +++++++ webroot/view/list/list.php | 19 +++++++ 5 files changed, 94 insertions(+), 56 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index bd7f602..c43ba02 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,2 +1,3 @@ 0.5 Lykos - + Initial beta release + + Some PHP syntax stuff diff --git a/webroot/lib/entry.class.php b/webroot/lib/entry.class.php index e00502a..7661dfd 100644 --- a/webroot/lib/entry.class.php +++ b/webroot/lib/entry.class.php @@ -36,7 +36,7 @@ class Entry { * * @param mysqli $db */ - public function __construct($db) { + public function __construct(mysqli $db) { $this->_DB = $db; } @@ -47,7 +47,7 @@ class Entry { * @param string $data * @return mixed */ - public function create($data) { + public function create(string $data): bool { $ret = false; $_words = implode(' ', $this->_words($data)); @@ -78,9 +78,9 @@ class Entry { * @param string $m Month m * @param string $d Day d * @param string $id Id of the entry - * @return array|null + * @return array */ - public function load($y, $m, $d, $id) { + public function load(string $y, string $m, string $d, string $id): array { $ret = array(); if(!empty($id) && !empty($y) && !empty($m) && !empty($d)) { @@ -108,10 +108,10 @@ class Entry { * * @param array $data * @param string $id - * @return mixed + * @return int */ - public function update($data,$id) { - $ret = false; + public function update(array $data, string $id) { + $ret = 0; if(!empty($data) && !empty($id)) { $_words = implode(' ', $this->_words($data)); @@ -135,12 +135,12 @@ class Entry { /** * Create unique words from the given data * + * @param $data string + * @return array * @todo ignores * - * @param $data - * @return array */ - private function _words($data) { + private function _words(string $data): array { preg_match_all('/\w{3,}+/',$data,$matches); return array_unique($matches[0]); } diff --git a/webroot/lib/summoner.class.php b/webroot/lib/summoner.class.php index 9b1b810..a402f4b 100644 --- a/webroot/lib/summoner.class.php +++ b/webroot/lib/summoner.class.php @@ -24,24 +24,24 @@ * A static helper class */ class Summoner { - /** - * validate the given string with the given type. Optional check the string - * length - * - * @param string $input The string to check - * @param string $mode How the string should be checked - * @param mixed $limit If int given the string is checked for length - * - * @return bool - * - * @see http://de.php.net/manual/en/regexp.reference.unicode.php - * http://www.sql-und-xml.de/unicode-database/#pc - * - * the pattern replaces all that is allowed. the correct result after - * the replace should be empty, otherwise are there chars which are not - * allowed - */ - static function validate($input,$mode='text',$limit=false) { + /** + * validate the given string with the given type. Optional check the string + * length + * + * @param string $input The string to check + * @param string $mode How the string should be checked + * @param mixed $limit If int given the string is checked for length + * + * @return bool + * + * @see http://de.php.net/manual/en/regexp.reference.unicode.php + * http://www.sql-und-xml.de/unicode-database/#pc + * + * the pattern replaces all that is allowed. the correct result after + * the replace should be empty, otherwise are there chars which are not + * allowed + */ + static function validate(string $input, $mode='text', $limit=false): bool { // check if we have input $input = trim($input); @@ -119,26 +119,26 @@ class Summoner { return $ret; } - /** - * check if a string starts with a given string - * - * @param string $haystack - * @param string $needle - * @return boolean - */ - static function startsWith($haystack, $needle) { + /** + * check if a string starts with a given string + * + * @param string $haystack + * @param string $needle + * @return boolean + */ + static function startsWith(string $haystack, string $needle): bool { $length = strlen($needle); return (substr($haystack, 0, $length) === $needle); } - /** - * check if a string ends with a given string - * - * @param string $haystack - * @param string $needle - * @return boolean - */ - static function endsWith($haystack, $needle) { + /** + * check if a string ends with a given string + * + * @param string $haystack + * @param string $needle + * @return boolean + */ + static function endsWith(string $haystack, string $needle): bool { $length = strlen($needle); if ($length == 0) { return true; @@ -155,7 +155,7 @@ class Summoner { * @param int $id * @return string */ - static function b64sl_pack_id($id) { + static function b64sl_pack_id(int $id): string { error_log($id); $id = intval($id); $ida = ($id > 0xFFFFFFFF ? $id >> 32 : 0); // 32 bit big endian, top @@ -169,14 +169,14 @@ class Summoner { return $id; } - /** - * Decode a base64-encoded big-endian integer of up to 64 bits. - * - * @see https://www.jwz.org/base64-shortlinks/ - * @param int $id - * @return false|int|string|string[] - */ - static function b64sl_unpack_id($id) { + /** + * Decode a base64-encoded big-endian integer of up to 64 bits. + * + * @see https://www.jwz.org/base64-shortlinks/ + * @param int $id + * @return false|int|string|string[] + */ + static function b64sl_unpack_id(int $id) { $id = str_replace ('-', '+', $id); // decode URL-unsafe "+" "/" $id = str_replace ('_', '/', $id); $id = base64_decode ($id); @@ -193,11 +193,11 @@ class Summoner { * * http://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op * - * @param $array - * @param $key + * @param $array array + * @param $key string * @return bool|mixed */ - static function ifset($array,$key) { + static function ifset(array $array, string $key): bool { return isset($array[$key]) ? $array[$key] : false; } diff --git a/webroot/view/entry/entry.php b/webroot/view/entry/entry.php index a3ab775..a6636ba 100644 --- a/webroot/view/entry/entry.php +++ b/webroot/view/entry/entry.php @@ -1,4 +1,22 @@