Skip to content

Commit 803e2e0

Browse files
committed
Add Php stan, fix errors to level 8
1 parent 7d950af commit 803e2e0

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "redbitcz/debug-mode-enabler",
3-
"description": "Debug mode enabler (not only for Tracy debugger) - safe and clean way to manage Debug Mode in your app",
4-
"keywords": ["nette", "tracy", "debug"],
3+
"description": "Debug mode enabler - safe and clean way to manage Debug Mode in your app",
4+
"keywords": ["debug"],
55
"license": ["MIT"],
66
"authors": [
77
{
@@ -29,5 +29,11 @@
2929
"branch-alias": {
3030
"dev-master": "2.0-dev"
3131
}
32+
},
33+
"require-dev": {
34+
"phpstan/phpstan": "^0.12.50"
35+
},
36+
"scripts": {
37+
"phpstan": "phpstan analyze src --level 8"
3238
}
3339
}

src/Detector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function getEnabler(): Enabler
2525
return $this->enabler;
2626
}
2727

28-
public function isDebugMode(?bool $default = false): bool
28+
public function isDebugMode(?bool $default = false): ?bool
2929
{
3030
return $this->isDebugModeByEnabler()
3131
?? $this->isDebugModeByEnv()
@@ -86,7 +86,7 @@ public function isDebugModeByIp(): ?bool
8686
return $result ?: null;
8787
}
8888

89-
public static function detect(string $tempDir, ?bool $default = false): bool
89+
public static function detect(string $tempDir, ?bool $default = false): ?bool
9090
{
9191
return (new self($tempDir))->isDebugMode($default);
9292
}

src/Enabler.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,32 @@ private function destroyToken(string $name): void
135135

136136
// TOKEN LIST ------------------------------------------------------------------------------------------------------
137137

138+
/**
139+
* @return array[]
140+
*/
138141
private function loadList(): array
139142
{
140143
return $this->readStorage();
141144
}
142145

146+
/**
147+
* @param bool $value
148+
* @param array<int, array> $list
149+
* @return string
150+
*/
143151
private function addListToken(bool $value, array &$list): string
144152
{
153+
/** @var string $name */
145154
[$name, $token] = $this->generateToken($value);
146155
$list[] = $token;
147156
return $name;
148157
}
149158

159+
/**
160+
* @param string $name
161+
* @param array<int, array> $list
162+
* @return bool|null
163+
*/
150164
private function getListTokenValue(string $name, array $list): ?bool
151165
{
152166
$id = $this->getIdByName($name);
@@ -160,6 +174,10 @@ private function getListTokenValue(string $name, array $list): ?bool
160174
}
161175

162176

177+
/**
178+
* @param string $name
179+
* @param array<int, array> $list
180+
*/
163181
private function dropListToken(string $name, array &$list): void
164182
{
165183
$id = $this->getIdByName($name);
@@ -171,6 +189,9 @@ static function ($token) use ($id) {
171189
);
172190
}
173191

192+
/**
193+
* @param array<int, array> $list
194+
*/
174195
private function saveList(array $list): void
175196
{
176197
// Filter invalid and expired tokens
@@ -186,6 +207,11 @@ function ($token) {
186207

187208
// TOKEN UTILS -----------------------------------------------------------------------------------------------------
188209

210+
/**
211+
* @param array<string, string|bool|int> $token
212+
* @param string|null $name
213+
* @return bool
214+
*/
189215
private function isTokenValid(array $token, ?string $name = null): bool
190216
{
191217
$now = time();
@@ -206,6 +232,10 @@ private function isTokenValid(array $token, ?string $name = null): bool
206232
return $result;
207233
}
208234

235+
/**
236+
* @param bool $value
237+
* @return array<int, string|array>
238+
*/
209239
private function generateToken(bool $value): array
210240
{
211241
$name = $this->generateTokenName();
@@ -221,6 +251,9 @@ private function generateToken(bool $value): array
221251

222252
// STORAGE ---------------------------------------------------------------------------------------------------------
223253

254+
/**
255+
* @return array<int, array>
256+
*/
224257
private function readStorage(): array
225258
{
226259
$file = $this->getStorageFileName();
@@ -233,6 +266,10 @@ private function readStorage(): array
233266
}
234267
}
235268

269+
/**
270+
* @param array<int, array> $list
271+
* @throws JsonException
272+
*/
236273
private function writeStorage(array $list): void
237274
{
238275
$file = $this->getStorageFileName();

0 commit comments

Comments
 (0)