Skip to content

Commit

Permalink
autumn cleaning: fix typos and upgrade type hints
Browse files Browse the repository at this point in the history
+ removed multiple old unused functions in fn.php
  • Loading branch information
vincent-peugnet committed Oct 16, 2024
1 parent 6abf8d6 commit 2d5c8d1
Show file tree
Hide file tree
Showing 17 changed files with 170 additions and 185 deletions.
62 changes: 28 additions & 34 deletions app/class/Controllerpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

class Controllerpage extends Controller
{
/** @var Page */
protected $page;
protected $mediamanager;
protected Page $page;
protected Modelmedia $mediamanager;

public function __construct($router)
{
Expand All @@ -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) {
Expand All @@ -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()) {
Expand All @@ -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);
Expand All @@ -70,7 +69,7 @@ public function pageconnect(string $route)
}
}

public function render($page)
public function render(string $page): void
{
$this->setpage($page, 'pageupdate');

Expand All @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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');
Expand All @@ -269,7 +270,7 @@ public function log($page)
}
}

public function add($page)
public function add(string $page): void
{
$this->setpage($page, 'pageadd');

Expand All @@ -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)) {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand All @@ -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']);
Expand All @@ -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)) {
Expand All @@ -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()) {
Expand All @@ -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)) {
Expand All @@ -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 {
Expand All @@ -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');

Expand Down Expand Up @@ -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);
Expand All @@ -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)]);
Expand Down
14 changes: 7 additions & 7 deletions app/class/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ________________________________________________________
Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/class/Font.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion app/class/Modelbookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions app/class/Modelconnect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
20 changes: 15 additions & 5 deletions app/class/Modeldb.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions app/class/Modelhome.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
{
Expand Down
Loading

0 comments on commit 2d5c8d1

Please sign in to comment.