Skip to content

Commit c622a97

Browse files
thisismeonmounteverestthisismeonmounteverest
authored andcommitted
Chores: Run php-cs-fixer.
1 parent 9a46a87 commit c622a97

File tree

307 files changed

+1575
-2329
lines changed

Some content is hidden

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

307 files changed

+1575
-2329
lines changed

src/Command/CreateTestDatabase.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
use Doctrine\ORM\EntityManagerInterface;
66
use Symfony\Component\Console\Attribute\AsCommand;
77
use Symfony\Component\Console\Command\Command;
8-
use Symfony\Component\Console\Input\ArrayInput;
98
use Symfony\Component\Console\Input\InputInterface;
109
use Symfony\Component\Console\Input\InputOption;
11-
use Symfony\Component\Console\Output\NullOutput;
1210
use Symfony\Component\Console\Output\OutputInterface;
1311
use Symfony\Component\Process\PhpExecutableFinder;
1412
use Symfony\Component\Process\Process;
@@ -63,7 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6361
$output->writeln([
6462
'Creating test database',
6563
'======================',
66-
''
64+
'',
6765
]);
6866

6967
$drop = $input->getOption('drop');

src/Command/DataRetentionCommand.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use App\Entity\NewLocation;
99
use App\Logger\Logger;
1010
use App\Repository\MemberRepository;
11-
use DateTime;
1211
use Doctrine\ORM\EntityManagerInterface;
1312
use Doctrine\ORM\EntityRepository;
1413
use Hidehalo\Nanoid\Client;
@@ -34,7 +33,7 @@ class DataRetentionCommand extends Command
3433
public function __construct(
3534
private readonly Logger $logger,
3635
private readonly EntityManagerInterface $entityManager,
37-
private readonly string $dataDirectory
36+
private readonly string $dataDirectory,
3837
) {
3938
parent::__construct();
4039
}
@@ -58,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5857

5958
$retired = $this->removeMembers($io);
6059

61-
$io->success(sprintf('Data of %d members has been deleted.', $retired));
60+
$io->success(\sprintf('Data of %d members has been deleted.', $retired));
6261

