Skip to content

Commit 61f6c4d

Browse files
committed
refactor: simplified code, fixed linter issues
1 parent a954412 commit 61f6c4d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+282
-201
lines changed

mago.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Mago configuration file
22
# For more information, see https://mago.carthage.software/#/getting-started/configuration
3-
php-version = "8.3.0"
3+
php-version = "8.4.0"
44

55
[source]
66
paths = ["./phpmyfaq/src/phpMyFAQ"]
@@ -18,9 +18,9 @@ null-type-hint = "question"
1818
integrations = ["symfony", "php-unit"]
1919

2020
[linter.rules]
21-
cyclomatic-complexity = { threshold = 50 }
22-
halstead = { volume-threshold = 3000, effort-threshold = 20000 }
23-
kan-defect = { threshold = 3.0 }
21+
cyclomatic-complexity = { threshold = 75 }
22+
halstead = { volume-threshold = 3000, effort-threshold = 25000 }
23+
kan-defect = { threshold = 4.0 }
2424
too-many-enum-cases = { threshold = 50 }
2525
too-many-methods = { threshold = 20 }
2626
too-many-properties = { threshold = 15 }

phpmyfaq/src/phpMyFAQ/Category/CategoryRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public function findByIdAndLanguage(int $categoryId, string $language): ?Categor
178178
$result = $this->configuration->getDb()->query($query);
179179

