Skip to content

Commit 8074b29

Browse files
committed
build: updated to Mago 1.0.0
1 parent 2204278 commit 8074b29

File tree

70 files changed

+647
-1632
lines changed

Some content is hidden

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

70 files changed

+647
-1632
lines changed

composer.lock

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

phpmyfaq/src/phpMyFAQ/Administration/Backup.php

Lines changed: 16 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,8 @@ public function getLastBackupInfo(): array
6969

7070
if ($lastBackup !== null && isset($lastBackup->created)) {
7171
$createdRaw = (string) $lastBackup->created;
72-
$createdDate = DateTimeImmutable::createFromFormat(
73-
format: 'Y-m-d H:i:s',
74-
datetime: $createdRaw,
75-
) ?: null;
72+
$createdDate = DateTimeImmutable::createFromFormat(format: 'Y-m-d H:i:s', datetime: $createdRaw)
73+
?: null;
7674
if ($createdDate !== null) {
7775
$lastBackupDateFormatted = $createdDate->format(format: 'Y-m-d H:i:s');
7876
$threshold = new DateTimeImmutable(datetime: '-30 days');
@@ -131,23 +129,17 @@ public function verifyBackup(string $backup, string $backupFileName): bool
131129

132130
public function generateBackupQueries(string $tableNames): string
133131
{
134-
$backup = implode(
135-
separator: "\r\n",
136-
array: $this->getBackupHeader($tableNames),
137-
);
132+
$backup = implode(separator: "\r\n", array: $this->getBackupHeader($tableNames));
138133

139-
foreach (explode(
140-
separator: ' ',
141-
string: $tableNames,
142-
) as $tableName) {
134+
foreach (explode(separator: ' ', string: $tableNames) as $tableName) {
143135
if ('' === $tableName) {
144136
continue;
145137
}
146138

147-
$backup .= implode(
148-
separator: "\r\n",
149-
array: $this->databaseHelper->buildInsertQueries('SELECT * FROM ' . $tableName, $tableName),
150-
);
139+
$backup .= implode(separator: "\r\n", array: $this->databaseHelper->buildInsertQueries(
140+
'SELECT * FROM ' . $tableName,
141+
$tableName,
142+
));
151143
}
152144

153145
return $backup;
@@ -206,11 +198,7 @@ private function getBackupHeader(string $tableNames): array
206198
return [
207199
sprintf(
208200
'-- pmf%s: %s',
209-
substr(
210-
string: $this->configuration->getVersion(),
211-
offset: 0,
212-
length: 3,
213-
),
201+
substr(string: $this->configuration->getVersion(), offset: 0, length: 3),
214202
$tableNames,
215203
),
216204
'-- DO NOT REMOVE THE FIRST LINE!',
@@ -290,28 +278,13 @@ public function parseBackupFile(string $filePath, string $currentVersion): Backu
290278
throw new Exception(message: 'Empty backup file.');
291279
}
292280

293-
$versionFound = Strings::substr(
294-
string: $firstLine,
295-
start: 0,
296-
length: 9,
297-
);
281+
$versionFound = Strings::substr(string: $firstLine, start: 0, length: 9);
298282

299-
$versionExpected = '-- pmf'
300-
. substr(
301-
string: $currentVersion,
302-
offset: 0,
303-
length: 3,
304-
);
283+
$versionExpected = '-- pmf' . substr(string: $currentVersion, offset: 0, length: 3);
305284

306285
// Tabellen aus der ersten Zeile extrahieren
307-
$tablesLine = trim(Strings::substr(
308-
string: $firstLine,
309-
start: 11,
310-
));
311-
$tables = explode(
312-
separator: ' ',
313-
string: $tablesLine,
314-
);
286+
$tablesLine = trim(Strings::substr(string: $firstLine, start: 11));
287+
$tables = explode(separator: ' ', string: $tablesLine);
315288

316289
$queries = [];
317290
foreach ($tables as $tableName) {
@@ -329,31 +302,14 @@ public function parseBackupFile(string $filePath, string $currentVersion): Backu
329302
$backupPrefixPattern = '-- pmftableprefix:';
330303
$backupPrefixPatternLength = Strings::strlen($backupPrefixPattern);
331304

332-
if (
333-
Strings::substr(
334-
string: $line,
335-
start: 0,
336-
length: $backupPrefixPatternLength,
337-
) === $backupPrefixPattern
338-
) {
305+
if (Strings::substr(string: $line, start: 0, length: $backupPrefixPatternLength) === $backupPrefixPattern) {
339306
$tablePrefix = trim(Strings::substr($line, $backupPrefixPatternLength));
340307

341308
continue;
342309
}
343310

344-
if (
345-
Strings::substr(
346-
string: $line,
347-
start: 0,
348-
length: 2,
349-
) !== '--'
350-
&& $line !== ''
351-
) {
352-
$queries[] = trim(Strings::substr(
353-
string: $line,
354-
start: 0,
355-
length: -1,
356-
));
311+
if (Strings::substr(string: $line, start: 0, length: 2) !== '--' && $line !== '') {
312+
$queries[] = trim(Strings::substr(string: $line, start: 0, length: -1));
357313
}
358314
}
359315

phpmyfaq/src/phpMyFAQ/Administration/Backup/BackupRepository.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ public function add(string $filename, string $authKeyHex, string $authCodeHex, s
7979
}
8080

8181
$table = Database::getTablePrefix() . 'faqbackup';
82-
$id = $this->configuration->getDb()->nextId(
83-
table: $table,
84-
column: 'id',
85-
);
82+
$id = $this->configuration->getDb()->nextId(table: $table, column: 'id');
8683

8784
$filenameEscaped = $this->configuration->getDb()->escape($filename);
8885
$authKeyEscaped = $this->configuration->getDb()->escape($authKeyHex);

phpmyfaq/src/phpMyFAQ/Administration/HttpStreamer.php

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -133,36 +133,15 @@ private function setHttpHeaders(): void
133133
]);
134134

135135
// 2. Set the correct values for file streaming
136-
$this->response->headers->set(
137-
key: 'Content-Type',
138-
values: $mimeType,
139-
);
136+
$this->response->headers->set(key: 'Content-Type', values: $mimeType);
140137

141138
// 3. RFC2616, §19.5.1: $filename must be a quoted-string
142-
$disposition = HeaderUtils::makeDisposition(
143-
disposition: $this->disposition,
144-
filename: $filename,
145-
);
146-
$this->response->headers->set(
147-
key: 'Content-Disposition',
148-
values: $disposition,
149-
);
150-
$this->response->headers->set(
151-
key: 'Content-Description',
152-
values: $description,
153-
);
154-
$this->response->headers->set(
155-
key: 'Content-Transfer-Encoding',
156-
values: 'binary',
157-
);
158-
$this->response->headers->set(
159-
key: 'Accept-Ranges',
160-
values: 'none',
161-
);
162-
$this->response->headers->set(
163-
key: 'Content-Length',
164-
values: (string) $this->size,
165-
);
139+
$disposition = HeaderUtils::makeDisposition(disposition: $this->disposition, filename: $filename);
140+
$this->response->headers->set(key: 'Content-Disposition', values: $disposition);
141+
$this->response->headers->set(key: 'Content-Description', values: $description);
142+
$this->response->headers->set(key: 'Content-Transfer-Encoding', values: 'binary');
143+
$this->response->headers->set(key: 'Accept-Ranges', values: 'none');
144+
$this->response->headers->set(key: 'Content-Length', values: (string) $this->size);
166145
}
167146

168147
/**

phpmyfaq/src/phpMyFAQ/Administration/Report.php

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,7 @@ public function getReportingData(): array
8888
public function convertEncoding(string $outputString = ''): string
8989
{
9090
$outputString = html_entity_decode($outputString, ENT_QUOTES, encoding: 'utf-8');
91-
$outputString = str_replace(
92-
search: ',',
93-
replace: ' ',
94-
subject: $outputString,
95-
);
91+
$outputString = str_replace(search: ',', replace: ' ', subject: $outputString);
9692

9793
if (extension_loaded(extension: 'mbstring')) {
9894
$detected = mb_detect_encoding($outputString);
@@ -103,11 +99,7 @@ public function convertEncoding(string $outputString = ''): string
10399
}
104100

105101
$toBeRemoved = ['=', '+', '-', 'HYPERLINK'];
106-
return str_replace(
107-
search: $toBeRemoved,
108-
replace: '',
109-
subject: $outputString,
110-
);
102+
return str_replace(search: $toBeRemoved, replace: '', subject: $outputString);
111103
}
112104

113105
/**
@@ -117,19 +109,8 @@ public function convertEncoding(string $outputString = ''): string
117109
*/
118110
public static function sanitize(int|string $value): string|int
119111
{
120-
if (preg_match(
121-
pattern: '/[=\+\-\@\|]/',
122-
subject: (string) $value,
123-
)) {
124-
return (
125-
'"'
126-
. str_replace(
127-
search: '"',
128-
replace: '""',
129-
subject: $value,
130-
)
131-
. '"'
132-
);
112+
if (preg_match(pattern: '/[=\+\-\@\|]/', subject: (string) $value)) {
113+
return '"' . str_replace(search: '"', replace: '""', subject: $value) . '"';
133114
}
134115

135116
return $value;

phpmyfaq/src/phpMyFAQ/Administration/Session.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -124,28 +124,15 @@ public function getLast30DaysVisits(int $endDate): array
124124
$visits = $this->repository->getSessionTimestamps($startDate, $endDate);
125125

126126
for ($date = $startDate; $date <= $endDate; $date += 86400) {
127-
$stats[date(
128-
format: 'Y-m-d',
129-
timestamp: $date,
130-
)] = 0;
127+
$stats[date(format: 'Y-m-d', timestamp: $date)] = 0;
131128
}
132129

133130
foreach ($visits as $visitDate) {
134-
if (
135-
!isset(
136-
$stats[date(
137-
format: 'Y-m-d',
138-
timestamp: $visitDate,
139-
)],
140-
)
141-
) {
131+
if (!isset($stats[date(format: 'Y-m-d', timestamp: $visitDate)])) {
142132
continue;
143133
}
144134

145-
++$stats[date(
146-
format: 'Y-m-d',
147-
timestamp: $visitDate,
148-
)];
135+
++$stats[date(format: 'Y-m-d', timestamp: $visitDate)];
149136
}
150137

151138
foreach (array_keys($stats) as $date) {

phpmyfaq/src/phpMyFAQ/Administration/TranslationStatistics.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,7 @@ private function getTranslationKeys(string $language): array
132132
*/
133133
private function extractLanguageCode(string $filePath): ?string
134134
{
135-
if (preg_match(
136-
pattern: '/language_([a-z_]+)\.php$/',
137-
subject: $filePath,
138-
matches: $matches,
139-
)) {
135+
if (preg_match(pattern: '/language_([a-z_]+)\.php$/', subject: $filePath, matches: $matches)) {
140136
return $matches[1];
141137
}
142138

phpmyfaq/src/phpMyFAQ/Application.php

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,10 @@ private function handleRequest(
139139
)
140140
: 'Not Found';
141141

142-
$response = new Response(
143-
content: $message,
144-
status: Response::HTTP_NOT_FOUND,
145-
);
142+
$response = new Response(content: $message, status: Response::HTTP_NOT_FOUND);
146143
} catch (UnauthorizedHttpException) {
147144
$response = new RedirectResponse(url: './login');
148-
if (str_contains(
149-
haystack: $urlMatcher->getContext()->getBaseUrl(),
150-
needle: '/api',
151-
)) {
145+
if (str_contains(haystack: $urlMatcher->getContext()->getBaseUrl(), needle: '/api')) {
152146
$response = new Response(
153147
content: json_encode(value: ['error' => 'Unauthorized access']),
154148
status: Response::HTTP_UNAUTHORIZED,
@@ -162,21 +156,15 @@ private function handleRequest(
162156
exception: $exception,
163157
)
164158
: 'Bad Request';
165-
$response = new Response(
166-
content: $message,
167-
status: Response::HTTP_FORBIDDEN,
168-
);
159+
$response = new Response(content: $message, status: Response::HTTP_FORBIDDEN);
169160
} catch (BadRequestException $exception) {
170161
$message = Environment::isDebugMode()
171162
? $this->formatExceptionMessage(
172163
template: 'An error occurred: :message at line :line at :file',
173164
exception: $exception,
174165
)
175166
: 'Bad Request';
176-
$response = new Response(
177-
content: $message,
178-
status: Response::HTTP_BAD_REQUEST,
179-
);
167+
$response = new Response(content: $message, status: Response::HTTP_BAD_REQUEST);
180168
}
181169

182170
$response->send();
@@ -187,13 +175,10 @@ private function handleRequest(
187175
*/
188176
private function formatExceptionMessage(string $template, Throwable $exception): string
189177
{
190-
return strtr(
191-
string: $template,
192-
from: [
193-
':message' => $exception->getMessage(),
194-
':line' => (string) $exception->getLine(),
195-
':file' => $exception->getFile(),
196-
],
197-
);
178+
return strtr(string: $template, from: [
179+
':message' => $exception->getMessage(),
180+
':line' => (string) $exception->getLine(),
181+
':file' => $exception->getFile(),
182+
]);
198183
}
199184
}

phpmyfaq/src/phpMyFAQ/Auth.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,7 @@ public function getEncryptionContainer(string $encType): Encryption
8080
*/
8181
public function getErrors(): string
8282
{
83-
$message = $this->errors !== []
84-
? implode(
85-
separator: PHP_EOL,
86-
array: $this->errors,
87-
) . PHP_EOL : '';
83+
$message = $this->errors !== [] ? implode(separator: PHP_EOL, array: $this->errors) . PHP_EOL : '';
8884
return $message . ($this->encContainer ? $this->encContainer->error() : '');
8985
}
9086

0 commit comments

Comments
 (0)