Skip to content

Commit 134d360

Browse files
committed
refactor: corrected some PHPStan issues
1 parent c8edab5 commit 134d360

File tree

5 files changed

+32
-15
lines changed

5 files changed

+32
-15
lines changed

phpmyfaq/src/phpMyFAQ/Auth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function error(): string
107107
* @param string $method Authentication access methods
108108
* @throws Exception
109109
*/
110-
public function selectAuth(string $method): AuthDriverInterface
110+
public function selectAuth(string $method): Auth
111111
{
112112
// verify selected authentication
113113
$method = ucfirst(strtolower($method));

phpmyfaq/src/phpMyFAQ/Setup/Upgrade.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,23 @@ public function checkFilesystem(): bool
7979
if (!is_dir(PMF_ROOT_DIR . '/assets/themes')) {
8080
throw new Exception('The folder /phpmyfaq/assets/themes is missing.');
8181
}
82+
8283
if (!is_dir(PMF_CONTENT_DIR . '/user/attachments')) {
8384
return false;
8485
}
86+
8587
if (!is_dir(PMF_CONTENT_DIR . '/user/images')) {
8688
return false;
8789
}
90+
8891
if (!is_dir(PMF_CONTENT_DIR . '/core/data')) {
8992
return false;
9093
}
94+
9195
if (!is_dir(PMF_ROOT_DIR . '/assets/themes')) {
9296
return false;
9397
}
98+
9499
if (
95100
is_file(PMF_CONTENT_DIR . '/core/config/constants.php') &&
96101
is_file(PMF_CONTENT_DIR . '/core/config/database.php')

phpmyfaq/src/phpMyFAQ/Template/TwigWrapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ public function addFunction(TwigFunction $twigFunction): void
6666

6767
public function getExtension(string $class): ExtensionInterface
6868
{
69-
return $this->twigEnvironment->getExtension($class);
69+
return $this->twigEnvironment->getExtension($class); /** @phpstan-ignore-line */
7070
}
7171
}

phpmyfaq/src/phpMyFAQ/Translation.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,20 @@ public function setMultiByteLanguage(): void
146146

147147
/**
148148
* Returns the configuration items from the current language for the given section.
149+
*
150+
* @return array<string, array<string, string>>
149151
*/
150152
public static function getConfigurationItems(string $section = ''): array
151153
{
152-
include self::$translation->filename(self::$translation->currentLanguage);
153-
154154
$configuration = [];
155155

156-
foreach ($LANG_CONF as $key => $value) {
157-
if (str_starts_with((string) $key, $section)) {
156+
foreach (self::fetchTranslationFile() as $key => $value) {
157+
if (str_starts_with($key, $section)) {
158158
$configuration[$key] = ['element' => $value[0] ?? '', 'label' => $value[1] ?? ''];
159159

160160
switch ($key) {
161161
case 'records.maxAttachmentSize':
162+
/** @phpstan-ignore-next-line */
162163
$configuration[$key]['label'] = sprintf(
163164
$configuration[$key]['label'],
164165
ini_get('upload_max_filesize')
@@ -267,4 +268,16 @@ protected function filename(string $language): string
267268
{
268269
return self::$translation->languagesDir . DIRECTORY_SEPARATOR . 'language_' . $language . '.php';
269270
}
271+
272+
/**
273+
* Fetches the translation file for the current language.
274+
* @return array<string, array<string, string>>
275+
*/
276+
private static function fetchTranslationFile(): array
277+
{
278+
$LANG_CONF = [];
279+
include self::$translation->filename(self::$translation->currentLanguage);
280+
281+
return $LANG_CONF;
282+
}
270283
}

phpmyfaq/src/phpMyFAQ/User.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ class User
6767
final public const ERROR_USER_LOGIN_INVALID = 'The chosen login is invalid. A valid login has at least four ' .
6868
'characters. Only letters, numbers and underscore _ are allowed. The first letter must be a letter. ';
6969

70-
final public const ERROR_USER_NO_PERM = 'No permission container specified.';
71-
7270
final public const ERROR_USER_NO_USERID = 'No user-ID found. ';
7371

7472
final public const ERROR_USER_NO_USERLOGINDATA = 'No user login data found. ';
@@ -106,7 +104,7 @@ class User
106104
/**
107105
* authentication container.
108106
*
109-
* @var array<string, AuthDriverInterface>
107+
* @var array<string, Auth|AuthDriverInterface>
110108
*/
111109
protected array $authContainer = [];
112110

@@ -240,10 +238,10 @@ public function getAuthData(string $key): mixed
240238
/**
241239
* adds a new authentication object to the user object.
242240
*
243-
* @param AuthDriverInterface $authDriver Driver object
241+
* @param Auth $authDriver Driver object
244242
* @param string $name Auth name
245243
*/
246-
public function addAuth(AuthDriverInterface $authDriver, string $name): bool
244+
public function addAuth(Auth $authDriver, string $name): bool
247245
{
248246
if ($this->checkAuth($authDriver)) {
249247
$this->authContainer[$name] = $authDriver;
@@ -257,9 +255,9 @@ public function addAuth(AuthDriverInterface $authDriver, string $name): bool
257255
/**
258256
* Returns true if auth is a valid authentication object.
259257
*
260-
* @param AuthDriverInterface $auth Auth object
258+
* @param Auth $auth Auth object
261259
*/
262-
protected function checkAuth(AuthDriverInterface $auth): bool
260+
protected function checkAuth(Auth $auth): bool
263261
{
264262
$methods = ['checkCredentials'];
265263
foreach ($methods as $method) {
@@ -359,10 +357,10 @@ public function checkMailAddress(string $name): bool
359357
}
360358

361359
/**
362-
* search users by login.
360+
* Search users by login.
363361
*
364362
* @param string $search Login name
365-
* @return array<int, array>
363+
* @return array<string[]>
366364
*/
367365
public function searchUsers(string $search): array
368366
{
@@ -626,6 +624,7 @@ public function deleteUser(): bool
626624
return false;
627625
}
628626

627+
/** @phpstan-ignore-next-line */
629628
$this->perm->refuseAllUserRights($this->userId);
630629

631630
$delete = sprintf(

0 commit comments

Comments
 (0)