Skip to content

Commit 9e33a17

Browse files
thisismeonmounteverestthisismeonmounteverest
authored andcommitted
CI: Update cs-fixer config to match with phpmd rule set.
1 parent c622a97 commit 9e33a17

File tree

179 files changed

+905
-653
lines changed

Some content is hidden

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

179 files changed

+905
-653
lines changed

.php-cs-fixer.dist.php

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,45 @@
1515
'@Symfony:risky' => true,
1616
'array_syntax' => ['syntax' => 'short'],
1717
'combine_consecutive_unsets' => true,
18-
// one should use PHPUnit methods to set up expected exception instead of annotations
19-
'general_phpdoc_annotation_remove' => [
20-
'annotations' => [
21-
'expectedException',
22-
'expectedExceptionMessage',
23-
'expectedExceptionMessageRegExp',
24-
]
25-
],
26-
'heredoc_to_nowdoc' => true,
27-
'no_extra_blank_lines' => [
28-
'tokens' => [
29-
'break',
30-
'continue',
31-
'extra',
32-
'return',
33-
'throw',
34-
'use',
35-
'parenthesis_brace_block',
36-
'square_brace_block',
37-
'curly_brace_block'
38-
],
39-
],
40-
'no_unreachable_default_argument_value' => true,
41-
'no_useless_else' => true,
42-
'no_useless_return' => true,
43-
'ordered_class_elements' => true,
44-
'ordered_imports' => true,
45-
'php_unit_strict' => true,
46-
'phpdoc_add_missing_param_annotation' => true,
47-
'phpdoc_order' => true,
48-
'semicolon_after_instruction' => true,
49-
'strict_comparison' => true,
50-
'strict_param' => true,
51-
'concat_space' => ['spacing' => 'one'],
52-
])
53-
->setFinder($finder)
54-
;
18+
// one should use PHPUnit methods to set up expected exception instead of annotations
19+
'general_phpdoc_annotation_remove' => [
20+
'annotations' => [
21+
'expectedException',
22+
'expectedExceptionMessage',
23+
'expectedExceptionMessageRegExp',
24+
]
25+
],
26+
'global_namespace_import' => [
27+
'import_classes' => true,
28+
'import_constants' => true,
29+
],
30+
'heredoc_to_nowdoc' => true,
31+
'no_extra_blank_lines' => [
32+
'tokens' => [
33+
'break',
34+
'continue',
35+
'extra',
36+
'return',
37+
'throw',
38+
'use',
39+
'parenthesis_brace_block',
40+
'square_brace_block',
41+
'curly_brace_block'
42+
],
43+
],
44+
'no_unreachable_default_argument_value' => true,
45+
'no_useless_else' => true,
46+
'no_useless_return' => true,
47+
'ordered_class_elements' => true,
48+
'ordered_imports' => true,
49+
'php_unit_strict' => true,
50+
'phpdoc_add_missing_param_annotation' => true,
51+
'phpdoc_order' => true,
52+
'semicolon_after_instruction' => true,
53+
'strict_comparison' => true,
54+
'strict_param' => true,
55+
'concat_space' => ['spacing' => 'one'],
56+
])
57+
->setFinder($finder);
5558

5659
return $config;

