Skip to content

Commit 66926d6

Browse files
committed
refactor: switched code formatting to Mago
1 parent e1a3c23 commit 66926d6

File tree

340 files changed

+5412
-5330
lines changed

Some content is hidden

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

340 files changed

+5412
-5330
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,17 @@ jobs:
4141
- name: Install PHP dependencies
4242
run: composer install --no-progress --prefer-dist --optimize-autoloader
4343

44-
- name: Lint with PHPCS
45-
run: phpmyfaq/src/libs/bin/phpcs --standard=PSR12 ./phpmyfaq/src/phpMyFAQ
44+
#- name: Lint with PHPCS
45+
# run: phpmyfaq/src/libs/bin/phpcs --standard=PSR12 ./phpmyfaq/src/phpMyFAQ
46+
47+
- name: Setup Mago
48+
uses: nhedger/setup-mago@v1
49+
50+
#- name: Run Mago
51+
# run: |
52+
# mago format --dry-run
53+
# mago lint --reporting-format=github
54+
# mago analyze --reporting-format=github
4655

4756
- name: Test with PHPUnit
4857
run: phpmyfaq/src/libs/bin/phpunit --coverage-text

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
composer lint && composer validate && composer test && pnpm pretty-quick --staged && pnpm test
1+
composer validate && composer test && pnpm pretty-quick --staged && pnpm test

