Skip to content

Commit b901061

Browse files
add many type hints
1 parent 51ea6c1 commit b901061

24 files changed

+217
-161
lines changed

app/class/Application.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ public function __construct()
1717
$this->usermanager = new Modeluser();
1818
}
1919

20-
public function wakeup()
20+
public function wakeup(): void
2121
{
2222
if (isset($_POST['configinit'])) {
2323
if (Config::readconfig()) {
24-
Config::createconfig($_POST['configinit']);
24+
Config::hydrate($_POST['configinit']);
2525
} else {
2626
Config::hydrate($_POST['configinit']);
2727
}
@@ -91,7 +91,7 @@ public function wakeup()
9191
}
9292
}
9393

94-
protected function configform()
94+
protected function configform(): void
9595
{
9696
?>
9797
<h1>Configuration</h1>
@@ -172,7 +172,7 @@ protected function configform()
172172
<?php
173173
}
174174

175-
protected function adminform()
175+
protected function adminform(): void
176176
{
177177
?>
178178

@@ -207,7 +207,7 @@ protected function adminform()
207207
/**
208208
* Create default bookmarks set during install
209209
*/
210-
protected function defaultbookmarks()
210+
protected function defaultbookmarks(): void
211211
{
212212
$bookmarkmanager = new Modelbookmark();
213213
if (empty($bookmarkmanager->list())) {

app/class/Bookmark.php

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class Bookmark extends Item
3131
protected string $ref = "";
3232

3333
/**
34+
* @param object|array $datas
35+
*
3436
* @throws RuntimeException
3537
*/
3638
public function __construct($datas = [])
@@ -44,7 +46,7 @@ public function init(
4446
string $icon = '',
4547
string $name = '',
4648
string $description = ''
47-
) {
49+
): void {
4850
$this->setid($id);
4951
$this->setquery($query);
5052
$this->seticon($icon);
@@ -66,7 +68,7 @@ public function ispublished(): bool
6668
// _____________________________ G E T __________________________________
6769

6870

69-
public function id()
71+
public function id(): string
7072
{
7173
return $this->id;
7274
}
@@ -81,12 +83,12 @@ public function description(): string
8183
return $this->description;
8284
}
8385

84-
public function query()
86+
public function query(): string
8587
{
8688
return $this->query;
8789
}
8890

89-
public function icon()
91+
public function icon(): string
9092
{
9193
return $this->icon;
9294
}
@@ -140,30 +142,24 @@ public function setdescription(string $description): bool
140142
}
141143
}
142144

143-
public function setquery($query)
145+
public function setquery(string $query): void
144146
{
145-
if (is_string($query)) {
146-
$this->query = strip_tags(mb_substr($query, 0, Model::MAX_QUERY_LENGH));
147-
}
147+
$this->query = strip_tags(mb_substr($query, 0, Model::MAX_QUERY_LENGH));
148148
}
149149

150-
public function seticon($icon)
150+
public function seticon(string $icon): void
151151
{
152-
if (is_string($icon)) {
153-
$this->icon = mb_substr(strip_tags($icon), 0, 16);
154-
}
152+
$this->icon = mb_substr(strip_tags($icon), 0, 16);
155153
}
156154

157-
public function setuser($user)
155+
public function setuser(string $user): void
158156
{
159-
if (is_string($user)) {
160-
$this->user = Model::idclean($user);
161-
return true;
157+
if (Model::idcheck($user)) {
158+
$this->user = $user;
162159
}
163-
return false;
164160
}
165161

166-
public function setpublished(bool $published)
162+
public function setpublished(bool $published): void
167163
{
168164
$this->published = $published;
169165
}

app/class/Clock.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ public function setformat(string $format): void
159159
}
160160
}
161161

162-
public function setlang($lang)
162+
public function setlang(string $lang): void
163163
{
164-
if (is_string($lang) && strlen($lang) < Config::LANG_MAX && strlen($lang) >= Config::LANG_MIN) {
164+
if (strlen($lang) < Config::LANG_MAX && strlen($lang) >= Config::LANG_MIN) {
165165
$this->lang = $lang;
166166
}
167167
}

app/class/Config.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ abstract class Config
8181
// _______________________________________ F U N _______________________________________
8282

8383

84-
85-
public static function hydrate(array $datas): void
84+
/**
85+
* @param object|array $datas
86+
*/
87+
public static function hydrate($datas): void
8688
{
8789
foreach ($datas as $key => $value) {
8890
$method = 'set' . $key;
@@ -108,11 +110,6 @@ public static function readconfig(): bool
108110
}
109111
}
110112

111-
public static function createconfig(array $datas): void
112-
{
113-
self::hydrate($datas);
114-
}
115-
116113
/**
117114
* @throws Filesystemexception If file cant be saved
118115
*/
@@ -124,7 +121,7 @@ public static function savejson(): bool
124121
}
125122

126123

127-
public static function tojson(): string
124+
protected static function tojson(): string
128125
{
129126
$arr = get_class_vars(get_class());
130127
// get_class_vars returns default values, we need to update each of them with the current one

app/class/Item.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function hydratejob($datas = []): array
7272
* Export Item Object as an array in order to store it in the database
7373
*
7474
* @param string $dateformat Date formating for DateTime properties {@see Item::datetransform()}
75-
* @return array Item as an associative array
75+
* @return array<string, mixed> Item as an associative array
7676
*/
7777
public function dry(string $dateformat = "string"): array
7878
{
@@ -119,7 +119,7 @@ public function aa(array $arr, string $dateformat): array
119119
* @param string[] $vars list of vars
120120
* @param string $dateformat Date formating for DateTime properties {@see Item::datetransform()}
121121
* @throws InvalidArgumentException if a listed property does not exist or is an object or array
122-
* @return array Associative array `$var => $value`
122+
* @return array<string, mixed> Associative array `var => value`
123123
*/
124124
public function drylist(array $vars, string $dateformat = "string"): array
125125
{

app/class/Logger.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
class Logger
1313
{
14+
/** @var resource|false */
1415
private static $file = false;
1516
private static int $verbosity = 4;
1617

0 commit comments

Comments
 (0)