src/Command/DataRetentionCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
use App\Entity\NewLocation;
99
use App\Logger\Logger;
1010
use App\Repository\MemberRepository;
11+
use DateTime;
1112
use Doctrine\ORM\EntityManagerInterface;
1213
use Doctrine\ORM\EntityRepository;
14+
use Exception;
1315
use Hidehalo\Nanoid\Client;
1416
use Symfony\Component\Console\Attribute\AsCommand;
1517
use Symfony\Component\Console\Command\Command;
@@ -122,7 +124,7 @@ private function removeMemberInfo(Member $member): Member
122124
{
123125
// Used to set a random password (and forget it directly)
124126
$client = new Client();
125-
$longAgo = new \DateTime('1900-01-01');
127+
$longAgo = new DateTime('1900-01-01');
126128

127129
/** @var EntityRepository $locationRepository */
128130
$locationRepository = $this->entityManager->getRepository(NewLocation::class);
@@ -236,7 +238,7 @@ private function removeProfilePictures(Member $member): void
236238
foreach ($files as $file) {
237239
$filesystem->remove($file);
238240
}
239-
} catch (\Exception $e) {
241+
} catch (Exception $e) {
240242
$this->logger->write(
241243
'Problem during retention run: ' . $e->getMessage(),
242244
'Data Retention',

src/Command/GeonamesUpdateDailyCommand.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Command;
44

5+
use DateTime;
56
use Doctrine\ORM\EntityManagerInterface;
67
use Symfony\Component\Console\Attribute\AsCommand;
78
use Symfony\Component\Console\Command\Command;
@@ -51,7 +52,7 @@ private function fetchFile($url): array
5152
return $content;
5253
}
5354

54-
private function updateGeonamesForDate(\DateTime $date, SymfonyStyle $io): int
55+
private function updateGeonamesForDate(DateTime $date, SymfonyStyle $io): int
5556
{
5657
$io->note('Working on date ' . $date->format('Y-m-d'));
5758

@@ -170,17 +171,17 @@ private function updateAlternateNamesForDate($date, SymfonyStyle $io): int
170171
**/
171172
private function updateGeonames($io): void
172173
{
173-
$this->updateGeonamesForDate((new \DateTime())->modify('-1day'), $io); // Yesterday
174-
$this->updateGeonamesForDate((new \DateTime())->modify('-2days'), $io); // the day before yesterday
174+
$this->updateGeonamesForDate((new DateTime())->modify('-1day'), $io); // Yesterday
175+
$this->updateGeonamesForDate((new DateTime())->modify('-2days'), $io); // the day before yesterday
175176
if ('01' === date('d', time())) {
176177
// \todo: Update country list on the first day of a month
177178
}
178179
}
179180

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

185186
return $result;
186187
}

src/Command/GeonamesUpdateFullCommand.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Doctrine\ORM\AbstractQuery;
77
use Doctrine\ORM\EntityManagerInterface;
88
use Doctrine\ORM\Query;
9+
use Exception;
910
use Symfony\Component\Console\Attribute\AsCommand;
1011
use Symfony\Component\Console\Command\Command;
1112
use Symfony\Component\Console\Helper\ProgressBar;
@@ -15,6 +16,7 @@
1516
use Symfony\Component\Console\Style\SymfonyStyle;
1617
use Symfony\Component\Filesystem\Filesystem;
1718
use Symfony\Contracts\HttpClient\HttpClientInterface;
19+
use ZipArchive;
1820

1921
/**
2022
* @SuppressWarnings("PHPMD")
@@ -164,7 +166,7 @@ protected function updateGeonames(SymfonyStyle $io, bool $download): int
164166
return -1;
165167
}
166168

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

260262
$io->writeln('Extracting downloaded file.');
261263

262-
$zip = new \ZipArchive();
264+
$zip = new ZipArchive();
263265
$dir = sys_get_temp_dir() . '/alternatenames';
264266
if (true === $zip->open($filename)) {
265267
$zip->extractTo($dir);
@@ -579,7 +581,7 @@ private function updateGeonamesInDatabase(SymfonyStyle $io, array $rows, Progres
579581
$connection->quote($row[14]),
580582
$connection->quote($row[18])
581583
);
582-
} catch (\Exception $e) {
584+
} catch (Exception $e) {
583585
$io->note(
584586
'Skipped ' . $row[1] . ' (' . $row[8] . ', ' . $row[10] . ' - ' . $row[0]
585587
. ') -- ' . $e->getMessage()
@@ -638,7 +640,7 @@ private function updateAlternatenamesInDatabase(SymfonyStyle $io, array $rows, P
638640
$connection->quote($row[6]),
639641
$connection->quote($row[7])
640642
);
641-
} catch (\Exception $e) {
643+
} catch (Exception $e) {
642644
$io->note(
643645
'Skipped ' . $row[1] . ' (' . $row[8] . ', ' . $row[10] . ' - ' . $row[0] . ') -- ' . $e->getMessage()
644646
);

src/Command/ManticoreIndicesForumCommand.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
use Doctrine\ORM\EntityManagerInterface;
66
use Doctrine\ORM\NativeQuery;
77
use Doctrine\ORM\Query\ResultSetMapping;
8+
use Exception;
89
use Manticoresearch\Client;
910
use Manticoresearch\Table;
11+
12+
use const PHP_EOL;
13+
1014
use Symfony\Component\Console\Attribute\AsCommand;
1115
use Symfony\Component\Console\Command\Command;
1216
use Symfony\Component\Console\Helper\ProgressBar;
@@ -45,7 +49,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4549
$this->io->note('Created ' . self::FORUM_INDEX . '.');
4650
} else {
4751
$this->io->note(
48-
'Skipped creation of ' . self::FORUM_INDEX . ' index. ' . \PHP_EOL .
52+
'Skipped creation of ' . self::FORUM_INDEX . ' index. ' . PHP_EOL .
4953
'Index already exists.'
5054
);
5155

@@ -86,7 +90,7 @@ private function createForumIndex(): ?Table
8690
'ngram_len' => '1',
8791
]
8892
);
89-
} catch (\Exception $e) {
93+
} catch (Exception $e) {
9094
// $index = null;
9195

9296
$this->io->error($e->getMessage());

src/Command/ManticoreIndicesGeonamesCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Doctrine\ORM\EntityManagerInterface;
77
use Doctrine\ORM\NativeQuery;
88
use Doctrine\ORM\Query\ResultSetMapping;
9+
use Exception;
910
use Manticoresearch\Client;
1011
use Manticoresearch\Table;
1112
use Symfony\Component\Console\Attribute\AsCommand;
@@ -95,7 +96,7 @@ private function createGeonamesIndex(): ?Table
9596
'ngram_len' => '1',
9697
]
9798
);
98-
} catch (\Exception $e) {
99+
} catch (Exception $e) {
99100
// $index = null;
100101

101102
$this->io->error($e->getMessage());

src/Command/SendMassmailCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use App\Entity\Newsletter;
99
use App\Service\Mailer;
1010
use Doctrine\ORM\EntityManagerInterface;
11+
use Exception;
1112
use Symfony\Component\Console\Attribute\AsCommand;
1213
use Symfony\Component\Console\Command\Command;
1314
use Symfony\Component\Console\Input\InputInterface;
@@ -96,7 +97,7 @@ private function sendMassmail(array $scheduledBroadcastMessages, SymfonyStyle $i
9697
->setStatus('Sent')
9798
->setUnsubscribeKey($unsubscribeKey);
9899
++$sent;
99-
} catch (\Exception $e) {
100+
} catch (Exception $e) {
100101
$io->error('Message Frozen: ' . $e->getMessage());
101102
$scheduled->setStatus('Freeze');
102103
}

src/Command/SendNotificationsCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use App\Service\Mailer;
1111
use App\Utilities\TranslatorTrait;
1212
use Doctrine\ORM\EntityManagerInterface;
13+
use Exception;
1314
use Psr\Log\LoggerInterface;
1415
use Symfony\Component\Console\Attribute\AsCommand;
1516
use Symfony\Component\Console\Command\Command;
@@ -88,7 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8889
);
8990
$notificationStatus = NotificationStatusType::SENT;
9091
++$sent;
91-
} catch (\Exception $e) {
92+
} catch (Exception $e) {
9293
$io->error($e->getMessage());
9394
}
9495
}

src/Command/UpdateStatistics.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
namespace App\Command;
44

55
use App\Model\StatisticsModel;
6+
use DateInterval;
7+
use DatePeriod;
8+
use DateTime;
69
use Doctrine\DBAL\DBALException;
710
use Doctrine\ORM\OptimisticLockException;
811
use Doctrine\ORM\ORMException;
12+
use Exception;
913
use Psr\Log\LoggerInterface;
1014
use Symfony\Component\Console\Attribute\AsCommand;
1115
use Symfony\Component\Console\Command\Command;
@@ -53,14 +57,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5357

5458
$startDateGiven = $input->getArgument('startDate');
5559
if ($startDateGiven) {
56-
$startDate = \DateTime::createFromFormat('Y-m-d', $startDateGiven);
60+
$startDate = DateTime::createFromFormat('Y-m-d', $startDateGiven);
5761
} else {
58-
$startDate = new \DateTime();
62+
$startDate = new DateTime();
5963
$startDate->modify('-1 day');
6064
}
6165

6266
// Check first to avoid false positives on end date if none given
63-
$today = new \DateTime();
67+
$today = new DateTime();
6468
$today->setTime(0, 0, 0, 0);
6569
if ($startDate >= $today) {
6670
$output->writeln([
@@ -72,9 +76,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7276

7377
$endDateGiven = $input->getArgument('endDate');
7478
if ($endDateGiven) {
75-
$endDate = \DateTime::createFromFormat('Y-m-d', $endDateGiven);
79+
$endDate = DateTime::createFromFormat('Y-m-d', $endDateGiven);
7680
} else {
77-
$endDate = new \DateTime();
81+
$endDate = new DateTime();
7882
}
7983

8084
if (!$startDate || !$endDate) {
@@ -102,15 +106,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
102106
$endDate->modify('+1 day');
103107
}
104108

105-
$interval = new \DateInterval('P1D');
106-
$dates = new \DatePeriod($startDate, $interval, $endDate);
109+
$interval = new DateInterval('P1D');
110+
$dates = new DatePeriod($startDate, $interval, $endDate);
107111

108112
$this->logger->info('Updating statistics from ' . $startDate->format('Y-m-d') . ' to ' . $endDate->format('Y-m-d'));
109113

110114
$returnCode = 1;
111115
try {
112116
$returnCode = $this->statisticsModel->updateStatistics($dates, $output);
113-
} catch (\Exception $e) {
117+
} catch (Exception $e) {
114118
$this->logger->error('Updating statistics failed: ' . $e->getMessage());
115119
}
116120

src/Controller/ActivityController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Controller;
44

55
use App\Entity\Activity;
6+
use DateTimeImmutable;
67
use Eluceo\iCal\Domain\Entity\Calendar;
78
use Eluceo\iCal\Domain\Entity\Event;
89
use Eluceo\iCal\Domain\ValueObject\DateTime;
@@ -30,8 +31,8 @@ public function created(Activity $activity): Response
3031
#[Route(path: '/activity/{id}/download', name: 'activity_download', requirements: ['id' => '\d+'])]
3132
public function download(Activity $activity): Response
3233
{
33-
$start = new DateTime(\DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $activity->getStarts()), false);
34-
$end = new DateTime(\DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $activity->getEnds()), false);
34+
$start = new DateTime(DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $activity->getStarts()), false);
35+
$end = new DateTime(DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $activity->getEnds()), false);
3536
$occurrence = new TimeSpan($start, $end);
3637
$location = new Location($activity->getAddress());
3738
$strippedDescription = strip_tags(str_replace('<br>', "\r\n", $activity->getDescription()));

0 commit comments

Comments
 (0)