6362
return Command::SUCCESS;
6463
}
@@ -123,7 +122,7 @@ private function removeMemberInfo(Member $member): Member
123122
{
124123
// Used to set a random password (and forget it directly)
125124
$client = new Client();
126-
$longAgo = new DateTime('1900-01-01');
125+
$longAgo = new \DateTime('1900-01-01');
127126

128127
/** @var EntityRepository $locationRepository */
129128
$locationRepository = $this->entityManager->getRepository(NewLocation::class);

src/Command/GeonamesUpdateDailyCommand.php

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22

33
namespace App\Command;
44

5-
use DateTime;
6-
use Doctrine\DBAL\ParameterType;
7-
use Doctrine\ORM\EntityManager;
85
use Doctrine\ORM\EntityManagerInterface;
96
use Symfony\Component\Console\Attribute\AsCommand;
107
use Symfony\Component\Console\Command\Command;
118
use Symfony\Component\Console\Input\InputInterface;
129
use Symfony\Component\Console\Output\OutputInterface;
1310
use Symfony\Component\Console\Style\SymfonyStyle;
14-
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
1511

1612
/**
1713
* @SuppressWarnings("PHPMD.UnusedFormalParameter")
@@ -23,13 +19,24 @@
2319
description: 'Update the geonames data with the latest additions (no deletions!).',
2420
aliases: [],
2521
hidden: false,
26-
)]class GeonamesUpdateDailyCommand extends Command
22+
)] class GeonamesUpdateDailyCommand extends Command
2723
{
2824
public function __construct(private readonly EntityManagerInterface $entityManager)
2925
{
3026
parent::__construct();
3127
}
3228

29+
protected function execute(InputInterface $input, OutputInterface $output): int
30+
{
31+
$io = new SymfonyStyle($input, $output);
32+
$this->updateGeonames($io);
33+
$this->updateAlternatenames($io);
34+
$io->success('Geonames data update successful.');
35+
36+
// always successful
37+
return 0;
38+
}
39+
3340
private function fetchFile($url): array
3441
{
3542
$content = [];
@@ -44,18 +51,7 @@ private function fetchFile($url): array
4451
return $content;
4552
}
4653

47-
protected function execute(InputInterface $input, OutputInterface $output): int
48-
{
49-
$io = new SymfonyStyle($input, $output);
50-
$this->updateGeonames($io);
51-
$this->updateAlternatenames($io);
52-
$io->success('Geonames data update successful.');
53-
54-
// always successful
55-
return 0;
56-
}
57-
58-
private function updateGeonamesForDate(DateTime $date, SymfonyStyle $io): int
54+
private function updateGeonamesForDate(\DateTime $date, SymfonyStyle $io): int
5955
{
6056
$io->note('Working on date ' . $date->format('Y-m-d'));
6157

@@ -174,17 +170,17 @@ private function updateAlternateNamesForDate($date, SymfonyStyle $io): int
174170
**/
175171
private function updateGeonames($io): void
176172
{
177-
$this->updateGeonamesForDate((new DateTime())->modify('-1day'), $io); // Yesterday
178-
$this->updateGeonamesForDate((new DateTime())->modify('-2days'), $io); // the day before yesterday
173+
$this->updateGeonamesForDate((new \DateTime())->modify('-1day'), $io); // Yesterday
174+
$this->updateGeonamesForDate((new \DateTime())->modify('-2days'), $io); // the day before yesterday
179175
if ('01' === date('d', time())) {
180176
// \todo: Update country list on the first day of a month
181177
}
182178
}
183179

184180
private function updateAlternatenames($io): int
185181
{
186-
$result = $this->updateAlternateNamesForDate((new DateTime())->modify('-1day'), $io); // Yesterday
187-
$result |= $this->updateAlternateNamesForDate((new DateTime())->modify('-2days'), $io); // the day before yesterday
182+
$result = $this->updateAlternateNamesForDate((new \DateTime())->modify('-1day'), $io); // Yesterday
183+
$result |= $this->updateAlternateNamesForDate((new \DateTime())->modify('-2days'), $io); // the day before yesterday
188184

189185
return $result;
190186
}

src/Command/GeonamesUpdateFullCommand.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Doctrine\ORM\AbstractQuery;
77
use Doctrine\ORM\EntityManagerInterface;
88
use Doctrine\ORM\Query;
9-
use Exception;
109
use Symfony\Component\Console\Attribute\AsCommand;
1110
use Symfony\Component\Console\Command\Command;
1211
use Symfony\Component\Console\Helper\ProgressBar;
@@ -16,7 +15,6 @@
1615
use Symfony\Component\Console\Style\SymfonyStyle;
1716
use Symfony\Component\Filesystem\Filesystem;
1817
use Symfony\Contracts\HttpClient\HttpClientInterface;
19-
use ZipArchive;
2018

2119
/**
2220
* @SuppressWarnings("PHPMD")
@@ -36,7 +34,7 @@ class GeonamesUpdateFullCommand extends Command
3634
public function __construct(
3735
private readonly HttpClientInterface $httpClient,
3836
private readonly EntityManagerInterface $entityManager,
39-
array $locales
37+
array $locales,
4038
) {
4139
parent::__construct();
4240

@@ -104,7 +102,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
104102

105103
$returnCode = 0;
106104

107-
$downloadFiles = ($input->getOption('download'));
105+
$downloadFiles = $input->getOption('download');
108106

109107
$continueOnErrors = $input->getOption('continue-on-errors');
110108
$geonames = $input->getOption('geonames');
@@ -166,7 +164,7 @@ protected function updateGeonames(SymfonyStyle $io, bool $download): int
166164
return -1;
167165
}
168166

169-
$zip = new ZipArchive();
167+
$zip = new \ZipArchive();
170168
$dir = sys_get_temp_dir() . '/allcountries';
171169
if (true === $zip->open($filename)) {
172170
$zip->extractTo($dir);
@@ -261,7 +259,7 @@ protected function updateAlternatenames(SymfonyStyle $io, bool $download): int
261259

262260
$io->writeln('Extracting downloaded file.');
263261

264-
$zip = new ZipArchive();
262+
$zip = new \ZipArchive();
265263
$dir = sys_get_temp_dir() . '/alternatenames';
266264
if (true === $zip->open($filename)) {
267265
$zip->extractTo($dir);
@@ -300,7 +298,7 @@ protected function updateAlternatenames(SymfonyStyle $io, bool $download): int
300298
if (
301299
is_numeric($row[0])
302300
&& isset($geonameIds[$row[0]])
303-
// && in_array(strtolower($row[2]), $this->allowedLocales)
301+
// && in_array(strtolower($row[2]), $this->allowedLocales)
304302
) {
305303
$rows[] = $row;
306304

@@ -565,7 +563,7 @@ private function updateGeonamesInDatabase(SymfonyStyle $io, array $rows, Progres
565563
}
566564

567565
try {
568-
$query .= sprintf(
566+
$query .= \sprintf(
569567
'(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s), ',
570568
$connection->quote($row[0]),
571569
$connection->quote($row[1]),
@@ -581,7 +579,7 @@ private function updateGeonamesInDatabase(SymfonyStyle $io, array $rows, Progres
581579
$connection->quote($row[14]),
582580
$connection->quote($row[18])
583581
);
584-
} catch (Exception $e) {
582+
} catch (\Exception $e) {
585583
$io->note(
586584
'Skipped ' . $row[1] . ' (' . $row[8] . ', ' . $row[10] . ' - ' . $row[0]
587585
. ') -- ' . $e->getMessage()
@@ -629,7 +627,7 @@ private function updateAlternatenamesInDatabase(SymfonyStyle $io, array $rows, P
629627
break;
630628
}
631629

632-
$query .= sprintf(
630+
$query .= \sprintf(
633631
'(%s, %s, %s, %s, %s, %s, %s, %s), ',
634632
$connection->quote($row[0]),
635633
$connection->quote($row[1]),
@@ -640,7 +638,7 @@ private function updateAlternatenamesInDatabase(SymfonyStyle $io, array $rows, P
640638
$connection->quote($row[6]),
641639
$connection->quote($row[7])
642640
);
643-
} catch (Exception $e) {
641+
} catch (\Exception $e) {
644642
$io->note(
645643
'Skipped ' . $row[1] . ' (' . $row[8] . ', ' . $row[10] . ' - ' . $row[0] . ') -- ' . $e->getMessage()
646644
);

src/Command/ManticoreIndicesForumCommand.php

Lines changed: 42 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,18 @@
22

33
namespace App\Command;
44

5-
use App\Entity\NewLocation;
65
use Doctrine\ORM\EntityManagerInterface;
76
use Doctrine\ORM\NativeQuery;
87
use Doctrine\ORM\Query\ResultSetMapping;
9-
use Doctrine\ORM\Query\ResultSetMappingBuilder;
10-
use Exception;
11-
use Gedmo\Translatable\Entity\Repository\TranslationRepository;
12-
use Gedmo\Translatable\Entity\Translation;
138
use Manticoresearch\Client;
149
use Manticoresearch\Table;
1510
use Symfony\Component\Console\Attribute\AsCommand;
1611
use Symfony\Component\Console\Command\Command;
1712
use Symfony\Component\Console\Helper\ProgressBar;
18-
use Symfony\Component\Console\Input\InputArgument;
1913
use Symfony\Component\Console\Input\InputInterface;
20-
use Symfony\Component\Console\Input\InputOption;
2114
use Symfony\Component\Console\Output\OutputInterface;
2215
use Symfony\Component\Console\Style\SymfonyStyle;
2316

24-
use function count;
25-
2617
#[AsCommand(
2718
name: 'manticore:indices:forum',
2819
description: 'Creates the manticore indices for the forum search',
@@ -54,9 +45,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5445
$this->io->note('Created ' . self::FORUM_INDEX . '.');
5546
} else {
5647
$this->io->note(
57-
'Skipped creation of ' . self::FORUM_INDEX . ' index. ' . PHP_EOL .
48+
'Skipped creation of ' . self::FORUM_INDEX . ' index. ' . \PHP_EOL .
5849
'Index already exists.'
5950
);
51+
6052
return Command::INVALID;
6153
}
6254

@@ -94,7 +86,7 @@ private function createForumIndex(): ?Table
9486
'ngram_len' => '1',
9587
]
9688
);
97-
} catch (Exception $e) {
89+
} catch (\Exception $e) {
9890
// $index = null;
9991

10092
$this->io->error($e->getMessage());
@@ -121,39 +113,38 @@ private function addForumDocuments(Table $index, OutputInterface $output)
121113

122114
$stmt = $this->entityManager
123115
->getConnection()
124-
->executeQuery(<<<___SQL
125-
SELECT
126-
count(*) as cnt
127-
FROM
128-
forums_posts fp
129-
___SQL);
130-
131-
$count = ($stmt->fetchNumeric())[0];
132-
if ($count !== 0) {
116+
->executeQuery(<<<'___SQL'
117+
SELECT
118+
count(*) as cnt
119+
FROM
120+
forums_posts fp
121+
___SQL);
122+
123+
$count = $stmt->fetchNumeric()[0];
124+
if (0 !== $count) {
133125
$progressBar = $this->getProgressBar($output, $count);
134126

135127
$firstResult = 0;
136128
do {
137129
$query = $this->entityManager->createNativeQuery(<<<___SQL
138-
SELECT
139-
fp.id as post_id,
140-
fp.PostDeleted as post_deleted,
141-
fp.PostVisibility as post_visibility,
142-
ft.id AS thread_id,
143-
ft.ThreadDeleted AS thread_deleted,
144-
ft.ThreadVisibility AS thread_visibility,
145-
ftr.Sentence as content,
146-
ft.IdGroup AS `group`,
147-
fp.IdWriter as author,
148-
l.shortcode as locale
149-
FROM
150-
forums_posts fp
151-
JOIN forums_threads ft ON fp.threadid = ft.id
152-
JOIN forum_trads ftr ON fp.IdContent = ftr.IdTrad
153-
JOIN languages l ON ftr.IdLanguage = l.id
154-
LIMIT {$firstResult}, {$this->chunkSize}
155-
___SQL
156-
, $this->getResultSetMappingForForumIndex());
130+
SELECT
131+
fp.id as post_id,
132+
fp.PostDeleted as post_deleted,
133+
fp.PostVisibility as post_visibility,
134+
ft.id AS thread_id,
135+
ft.ThreadDeleted AS thread_deleted,
136+
ft.ThreadVisibility AS thread_visibility,
137+
ftr.Sentence as content,
138+
ft.IdGroup AS `group`,
139+
fp.IdWriter as author,
140+
l.shortcode as locale
141+
FROM
142+
forums_posts fp
143+
JOIN forums_threads ft ON fp.threadid = ft.id
144+
JOIN forum_trads ftr ON fp.IdContent = ftr.IdTrad
145+
JOIN languages l ON ftr.IdLanguage = l.id
146+
LIMIT {$firstResult}, {$this->chunkSize}
147+
___SQL, $this->getResultSetMappingForForumIndex());
157148

158149
$addDocumentsCount = $this->addForumDocumentsToIndex($index, $query, $progressBar);
159150

@@ -173,22 +164,22 @@ private function addForumDocumentsToIndex(Table $index, NativeQuery $query, Prog
173164
foreach ($forumPosts as $forumPost) {
174165
$documents[] = [
175166
'post_id' => $forumPost['post_id'],
176-
'post_deleted' => $forumPost['post_deleted'],
177-
'post_visibility' => $forumPost['post_visibility'],
178-
'thread_id' => $forumPost['thread_id'],
179-
'thread_deleted' => $forumPost['thread_deleted'],
180-
'thread_visibility' => $forumPost['thread_visibility'],
181-
'content' => $forumPost['content'],
182-
'group' => $forumPost['group'] ?? 0,
183-
'author' => $forumPost['author'],
184-
'locale' => $forumPost['locale'],
167+
'post_deleted' => $forumPost['post_deleted'],
168+
'post_visibility' => $forumPost['post_visibility'],
169+
'thread_id' => $forumPost['thread_id'],
170+
'thread_deleted' => $forumPost['thread_deleted'],
171+
'thread_visibility' => $forumPost['thread_visibility'],
172+
'content' => $forumPost['content'],
173+
'group' => $forumPost['group'] ?? 0,
174+
'author' => $forumPost['author'],
175+
'locale' => $forumPost['locale'],
185176
];
186177
$progress->advance();
187178
}
188179
$count = \count($forumPosts);
189180
unset($forumPosts);
190181

191-
if ($count !== 0) {
182+
if (0 !== $count) {
192183
$index->addDocuments($documents);
193184
$index->flush();
194185
}
@@ -214,8 +205,10 @@ private function getResultSetMappingForForumIndex(): ResultSetMapping
214205
->addScalarResult('locale', 'locale')
215206
->addScalarResult('created', 'created')
216207
;
208+
217209
return $rsm;
218210
}
211+
219212
private function getProgressBar(OutputInterface $output, $count): ProgressBar
220213
{
221214
$progressBar = new ProgressBar($output, $count);

0 commit comments

Comments
 (0)