.husky/pre-push

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
composer lint && composer validate && composer test && pnpm pretty-quick --staged && pnpm test
1+
composer validate && composer test && pnpm pretty-quick --staged && pnpm test

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"twig/twig": "^3.10"
5555
},
5656
"require-dev": {
57+
"carthage-software/mago": "^1.0.0-beta.28",
5758
"doctrine/instantiator": "2.*",
5859
"mikey179/vfsstream": "^1.6",
5960
"phpdocumentor/reflection-docblock": "5.*",

composer.lock

Lines changed: 61 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpmyfaq/src/phpMyFAQ/Administration/AdminLog.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/**
46
* The main Logging class.
57
*
@@ -19,8 +21,8 @@
1921

2022
use phpMyFAQ\Configuration;
2123
use phpMyFAQ\Database;
22-
use phpMyFAQ\User;
2324
use phpMyFAQ\Entity\AdminLog as AdminLogEntity;
25+
use phpMyFAQ\User;
2426
use Symfony\Component\HttpFoundation\Request;
2527

2628
/**
@@ -33,8 +35,9 @@
3335
/**
3436
* Constructor.
3537
*/
36-
public function __construct(private Configuration $configuration)
37-
{
38+
public function __construct(
39+
private Configuration $configuration,
40+
) {
3841
}
3942

4043
/**
@@ -44,9 +47,7 @@ public function getNumberOfEntries(): int
4447
{
4548
$query = sprintf('SELECT id FROM %sfaqadminlog', Database::getTablePrefix());
4649

47-
return $this->configuration->getDb()->numRows(
48-
$this->configuration->getDb()->query($query)
49-
);
50+
return $this->configuration->getDb()->numRows($this->configuration->getDb()->query($query));
5051
}
5152

5253
/**
@@ -59,7 +60,7 @@ public function getAll(): array
5960

6061
$query = sprintf(
6162
'SELECT id, time, usr AS user, text, ip FROM %sfaqadminlog ORDER BY id DESC',
62-
Database::getTablePrefix()
63+
Database::getTablePrefix(),
6364
);
6465

6566
$result = $this->configuration->getDb()->query($query);
@@ -95,7 +96,7 @@ public function log(User $user, string $logText = ''): bool
9596
$request->server->get('REQUEST_TIME'),
9697
$user->getUserId(),
9798
$this->configuration->getDb()->escape(nl2br($logText)),
98-
$this->configuration->getDb()->escape($request->getClientIp())
99+
$this->configuration->getDb()->escape($request->getClientIp()),
99100
);
100101

101102
return (bool) $this->configuration->getDb()->query($query);
@@ -112,7 +113,7 @@ public function delete(): bool
112113
$query = sprintf(
113114
'DELETE FROM %sfaqadminlog WHERE time < %d',
114115
Database::getTablePrefix(),
115-
Request::createFromGlobals()->server->get('REQUEST_TIME') - 30 * 86400
116+
Request::createFromGlobals()->server->get('REQUEST_TIME') - (30 * 86400),
116117
);
117118

118119
return (bool) $this->configuration->getDb()->query($query);

phpmyfaq/src/phpMyFAQ/Administration/Api.php

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/**
46
* API handler class.
57
*
@@ -19,7 +21,6 @@
1921

2022
use Exception;
2123
use phpMyFAQ\Configuration;
22-
use phpMyFAQ\Core;
2324
use phpMyFAQ\System;
2425
use stdClass;
2526
use Symfony\Component\HttpClient\HttpClient;
@@ -47,8 +48,10 @@ class Api
4748
/**
4849
* Api constructor.
4950
*/
50-
public function __construct(private readonly Configuration $configuration, private readonly System $system)
51-
{
51+
public function __construct(
52+
private readonly Configuration $configuration,
53+
private readonly System $system,
54+
) {
5255
$this->setHttpClient(HttpClient::create(['max_redirects' => 2, 'timeout' => 30]));
5356
}
5457

@@ -61,10 +64,7 @@ public function __construct(private readonly Configuration $configuration, priva
6164
*/
6265
public function getVersions(): array
6366
{
64-
$response = $this->httpClient->request(
65-
'GET',
66-
$this->apiUrl . 'versions'
67-
);
67+
$response = $this->httpClient->request('GET', $this->apiUrl . 'versions');
6868

6969
if ($response->getStatusCode() === Response::HTTP_OK) {
7070
try {
@@ -73,18 +73,13 @@ public function getVersions(): array
7373
'installed' => $this->configuration->getVersion(),
7474
'stable' => $content['stable'],
7575
'development' => $content['development'],
76-
'nightly' => $content['nightly']
76+
'nightly' => $content['nightly'],
7777
];
78-
} catch (
79-
ClientExceptionInterface |
80-
RedirectionExceptionInterface |
81-
ServerExceptionInterface |
82-
TransportExceptionInterface $exception
83-
) {
78+
} catch (ClientExceptionInterface|RedirectionExceptionInterface|ServerExceptionInterface|TransportExceptionInterface $exception) {
8479
throw new Exception(
85-
'phpMyFAQ Verification API is not available: ' . $exception->getMessage(),
80+
'phpMyFAQ Verification API is not available: ' . $exception->getMessage(),
8681
$exception->getCode(),
87-
$exception
82+
$exception,
8883
);
8984
}
9085
}
@@ -93,7 +88,7 @@ public function getVersions(): array
9388
'installed' => $this->configuration->getVersion(),
9489
'stable' => 'n/a',
9590
'development' => 'n/a',
96-
'nightly' => 'n/a'
91+
'nightly' => 'n/a',
9792
];
9893
}
9994

@@ -104,26 +99,18 @@ public function getVersions(): array
10499
*/
105100
public function isVerified(): bool
106101
{
107-
$response = $this->httpClient->request(
108-
'GET',
109-
$this->apiUrl . 'verify/' . $this->configuration->getVersion()
110-
);
102+
$response = $this->httpClient->request('GET', $this->apiUrl . 'verify/' . $this->configuration->getVersion());
111103

112104
try {
113105
$this->remoteHashes = $response->getContent();
114106
if (json_decode($this->remoteHashes, null, 512, JSON_THROW_ON_ERROR) instanceof stdClass) {
115107
return is_array(json_decode($this->remoteHashes, true, 512, JSON_THROW_ON_ERROR));
116108
}
117-
} catch (
118-
ClientExceptionInterface |
119-
RedirectionExceptionInterface |
120-
ServerExceptionInterface |
121-
TransportExceptionInterface $exception
122-
) {
109+
} catch (ClientExceptionInterface|RedirectionExceptionInterface|ServerExceptionInterface|TransportExceptionInterface $exception) {
123110
throw new Exception(
124-
'phpMyFAQ Verification API is not available: ' . $exception->getMessage(),
111+
'phpMyFAQ Verification API is not available: ' . $exception->getMessage(),
125112
$exception->getCode(),
126-
$exception
113+
$exception,
127114
);
128115
}
129116

@@ -139,7 +126,7 @@ public function getVerificationIssues(): array
139126
{
140127
return array_diff(
141128
json_decode($this->system->createHashes(), true, 512, JSON_THROW_ON_ERROR),
142-
json_decode((string) $this->remoteHashes, true, 512, JSON_THROW_ON_ERROR)
129+
json_decode((string) $this->remoteHashes, true, 512, JSON_THROW_ON_ERROR),
143130
);
144131
}
145132

phpmyfaq/src/phpMyFAQ/Administration/Backup.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/**
46
* Provides methods for phpMyFAQ backups
57
*
@@ -37,8 +39,10 @@
3739
/**
3840
* Constructor.
3941
*/
40-
public function __construct(private Configuration $configuration, private DatabaseHelper $databaseHelper)
41-
{
42+
public function __construct(
43+
private Configuration $configuration,
44+
private DatabaseHelper $databaseHelper,
45+
) {
4246
}
4347

4448
/**
@@ -48,7 +52,7 @@ public function createBackup(string $backupType, string $backupFile): string
4852
{
4953
$backupDate = date('Y-m-d-H-i-s');
5054

51-
$fileNamePrefix = (Database::getTablePrefix() !== '') ? Database::getTablePrefix() . '.phpmyfaq' : 'phpmyfaq';
55+
$fileNamePrefix = Database::getTablePrefix() !== '' ? Database::getTablePrefix() . '.phpmyfaq' : 'phpmyfaq';
5256
$fileName = sprintf('%s-%s.%s.sql', $fileNamePrefix, $backupType, $backupDate);
5357

5458
$authKey = sodium_crypto_auth_keygen();
@@ -61,7 +65,7 @@ public function createBackup(string $backupType, string $backupFile): string
6165
$this->configuration->getDb()->escape($fileName),
6266
$this->configuration->getDb()->escape(sodium_bin2hex($authKey)),
6367
$this->configuration->getDb()->escape(sodium_bin2hex($authCode)),
64-
$backupDate
68+
$backupDate,
6569
);
6670

6771
$this->configuration->getDb()->query($query);
@@ -88,7 +92,7 @@ public function verifyBackup(string $backup, string $backupFileName): bool
8892
return sodium_crypto_auth_verify(
8993
sodium_hex2bin((string) $row->authcode),
9094
$backup,
91-
sodium_hex2bin((string) $row->authkey)
95+
sodium_hex2bin((string) $row->authkey),
9296
);
9397
}
9498

@@ -101,10 +105,10 @@ public function generateBackupQueries(string $tableNames): string
101105

102106
foreach (explode(' ', $tableNames) as $table) {
103107
if ('' !== $table) {
104-
$backup .= implode(
105-
"\r\n",
106-
$this->databaseHelper->buildInsertQueries('SELECT * FROM ' . $table, $table)
107-
);
108+
$backup .= implode("\r\n", $this->databaseHelper->buildInsertQueries(
109+
'SELECT * FROM ' . $table,
110+
$table,
111+
));
108112
}
109113
}
110114

@@ -134,8 +138,8 @@ public function getBackupTableNames(BackupType $backupType): string
134138
case BackupType::BACKUP_TYPE_LOGS:
135139
foreach ($tables as $table) {
136140
if (
137-
(Database::getTablePrefix() . 'faqadminlog' === trim((string) $table)) ||
138-
(Database::getTablePrefix() . 'faqsessions' === trim((string) $table))
141+
Database::getTablePrefix() . 'faqadminlog' === trim((string) $table)
142+
|| Database::getTablePrefix() . 'faqsessions' === trim((string) $table)
139143
) {
140144
$tableNames .= $table . ' ';
141145
}
@@ -158,7 +162,7 @@ private function getBackupHeader(string $tableNames): array
158162
'-- DO NOT REMOVE THE FIRST LINE!',
159163
'-- pmftableprefix: ' . Database::getTablePrefix(),
160164
'-- DO NOT REMOVE THE LINES ABOVE!',
161-
'-- Otherwise this backup will be broken.'
165+
'-- Otherwise this backup will be broken.',
162166
];
163167
}
164168

@@ -178,7 +182,7 @@ public function createContentFolderBackup(): string
178182

179183
$files = new RecursiveIteratorIterator(
180184
new RecursiveDirectoryIterator(PMF_CONTENT_DIR),
181-
RecursiveIteratorIterator::LEAVES_ONLY
185+
RecursiveIteratorIterator::LEAVES_ONLY,
182186
);
183187

184188
foreach ($files as $file) {

0 commit comments

Comments
 (0)