diff --git a/app/class/Controllerpage.php b/app/class/Controllerpage.php index 2584f26f..85b681a3 100644 --- a/app/class/Controllerpage.php +++ b/app/class/Controllerpage.php @@ -8,9 +8,8 @@ class Controllerpage extends Controller { - /** @var Page */ - protected $page; - protected $mediamanager; + protected Page $page; + protected Modelmedia $mediamanager; public function __construct($router) { @@ -19,7 +18,7 @@ public function __construct($router) $this->mediamanager = new Modelmedia(); } - public function setpage(string $id, string $route) + protected function setpage(string $id, string $route): void { $cleanid = Model::idclean($id); if ($cleanid !== $id) { @@ -38,7 +37,7 @@ public function setpage(string $id, string $route) * * @return bool If a page is found and stored in `$this->page` */ - public function importpage(): bool + protected function importpage(): bool { try { if (isset($_SESSION['pageupdate']['id']) && $_SESSION['pageupdate']['id'] == $this->page->id()) { @@ -61,7 +60,7 @@ public function importpage(): bool * @param string $route direction to redirect after the connection form * @return void */ - public function pageconnect(string $route) + protected function pageconnect(string $route): void { if ($this->user->isvisitor()) { http_response_code(401); @@ -70,7 +69,7 @@ public function pageconnect(string $route) } } - public function render($page) + public function render(string $page): void { $this->setpage($page, 'pageupdate'); @@ -88,7 +87,7 @@ public function render($page) * * @param string[] $relatedpages List of page ids */ - public function deletelinktocache(array $relatedpages): void + protected function deletelinktocache(array $relatedpages): void { foreach ($relatedpages as $pageid) { try { @@ -106,7 +105,7 @@ public function deletelinktocache(array $relatedpages): void * * @todo Move this function in Modelpage */ - private function templaterender(Page $page) + private function templaterender(Page $page): void { try { $templates = $this->pagemanager->getpagecsstemplates($page); @@ -135,11 +134,10 @@ private function templaterender(Page $page) /** * @param string $page page ID */ - public function read($page) + public function read(string $page): void { $this->setpage($page, 'pageread'); $filedir = Model::HTML_RENDER_DIR . $page . '.html'; - $reccursiverender = false; if (!$this->importpage()) { http_response_code(404); @@ -222,7 +220,7 @@ public function read($page) $this->pagemanager->update($this->page); } - public function edit($page) + public function edit(string $page): void { $this->setpage($page, 'pageedit'); @@ -256,7 +254,10 @@ public function edit($page) } } - public function log($page) + /** + * Print page's datas. Used for debug. Kind of obscure nowdays. + */ + public function log($page): void { if ($this->user->issupereditor()) { $this->setpage($page, 'pagelog'); @@ -269,7 +270,7 @@ public function log($page) } } - public function add($page) + public function add(string $page): void { $this->setpage($page, 'pageadd'); @@ -290,7 +291,7 @@ public function add($page) } } - public function addascopy(string $page, string $copy) + public function addascopy(string $page, string $copy): void { $page = Model::idclean($page); if ($this->copy($copy, $page)) { @@ -334,7 +335,7 @@ public function download($page) /** * Import page and save it into the database */ - public function upload() + public function upload(): void { $page = $this->pagemanager->getfromfile(); @@ -366,7 +367,7 @@ public function upload() $this->routedirect('home'); } - public function logout(string $page) + public function logout(string $page): void { if (!$this->user->isvisitor()) { $this->disconnect(); @@ -376,7 +377,7 @@ public function logout(string $page) } } - public function login(string $page) + public function login(string $page): void { if ($this->user->isvisitor()) { $this->showtemplate('connect', ['id' => $page, 'route' => 'pageread']); @@ -385,7 +386,7 @@ public function login(string $page) } } - public function delete($page) + public function delete(string $page): void { $this->setpage($page, 'pagecdelete'); if ($this->importpage() && $this->candelete($this->page)) { @@ -402,7 +403,7 @@ public function delete($page) } } - public function confirmdelete($page) + public function confirmdelete(string $page): void { $this->setpage($page, 'pageconfirmdelete'); if ($this->user->iseditor() && $this->importpage()) { @@ -414,7 +415,7 @@ public function confirmdelete($page) } } - public function duplicate(string $page, string $duplicate) + public function duplicate(string $page, string $duplicate): void { $duplicate = Model::idclean($duplicate); if ($this->copy($page, $duplicate)) { @@ -430,7 +431,7 @@ public function duplicate(string $page, string $duplicate) * @param string $srcid Source page ID * @param string $targetid Target page ID */ - public function copy(string $srcid, string $targetid) + protected function copy(string $srcid, string $targetid): bool { if ($this->user->iseditor()) { try { @@ -451,7 +452,7 @@ public function copy(string $srcid, string $targetid) return false; } - public function update($page) + public function update(string $page): void { $this->setpage($page, 'pageupdate'); @@ -482,20 +483,13 @@ public function update($page) $this->routedirect('pageedit', ['page' => $this->page->id()]); } - /** - * Temporary redirection to a page. - * Send a `302` HTTP code. - */ - public function pagedirect($page): void - { - $this->routedirect('pageread', ['page' => Model::idclean($page)]); - } - /** * Permanent redirection to a page. * Send a `301` HTTP code. + * + * Used only with Route `pageread/` redirecting to `pageread` */ - public function pagepermanentredirect($page): void + public function pagepermanentredirect(string $page): void { $path = $this->generate('pageread', ['page' => Model::idclean($page)]); header("Location: $path", true, 301); @@ -506,7 +500,7 @@ public function pagepermanentredirect($page): void * * @todo use a dedicated view and suggest a list of W URL based command. */ - public function commandnotfound($page, $command): void + public function commandnotfound(string $page, string $command): void { http_response_code(404); $this->showtemplate('alertcommandnotfound', ['command' => $command, 'id' => strip_tags($page)]); diff --git a/app/class/Element.php b/app/class/Element.php index fc84fba6..b621bb80 100644 --- a/app/class/Element.php +++ b/app/class/Element.php @@ -17,14 +17,14 @@ abstract class Element extends Item protected $headerid = '1-6'; /** @var bool default value is set in Config class */ protected bool $urllinker; - protected int $headeranchor = self::NOHEADERANCHOR; + protected int $headeranchor = self::NO_HEADER_ANCHOR; - public const NOHEADERANCHOR = 0; - public const HEADERANCHORLINK = 1; - public const HEADERANCHORHASH = 2; - public const HEADERANCHORMODES = [ - self::NOHEADERANCHOR, self::HEADERANCHORLINK, self::HEADERANCHORHASH + public const NO_HEADER_ANCHOR = 0; + public const HEADER_ANCHOR_LINK = 1; + public const HEADER_ANCHOR_HASH = 2; + public const HEADER_ANCHOR_MODES = [ + self::NO_HEADER_ANCHOR, self::HEADER_ANCHOR_LINK, self::HEADER_ANCHOR_HASH ]; // ______________________________________________ F U N ________________________________________________________ @@ -140,7 +140,7 @@ public function setheaderid(string $headerid) public function setheaderanchor($headeranchor) { - if (in_array($headeranchor, self::HEADERANCHORMODES)) { + if (in_array($headeranchor, self::HEADER_ANCHOR_MODES)) { $this->headeranchor = (int) $headeranchor; } } diff --git a/app/class/Font.php b/app/class/Font.php index 676db941..b19c1b08 100644 --- a/app/class/Font.php +++ b/app/class/Font.php @@ -17,7 +17,7 @@ class Font protected ?string $weight = null; protected ?string $stretch = null; - /** @var Media[] $media */ + /** @var Media[] $medias */ protected array $medias; public const STYLE = "style"; diff --git a/app/class/Modelbookmark.php b/app/class/Modelbookmark.php index 0f5833c4..96946455 100644 --- a/app/class/Modelbookmark.php +++ b/app/class/Modelbookmark.php @@ -128,7 +128,7 @@ public function exist($id): bool * @throws Databaseexception When ID is invalid, already exist or creation failed * @throws Notfoundexception If personnal bookmark User does not exist */ - public function add(Bookmark $bookmark) + public function add(Bookmark $bookmark): void { if (empty($bookmark->id())) { $id = $bookmark->id(); diff --git a/app/class/Modelconnect.php b/app/class/Modelconnect.php index 3494d1ba..cffe87e5 100644 --- a/app/class/Modelconnect.php +++ b/app/class/Modelconnect.php @@ -14,7 +14,7 @@ class Modelconnect extends Model * @param int $conservation * @throws RuntimeException if secret key is not set or cant send cookie */ - public function createauthcookie(string $userid, string $wsession, int $conservation) + public function createauthcookie(string $userid, string $wsession, int $conservation): void { $datas = [ "userid" => $userid, @@ -40,7 +40,7 @@ public function createauthcookie(string $userid, string $wsession, int $conserva /** * Get decoded cookie using JWT - * @return array Associative array containing JWT token's datas + * @return string[] Associative array containing JWT token's datas * @throws RuntimeException If JWT token decode failed or auth cookie is unset */ public function checkcookie(): array diff --git a/app/class/Modeldb.php b/app/class/Modeldb.php index 51413494..a8c22998 100644 --- a/app/class/Modeldb.php +++ b/app/class/Modeldb.php @@ -3,7 +3,7 @@ namespace Wcms; use InvalidArgumentException; -use JamesMoss\Flywheel; +use JamesMoss\Flywheel\Config; use JamesMoss\Flywheel\DocumentInterface; use JamesMoss\Flywheel\Document; use RuntimeException; @@ -13,9 +13,9 @@ class Modeldb extends Model { - protected $database; + protected Config $database; /** @var Repository */ - protected $repo; + protected Repository $repo; /** * Minimal disk space needed to authorize database writing. @@ -76,14 +76,24 @@ protected function updatedoc(DocumentInterface $document): bool return $this->repo->update($document); } - protected function dbinit($dir = Model::DATABASE_DIR) + /** + * Init database config + * + * @param string $dir Directory where repo is stored. + */ + protected function dbinit(string $dir = Model::DATABASE_DIR): void { - $this->database = new Flywheel\Config($dir, [ + $this->database = new Config($dir, [ 'query_class' => Query::class, 'formatter' => new JSON(), ]); } + /** + * Init store. + * + * @param string $repo Name of the repo + */ protected function storeinit(string $repo): void { try { diff --git a/app/class/Modelhome.php b/app/class/Modelhome.php index 1b779f98..5e531d02 100644 --- a/app/class/Modelhome.php +++ b/app/class/Modelhome.php @@ -17,12 +17,12 @@ class Modelhome extends Model /** * Transform list of page into list of nodes and edges * - * @param array $pagelist associative array of pages as `id => Page` + * @param Page[] $pagelist associative array of pages as `id => Page` * @param string $layout * @param bool $showorphans if `false`, remove orphans pages * @param bool $showredirection if `true`, add redirections * - * @return array + * @return array[] */ public function cytodata( array $pagelist, @@ -100,11 +100,11 @@ public function cytodata( /** * Transform list of Pages into cytoscape nodes and edge datas * - * @param array $pagelist associative array of pages as `id => Page` + * @param Page[] $pagelist associative array of pages as `id => Page` * @param bool $showorphans if `false`, remove orphans pages * @param bool $showredirection if `true`, add redirections * - * @return array of cytoscape datas + * @return array[] of cytoscape datas */ public function mapdata(array $pagelist, bool $showorphans = true, bool $showredirection = false): array { diff --git a/app/class/Modelmedia.php b/app/class/Modelmedia.php index 71409865..164fdbde 100644 --- a/app/class/Modelmedia.php +++ b/app/class/Modelmedia.php @@ -87,9 +87,9 @@ protected function getlistermedia(Mediaopt $mediaopt): array /** * Sort an array of media * - * @param array $medialist + * @param Media[] $medialist * @param string $sortby - * @param int $order Can be 1 or -1 + * @param int $order Can be 1 or -1 */ protected function medialistsort(array &$medialist, string $sortby = 'id', int $order = 1): bool { @@ -98,7 +98,7 @@ protected function medialistsort(array &$medialist, string $sortby = 'id', int $ return usort($medialist, $this->buildsorter($sortby, $order)); } - protected function buildsorter($sortby, $order) + protected function buildsorter(string $sortby, int $order): callable { return function ($media1, $media2) use ($sortby, $order) { $result = $this->mediacompare($media1, $media2, $sortby, $order); @@ -106,7 +106,7 @@ protected function buildsorter($sortby, $order) }; } - protected function mediacompare($media1, $media2, $method = 'filename', $order = 1) + protected function mediacompare(Media $media1, Media $media2, string $method = 'filename', int $order = 1) { $result = ($media1->$method() <=> $media2->$method()); return $result * $order; @@ -115,14 +115,19 @@ protected function mediacompare($media1, $media2, $method = 'filename', $order = - - public function listfavicon() + /** + * @return string[] + */ + public function listfavicon(): array { $faviconlist = $this->globlist(self::FAVICON_DIR, ['ico', 'png', 'jpg', 'jpeg', 'gif']); return $faviconlist; } - public function listthumbnail() + /** + * @return string[] + */ + public function listthumbnail(): array { $faviconlist = $this->globlist(self::THUMBNAIL_DIR, ['ico', 'png', 'jpg', 'jpeg', 'gif']); return $faviconlist; @@ -159,6 +164,8 @@ public function globlist(string $dir = '', array $extensions = []): array /** * Generate an recursive array where each folder is a array and containing a filecount in each folder + * + * @return array[] */ public function listdir(string $dir): array { @@ -182,7 +189,7 @@ public function listdir(string $dir): array /** * Analyse recursive array of content to generate list of path * - * @param array $dirlist Array generated by the listdir function + * @param array[] $dirlist Array generated by the listdir function * @param string $parent used to create the strings * @param array $pathlist used by reference, must be an empty array */ @@ -343,7 +350,7 @@ public function deletedir(string $dir): bool } /** - * Function do recursively delete a directory + * Function to recursively delete a directory */ public function deltree(string $dir) { @@ -375,6 +382,7 @@ public function multifiledelete(array $files): int Fs::deletefile($filedir); $counter++; } catch (Filesystemexception $e) { + Logger::errorex($e); } } else { throw new InvalidArgumentException('$files argument should be an array containing strings'); @@ -433,6 +441,8 @@ public function multimovefile(array $filedirlist, string $dir): bool * @param string $newname * * @throws Filesystemexception if cant access file + * + * @todo Use a Media as input */ public function rename(string $oldname, string $newname) { @@ -463,7 +473,7 @@ public function rename(string $oldname, string $newname) * * @return Media Converted Media object * - * @throws RuntimeException If imagick is not installed + * @throws RuntimeException If nor imagick or is installed * @throws ImagickException If an error occured during IM process * @throws Filesystemexception If deleting the original media failed, or if file creation failed. */ diff --git a/app/class/Modelpage.php b/app/class/Modelpage.php index 06d13e4b..2daa1c04 100644 --- a/app/class/Modelpage.php +++ b/app/class/Modelpage.php @@ -21,7 +21,8 @@ class Modelpage extends Modeldb 2 => 'not_published' ]; - protected $pagelist = []; + /** @var Page[] $pagelist */ + protected array $pagelist = []; public function __construct(string $pagetable, string $pagedir = self::PAGES_DIR) { @@ -291,7 +292,7 @@ public function delete(Page $page): bool * * @throws Filesystemexception If a file deletion failure occurs */ - public function unlink(string $pageid) + public function unlink(string $pageid): void { $files = ['.css', '.quick.css', '.js']; foreach ($files as $file) { @@ -345,14 +346,14 @@ public function update(Page $page) * Edit a page based on meta infos * * @param string $pageid - * @param array $datas - * @param array $reset + * @param mixed[] $datas + * @param string[] $reset * @param string $addtag * @param string $addauthor * * @throws RuntimeException When page is not found in the database or update failed */ - public function pageedit(string $pageid, array $datas, array $reset, string $addtag, string $addauthor) + public function pageedit(string $pageid, array $datas, array $reset, string $addtag, string $addauthor): void { $page = $this->get($pageid); $page = $this->reset($page, $reset); @@ -368,11 +369,11 @@ public function pageedit(string $pageid, array $datas, array $reset, string $add * Reset values of a page * * @param Page $page Page object to be reseted - * @param array $reset List of parameters needing reset + * @param string[] $reset List of parameters needing reset * * @return Page The reseted page object */ - public function reset(Page $page, array $reset): Page + protected function reset(Page $page, array $reset): Page { $now = new DateTimeImmutable("now", timezone_open("Europe/Paris")); if (boolval($reset['tag'])) { @@ -490,7 +491,7 @@ public function renderpage(Page $page, AltoRouter $router): Page * @param Opt $opt * * @param string $regex Regex to match. - * @param array $searchopt Option search, could be `content` `title` `description`. + * @param string[] $searchopt Option search, could be `content` `title` `description`. * * @return Page[] associative array of `Page` objects */ @@ -563,14 +564,16 @@ protected function sort(array $pagelist, Opt $opt): array return $pagelist; } - - protected function pagecompare($page1, $page2, $method = 'id', $order = 1) + /** + * @todo It can go in great-parent class Model to be used as well by Modelmedia. Using Item instead of Page + */ + protected function pagecompare(Page $page1, Page $page2, $method = 'id', $order = 1): int { $result = ($page1->$method('sort') <=> $page2->$method('sort')); return $result * $order; } - protected function buildsorter($sortby, $order) + protected function buildsorter(string $sortby, int $order): callable { return function ($page1, $page2) use ($sortby, $order) { $result = $this->pagecompare($page1, $page2, $sortby, $order); @@ -579,8 +582,12 @@ protected function buildsorter($sortby, $order) } - - protected function pagelistsort(&$pagelist, $sortby, $order = 1) + /** + * @param Page[] $pagelist + * + * @todo remove this method and put the content inside sort() method + */ + protected function pagelistsort(array &$pagelist, string $sortby, $order = 1): bool { return uasort($pagelist, $this->buildsorter($sortby, $order)); } @@ -729,7 +736,7 @@ protected function fgeo(Page $page, bool $geo) } } - protected function fversion(Page $page, int $version) + protected function fversion(Page $page, int $version): bool { if ($version === 0) { return true; @@ -746,7 +753,7 @@ protected function fversion(Page $page, int $version) * @param string $regex Regex to match. * @param string[] $options Option search, could be `content` `title` `description`. * - * @return array associative array of `Page` objects + * @return Page[] associative array of `Page` objects */ protected function deepsearch(array $pagelist, string $regex, array $options): array { diff --git a/app/class/Servicerender.php b/app/class/Servicerender.php index c377a038..585bf1fd 100644 --- a/app/class/Servicerender.php +++ b/app/class/Servicerender.php @@ -531,11 +531,11 @@ function ($matches) use ($element, $anchormode) { } $this->sum[$element][] = new Header($id, intval($level), $content); switch ($anchormode) { - case Element::HEADERANCHORLINK: + case Element::HEADER_ANCHOR_LINK: $content = "$content"; break; - case Element::HEADERANCHORHASH: + case Element::HEADER_ANCHOR_HASH: $content .= " #"; break; } diff --git a/app/class/User.php b/app/class/User.php index aeb5499f..34478c87 100644 --- a/app/class/User.php +++ b/app/class/User.php @@ -8,17 +8,17 @@ class User extends Item { - protected $id = ''; - protected $level = 0; - protected $signature = ''; - protected $password; - protected $passwordhashed = false; + protected string $id = ''; + protected int $level = 0; + protected string $signature = ''; + protected ?string $password; + protected bool $passwordhashed = false; /** @var string $name Displayed name */ - protected string $name = ""; + protected string $name = ''; /** @var string $url Account associated URL */ - protected string $url = ""; + protected string $url = ''; /** @var int $cookie Conservation time */ protected int $cookie = 30; @@ -29,15 +29,16 @@ class User extends Item /** @var int $connectcount Connections counter */ protected int $connectcount = 0; - protected $expiredate = false; + /** @var DateTimeImmutable|false $expiredate */ + protected mixed $expiredate = false; - /** @var array sessions */ + /** @var string[] sessions */ protected array $sessions = []; /** @var bool[] $display interface display options */ protected array $display = ['bookmark' => false]; - public const COLUMNS = [ + public const HOME_COLUMNS = [ 'favicon', 'download', 'tag', @@ -59,9 +60,7 @@ class User extends Item public function __construct($datas = []) { - if (!empty($datas)) { - $this->hydrate($datas); - } + $this->hydrate($datas); } // _________________________ G E T _______________________ @@ -234,7 +233,7 @@ public function setcookie($cookie) public function setcolumns($columns) { if (is_array($columns)) { - $columns = array_filter(array_intersect(array_unique($columns), self::COLUMNS)); + $columns = array_filter(array_intersect(array_unique($columns), self::HOME_COLUMNS)); $this->columns = $columns; } } @@ -364,7 +363,7 @@ public function checksession(string $session): bool */ public function checkedcolumns(): array { - foreach (self::COLUMNS as $col) { + foreach (self::HOME_COLUMNS as $col) { $checkedcolumns[$col] = in_array($col, $this->columns); } return $checkedcolumns; diff --git a/app/class/Workspace.php b/app/class/Workspace.php index fc2f1d94..d5c9d76b 100644 --- a/app/class/Workspace.php +++ b/app/class/Workspace.php @@ -23,6 +23,9 @@ class Workspace extends Item public const THEME_NONE = 'none'; public const THEMES = [self::THEME_DEFAULT, self::THEME_MONOKAI, self::THEME_NONE]; + /** + * @param mixed[] $datas + */ public function __construct(array $datas) { $this->hydrate($datas); @@ -58,22 +61,22 @@ public function highlighttheme(): string return $this->highlighttheme; } - public function setshoweditorleftpanel($show) + public function setshoweditorleftpanel(mixed $show): void { $this->showeditorleftpanel = boolval($show); } - public function setshoweditorrightpanel($show) + public function setshoweditorrightpanel(mixed $show): void { $this->showeditorrightpanel = boolval($show); } - public function setshoweoptionspanel($show) + public function setshoweoptionspanel(mixed $show): void { $this->showeoptionspanel = boolval($show); } - public function setfontsize($fontsize) + public function setfontsize(mixed $fontsize): void { $fontsize = intval($fontsize); if ($fontsize >= self::FONTSIZE_MIN && $fontsize <= self::FONTSIZE_MAX) { @@ -81,14 +84,14 @@ public function setfontsize($fontsize) } } - public function setmediadisplay($mediadisplay) + public function setmediadisplay(string $mediadisplay): void { if (in_array($mediadisplay, self::MEDIA_DISPLAY)) { $this->mediadisplay = $mediadisplay; } } - public function sethighlighttheme(string $theme) + public function sethighlighttheme(string $theme): void { if (in_array($theme, self::THEMES)) { $this->highlighttheme = $theme; diff --git a/app/fn/fn.php b/app/fn/fn.php index 1fbd6caa..3c4eea4d 100644 --- a/app/fn/fn.php +++ b/app/fn/fn.php @@ -2,7 +2,7 @@ use Wcms\Exception\Filesystemexception\Folderexception; -function readablesize($bytes, $base = 2 ** 10) +function readablesize(float $bytes, int $base = 2 ** 10): string { $format = '%d %s'; @@ -30,11 +30,13 @@ function readablesize($bytes, $base = 2 ** 10) return sprintf($format, $num, $unit); } -/* human readable date interval - * @param DateInterval $diff - l'interval de temps +/** + * Human readable date interval + * + * @param DateInterval $diff * @return string */ -function hrdi(DateInterval $diff) +function hrdi(DateInterval $diff): string { $str = ""; if ($diff->y > 1) { @@ -70,22 +72,10 @@ function hrdi(DateInterval $diff) return $str . ' a few secondes'; } - - -function arrayclean($input) -{ - $output = []; - foreach ($input as $key => $value) { - if (is_array($value)) { - $output[$key] = array_filter($value); - } else { - $output[$key] = $value; - } - } - return $output; -} - -function isreportingerrors() +/** + * Check if Sentry service is enabled + */ +function isreportingerrors(): bool { return function_exists('Sentry\init') && !empty(Wcms\Config::sentrydsn()); } @@ -105,58 +95,12 @@ function getversion(): string return $version; } - - -function array_update($base, $new) -{ - foreach ($base as $key => $value) { - if (array_key_exists($key, $new)) { - if (gettype($base[$key]) == gettype($new[$key])) { - $base[$key] = $new[$key]; - } - } - } - return $base; -} - -function contains($needle, $haystack) -{ - return strpos($haystack, $needle) !== false; -} - - -function str_clean(string $string) -{ - return str_replace(' ', '_', strtolower(strip_tags($string))); -} - - - - -function changekey($array, $oldkey, $newkey) -{ - if (!array_key_exists($oldkey, $array)) { - return $array; - } - - $keys = array_keys($array); - $keys[array_search($oldkey, $keys)] = $newkey; - - return array_combine($keys, $array); -} - -function findsize($file) -{ - if (mb_substr(PHP_OS, 0, 3) == "WIN") { - exec('for %I in ("' . $file . '") do @echo %~zI', $output); - $return = $output[0]; - } else { - $return = filesize($file); - } - return $return; -} - -function array_diff_assoc_recursive($array1, $array2) +/** + * @param mixed[] $array1 + * @param mixed[] $array2 + * @return mixed[] + */ +function array_diff_assoc_recursive(array $array1, array $array2): array { $difference = array(); foreach ($array1 as $key => $value) { @@ -179,9 +123,11 @@ function array_diff_assoc_recursive($array1, $array2) /** - * Generate a clickable folder tree based on reccurive array + * Print a clickable folder tree based on reccurive array + * + * @param mixed[] $dirlist */ -function basictree(array $dirlist, string $dirname, int $deepness, string $path, string $currentdir) +function basictree(array $dirlist, string $dirname, int $deepness, string $path, string $currentdir): void { if ($path === $currentdir) { @@ -211,7 +157,13 @@ function basictree(array $dirlist, string $dirname, int $deepness, string $path, } } -function checkboxes(string $name, array $optionlist = [], array $checkedlist = []) +/** + * Generate a HTML list of checkboxes that have the same name and use array storing + * + * @param string[] $optionlist checkbox values + * @param string[] $checkedlist checkboxes that are checked + */ +function checkboxes(string $name, array $optionlist = [], array $checkedlist = []): string { $checkboxes = ''; foreach ($optionlist as $option) { @@ -228,11 +180,11 @@ function checkboxes(string $name, array $optionlist = [], array $checkedlist = [ /** * Generate a list of html drop down list * - * @param array $options as `value => title` - * @param string|int $selected value of actualy selected option - * @param bool $simple Use title as value. Default : false + * @param string[] $options as `value => title` + * @param string|int $selected value of currently selected option + * @param bool $simple Use title as value. Default : `false` * - * @return string HTML list of options + * @return string HTML list of options */ function options(array $options, $selected = null, $simple = false): string { @@ -263,7 +215,7 @@ function secrethash(string $token): string // Returns a file size limit in bytes based on the PHP upload_max_filesize // and post_max_size -function file_upload_max_size() +function file_upload_max_size(): float { static $max_size = -1; @@ -284,7 +236,7 @@ function file_upload_max_size() return $max_size; } -function parse_size($size) +function parse_size(string $size): float { $unit = preg_replace('/[^bkmgtpezy]/i', '', $size); // Remove the non-unit characters from the size. $size = preg_replace('/[^0-9\.]/', '', $size); // Remove the non-numeric characters from the size. @@ -317,9 +269,10 @@ function randombytes(int $seed): string /** * @param string $url + * @return string output data + * * @throws ErrorException if Curl is not installed * @throws RuntimeException if curl_exec fail - * @return string output data */ function curl_download(string $url): string { diff --git a/app/view/templates/homemenu.php b/app/view/templates/homemenu.php index 9589c6b7..6ba50cc6 100644 --- a/app/view/templates/homemenu.php +++ b/app/view/templates/homemenu.php @@ -433,7 +433,7 @@
  • diff --git a/tests/Servicerenderv1Test.php b/tests/Servicerenderv1Test.php index c7cea782..08d67cb8 100644 --- a/tests/Servicerenderv1Test.php +++ b/tests/Servicerenderv1Test.php @@ -69,6 +69,9 @@ public function renderTestCommon(string $name): void $this->renderTest($name); } + /** + * @return array[] + */ public function renderProvider(): array { return [ diff --git a/tests/Servicerenderv2Test.php b/tests/Servicerenderv2Test.php index e3292b25..4aaef438 100644 --- a/tests/Servicerenderv2Test.php +++ b/tests/Servicerenderv2Test.php @@ -69,6 +69,9 @@ public function renderTestCommon(string $name): void $this->renderTest($name); } + /** + * @return array[] + */ public function renderProvider(): array { return [ diff --git a/tests/SummaryTest.php b/tests/SummaryTest.php index a2ae84c6..dd52aff4 100644 --- a/tests/SummaryTest.php +++ b/tests/SummaryTest.php @@ -18,6 +18,9 @@ public function sumparserTest(array $options, string $expected): void $this->assertEquals($expected, $summary->sumparser()); } + /** + * @return array[] + */ public function sumparserProvider(): array { return [