180180
if ($row = $this->configuration->getDb()->fetchObject($result)) {
181-
$categoryEntity = (new CategoryEntity())
181+
$categoryEntity = new CategoryEntity()
182182
->setId((int) $row->id)
183183
->setLang($row->lang)
184184
->setParentId((int) $row->parent_id)

phpmyfaq/src/phpMyFAQ/Command/UpdateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7777

7878
$io->success(message: strtr(string: 'phpMyFAQ was successfully updated to version version: on date:.', replace_pairs: [
7979
'version:' => System::getVersion(),
80-
'date:' => (new DateTime())->format(format: 'Y-m-d H:i:s'),
80+
'date:' => new DateTime()->format(format: 'Y-m-d H:i:s'),
8181
]));
8282

8383
return Command::SUCCESS;

phpmyfaq/src/phpMyFAQ/Controller/Administration/Api/AttachmentController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
use Symfony\Component\HttpFoundation\JsonResponse;
3232
use Symfony\Component\HttpFoundation\Request;
3333
use Symfony\Component\HttpFoundation\Response;
34-
use Symfony\Component\Routing\Annotation\Route;
34+
use Symfony\Component\Routing\Attribute\Route;
3535

3636
final class AttachmentController extends AbstractController
3737
{

phpmyfaq/src/phpMyFAQ/Controller/Administration/Api/CategoryController.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
use Symfony\Component\HttpFoundation\JsonResponse;
3333
use Symfony\Component\HttpFoundation\Request;
3434
use Symfony\Component\HttpFoundation\Response;
35-
use Symfony\Component\Routing\Annotation\Route;
35+
use Symfony\Component\Routing\Attribute\Route;
3636

3737
final class CategoryController extends AbstractController
3838
{
@@ -100,13 +100,15 @@ public function permissions(Request $request): JsonResponse
100100

101101
$categoryData = $request->attributes->get('categories');
102102

103-
if (empty($categoryData)) {
103+
if ($categoryData === null || $categoryData === '' || $categoryData === false) {
104104
$categories = [-1]; // Access for all users and groups
105-
} else {
105+
}
106+
107+
if ($categoryData !== null && $categoryData !== '' && $categoryData !== false) {
106108
$categories = explode(',', (string) $categoryData);
107109
}
108110

109-
if (!in_array(true, filter_var_array($categories, FILTER_VALIDATE_INT))) {
111+
if (!in_array(true, filter_var_array($categories, FILTER_VALIDATE_INT), strict: true)) {
110112
return $this->json(['error' => 'Only integer values are valid.'], Response::HTTP_BAD_REQUEST);
111113
}
112114

phpmyfaq/src/phpMyFAQ/Controller/Administration/Api/CommentController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
use Symfony\Component\HttpFoundation\JsonResponse;
2727
use Symfony\Component\HttpFoundation\Request;
2828
use Symfony\Component\HttpFoundation\Response;
29-
use Symfony\Component\Routing\Annotation\Route;
29+
use Symfony\Component\Routing\Attribute\Route;
3030

3131
final class CommentController extends AbstractController
3232
{

phpmyfaq/src/phpMyFAQ/Controller/Administration/Api/ConfigurationController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
use Symfony\Component\HttpFoundation\Request;
2929
use Symfony\Component\HttpFoundation\Response;
3030
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
31-
use Symfony\Component\Routing\Annotation\Route;
31+
use Symfony\Component\Routing\Attribute\Route;
3232

3333
final class ConfigurationController extends AbstractController
3434
{

phpmyfaq/src/phpMyFAQ/Controller/Administration/Api/ConfigurationTabController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
use Symfony\Component\HttpFoundation\JsonResponse;
3535
use Symfony\Component\HttpFoundation\Request;
3636
use Symfony\Component\HttpFoundation\Response;
37-
use Symfony\Component\Routing\Annotation\Route;
37+
use Symfony\Component\Routing\Attribute\Route;
3838
use Twig\Error\LoaderError;
3939

4040
final class ConfigurationTabController extends AbstractController
@@ -101,7 +101,7 @@ public function save(Request $request): JsonResponse
101101
// Parse the list of available fields from the form
102102
$availableFields = [];
103103
if ($availableFieldsJson) {
104-
$availableFields = json_decode($availableFieldsJson, true);
104+
$availableFields = json_decode($availableFieldsJson, associative: true);
105105
if (!is_array($availableFields)) {
106106
$availableFields = [];
107107
}
@@ -159,7 +159,7 @@ public function save(Request $request): JsonResponse
159159
// Only process fields that were available in the current form
160160
// For checkboxes: if field is available but not in configurationData, set to false
161161
// For other fields: keep original value if not in configurationData
162-
if (!empty($availableFields)) {
162+
if ($availableFields !== [] && $availableFields !== null) {
163163
foreach ($availableFields as $fieldKey) {
164164
if (array_key_exists($fieldKey, $newConfigValues)) {
165165
continue;

phpmyfaq/src/phpMyFAQ/Controller/Administration/Api/DashboardController.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
use Symfony\Component\HttpFoundation\JsonResponse;
3030
use Symfony\Component\HttpFoundation\Request;
3131
use Symfony\Component\HttpFoundation\Response;
32-
use Symfony\Component\Routing\Annotation\Route;
32+
use Symfony\Component\Routing\Attribute\Route;
3333
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
3434
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
3535

@@ -62,9 +62,12 @@ public function versions(): JsonResponse
6262

6363
try {
6464
$versions = $api->getVersions();
65+
$info = [];
6566
if (version_compare($versions['installed'], $versions[$releaseEnvironment]) < 0) {
6667
$info = ['warning' => Translation::get(key: 'ad_you_should_update')];
67-
} else {
68+
}
69+
70+
if (version_compare($versions['installed'], $versions[$releaseEnvironment]) >= 0) {
6871
$info = [
6972
'success' => Translation::get(key: 'ad_xmlrpc_latest') . ': phpMyFAQ ' . $versions['stable'],
7073
];

phpmyfaq/src/phpMyFAQ/Controller/Administration/Api/ElasticsearchController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
use phpMyFAQ\Translation;
3030
use Symfony\Component\HttpFoundation\JsonResponse;
3131
use Symfony\Component\HttpFoundation\Response;
32-
use Symfony\Component\Routing\Annotation\Route;
32+
use Symfony\Component\Routing\Attribute\Route;
3333

3434
final class ElasticsearchController extends AbstractController
3535
{

0 commit comments

Comments
 (0)