DX: apply rector rules up to php8.0

This commit is contained in:
2023-04-15 01:05:37 +02:00
parent d8870e906f
commit dde3002100
714 changed files with 2348 additions and 9263 deletions

View File

@@ -20,11 +20,8 @@ use UnexpectedValueException;
class RefreshAddressToGeographicalUnitMaterializedViewCronJob implements CronJobInterface
{
private Connection $connection;
public function __construct(Connection $connection)
public function __construct(private Connection $connection)
{
$this->connection = $connection;
}
public function canRun(?CronJobExecution $cronJobExecution): bool

View File

@@ -22,20 +22,8 @@ class AddressReferenceBEFromBestAddress
{
private const RELEASE = 'https://gitea.champs-libres.be/api/v1/repos/Chill-project/belgian-bestaddresses-transform/releases/tags/v1.0.0';
private AddressReferenceBaseImporter $baseImporter;
private AddressToReferenceMatcher $addressToReferenceMatcher;
private HttpClientInterface $client;
public function __construct(
HttpClientInterface $client,
AddressReferenceBaseImporter $baseImporter,
AddressToReferenceMatcher $addressToReferenceMatcher
) {
$this->client = $client;
$this->baseImporter = $baseImporter;
$this->addressToReferenceMatcher = $addressToReferenceMatcher;
public function __construct(private HttpClientInterface $client, private AddressReferenceBaseImporter $baseImporter, private AddressToReferenceMatcher $addressToReferenceMatcher)
{
}
public function import(string $lang, array $lists): void

View File

@@ -46,18 +46,12 @@ final class AddressReferenceBaseImporter
private ?string $currentSource = null;
private Connection $defaultConnection;
private bool $isInitialized = false;
private LoggerInterface $logger;
private array $waitingForInsert = [];
public function __construct(Connection $defaultConnection, LoggerInterface $logger)
public function __construct(private Connection $defaultConnection, private LoggerInterface $logger)
{
$this->defaultConnection = $defaultConnection;
$this->logger = $logger;
}
public function finalize(): void

View File

@@ -20,17 +20,8 @@ use function is_int;
class AddressReferenceFromBano
{
private AddressReferenceBaseImporter $baseImporter;
private AddressToReferenceMatcher $addressToReferenceMatcher;
private HttpClientInterface $client;
public function __construct(HttpClientInterface $client, AddressReferenceBaseImporter $baseImporter, AddressToReferenceMatcher $addressToReferenceMatcher)
public function __construct(private HttpClientInterface $client, private AddressReferenceBaseImporter $baseImporter, private AddressToReferenceMatcher $addressToReferenceMatcher)
{
$this->client = $client;
$this->baseImporter = $baseImporter;
$this->addressToReferenceMatcher = $addressToReferenceMatcher;
}
public function import(string $departementNo): void

View File

@@ -21,10 +21,6 @@ use Psr\Log\LoggerInterface;
*/
final class AddressToReferenceMatcher
{
private Connection $connection;
private LoggerInterface $logger;
private const LOG_PREFIX = '[address_to_reference_matcher] ';
private const SQL_MARK_TO_REVIEW_ADDRESS_UNMATCHING = <<<'SQL'
@@ -68,10 +64,8 @@ final class AddressToReferenceMatcher
'{{ reviewed }}' => Address::ADDR_REFERENCE_STATUS_REVIEWED
];
public function __construct(Connection $connection, LoggerInterface $logger)
public function __construct(private Connection $connection, private LoggerInterface $logger)
{
$this->connection = $connection;
$this->logger = $logger;
}
public function checkAddressesMatchingReferences(): void

View File

@@ -43,18 +43,12 @@ final class GeographicalUnitBaseImporter
*/
private array $cachingStatements = [];
private Connection $defaultConnection;
private bool $isInitialized = false;
private LoggerInterface $logger;
private array $waitingForInsert = [];
public function __construct(Connection $defaultConnection, LoggerInterface $logger)
public function __construct(private Connection $defaultConnection, private LoggerInterface $logger)
{
$this->defaultConnection = $defaultConnection;
$this->logger = $logger;
}
public function finalize(): void

View File

@@ -21,17 +21,8 @@ class PostalCodeBEFromBestAddress
{
private const RELEASE = 'https://gitea.champs-libres.be/api/v1/repos/Chill-project/belgian-bestaddresses-transform/releases/tags/v1.0.0';
private PostalCodeBaseImporter $baseImporter;
private HttpClientInterface $client;
private LoggerInterface $logger;
public function __construct(PostalCodeBaseImporter $baseImporter, HttpClientInterface $client, LoggerInterface $logger)
public function __construct(private PostalCodeBaseImporter $baseImporter, private HttpClientInterface $client, private LoggerInterface $logger)
{
$this->baseImporter = $baseImporter;
$this->client = $client;
$this->logger = $logger;
}
public function import(string $lang = 'fr'): void

View File

@@ -55,14 +55,10 @@ class PostalCodeBaseImporter
*/
private array $cachingStatements = [];
private Connection $defaultConnection;
private array $waitingForInsert = [];
public function __construct(
Connection $defaultConnection
) {
$this->defaultConnection = $defaultConnection;
public function __construct(private Connection $defaultConnection)
{
}
public function finalize(): void

View File

@@ -26,20 +26,8 @@ class PostalCodeFRFromOpenData
{
private const CSV = 'https://datanova.legroupe.laposte.fr/explore/dataset/laposte_hexasmal/download/?format=csv&timezone=Europe/Berlin&lang=fr&use_labels_for_header=true&csv_separator=%3B';
private PostalCodeBaseImporter $baseImporter;
private HttpClientInterface $client;
private LoggerInterface $logger;
public function __construct(
PostalCodeBaseImporter $baseImporter,
HttpClientInterface $client,
LoggerInterface $logger
) {
$this->baseImporter = $baseImporter;
$this->client = $client;
$this->logger = $logger;
public function __construct(private PostalCodeBaseImporter $baseImporter, private HttpClientInterface $client, private LoggerInterface $logger)
{
}
public function import(): void
@@ -86,7 +74,7 @@ class PostalCodeFRFromOpenData
$ref = trim($record['Code_commune_INSEE']);
if ('987' === substr($ref, 0, 3)) {
if (str_starts_with($ref, '987')) {
// some differences in French Polynesia
$ref .= '.' . trim($record['Libellé_d_acheminement']);
}

View File

@@ -20,16 +20,10 @@ use Symfony\Component\Mime\RawMessage;
class ChillMailer implements MailerInterface
{
private LoggerInterface $chillLogger;
private MailerInterface $initial;
private string $prefix = '[Chill] ';
public function __construct(MailerInterface $initial, LoggerInterface $chillLogger)
public function __construct(private MailerInterface $initial, private LoggerInterface $chillLogger)
{
$this->initial = $initial;
$this->chillLogger = $chillLogger;
}
public function send(RawMessage $message, ?Envelope $envelope = null): void

View File

@@ -63,25 +63,19 @@ class RollingDate
public const T_YEAR_PREVIOUS_START = 'year_previous_start';
private ?DateTimeImmutable $fixedDate;
/**
* The pivot date is the date from the rolling is computed. By default, it is "now".
*/
private DateTimeImmutable $pivotDate;
private string $roll;
/**
* @param string|self::T_* $roll
* @param DateTimeImmutable|null $pivotDate Will be "now" if null is given
* @param DateTimeImmutable|null $fixedDate Only to insert if $roll equals @see{self::T_FIXED_DATE}
*/
public function __construct(string $roll, ?DateTimeImmutable $fixedDate = null, ?DateTimeImmutable $pivotDate = null)
public function __construct(private string $roll, private ?\DateTimeImmutable $fixedDate = null, ?DateTimeImmutable $pivotDate = null)
{
$this->roll = $roll;
$this->pivotDate = $pivotDate ?? new DateTimeImmutable('now');
$this->fixedDate = $fixedDate;
}
public function getFixedDate(): ?DateTimeImmutable

View File

@@ -82,38 +82,13 @@ class RollingDateConverter implements RollingDateConverterInterface
private function toBeginOfQuarter(DateTimeImmutable $date): DateTimeImmutable
{
switch ((int) $date->format('n')) {
case 1:
case 2:
case 3:
$month = '01';
break;
case 4:
case 5:
case 6:
$month = '04';
break;
case 7:
case 8:
case 9:
$month = '07';
break;
case 10:
case 11:
case 12:
$month = '10';
break;
default:
throw new LogicException('this month is not valid: ' . $date->format('n'));
}
$month = match ((int) $date->format('n')) {
1, 2, 3 => '01',
4, 5, 6 => '04',
7, 8, 9 => '07',
10, 11, 12 => '10',
default => throw new LogicException('this month is not valid: ' . $date->format('n')),
};
return DateTimeImmutable::createFromFormat(
'Y-m-d His',

View File

@@ -26,17 +26,8 @@ class ShortMessage
public const PRIORITY_MEDIUM = 'medium';
private string $content;
private PhoneNumber $phoneNumber;
private string $priority = 'low';
public function __construct(string $content, PhoneNumber $phoneNumber, string $priority = 'low')
public function __construct(private string $content, private PhoneNumber $phoneNumber, private string $priority = 'low')
{
$this->content = $content;
$this->phoneNumber = $phoneNumber;
$this->priority = $priority;
}
public function getContent(): string

View File

@@ -25,11 +25,8 @@ use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
*/
class ShortMessageHandler implements MessageHandlerInterface
{
private ShortMessageTransporterInterface $messageTransporter;
public function __construct(ShortMessageTransporterInterface $messageTransporter)
public function __construct(private ShortMessageTransporterInterface $messageTransporter)
{
$this->messageTransporter = $messageTransporter;
}
public function __invoke(ShortMessage $message): void

View File

@@ -20,12 +20,8 @@ namespace Chill\MainBundle\Service\ShortMessage;
class ShortMessageTransporter implements ShortMessageTransporterInterface
{
private ShortMessageSenderInterface $sender;
public function __construct(
ShortMessageSenderInterface $sender // hint: must remain at place 0 for DI
) {
$this->sender = $sender;
public function __construct(private ShortMessageSenderInterface $sender)
{
}
public function send(ShortMessage $shortMessage): void

View File

@@ -27,28 +27,16 @@ use Psr\Log\LoggerInterface;
class OvhShortMessageSender implements ShortMessageSenderInterface
{
private Api $api;
private LoggerInterface $logger;
private PhoneNumberUtil $phoneNumberUtil;
private string $sender;
private string $serviceName;
public function __construct(
Api $api, // for DI, must remains as first argument
string $serviceName, // for di, must remains as second argument
string $sender, // for DI, must remains as third argument
LoggerInterface $logger,
PhoneNumberUtil $phoneNumberUtil
private Api $api,
// for DI, must remains as first argument
private string $serviceName,
// for di, must remains as second argument
private string $sender,
// for DI, must remains as third argument
private LoggerInterface $logger,
private PhoneNumberUtil $phoneNumberUtil
) {
$this->api = $api;
$this->serviceName = $serviceName;
$this->sender = $sender;
$this->logger = $logger;
$this->phoneNumberUtil = $phoneNumberUtil;
}
public function send(ShortMessage $shortMessage): void