Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 24 additions & 78 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,18 +655,6 @@
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/CompanyMembership/AbstractCompanyReminder.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$email of method AppBundle\\\\Association\\\\Model\\\\SubscriptionReminderLog\\:\\:setEmail\\(\\) expects string, mixed given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/CompanyMembership/AbstractCompanyReminder.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$userId of method AppBundle\\\\Association\\\\Model\\\\SubscriptionReminderLog\\:\\:setUserId\\(\\) expects int, mixed given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/CompanyMembership/AbstractCompanyReminder.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Association\\\\CompanyMembership\\\\CompanyReminderFactory\\:\\:getReminder\\(\\) has parameter \\$class with no type specified\\.$#',
'identifier' => 'missingType.parameter',
Expand Down Expand Up @@ -1189,60 +1177,6 @@
'count' => 5,
'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Binary operation "\\*" between int and mixed results in an error\\.$#',
'identifier' => 'binaryOp.invalid',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/SubscriptionReminderLogRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Binary operation "\\+" between mixed and 1 results in an error\\.$#',
'identifier' => 'binaryOp.invalid',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/SubscriptionReminderLogRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot cast mixed to int\\.$#',
'identifier' => 'cast.int',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/SubscriptionReminderLogRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Association\\\\Model\\\\Repository\\\\SubscriptionReminderLogRepository\\:\\:getPaginatedLogs\\(\\) has no return type specified\\.$#',
'identifier' => 'missingType.return',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/SubscriptionReminderLogRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Association\\\\Model\\\\Repository\\\\SubscriptionReminderLogRepository\\:\\:getPaginatedLogs\\(\\) has parameter \\$limit with no type specified\\.$#',
'identifier' => 'missingType.parameter',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/SubscriptionReminderLogRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Association\\\\Model\\\\Repository\\\\SubscriptionReminderLogRepository\\:\\:getPaginatedLogs\\(\\) has parameter \\$page with no type specified\\.$#',
'identifier' => 'missingType.parameter',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/SubscriptionReminderLogRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Association\\\\Model\\\\Repository\\\\SubscriptionReminderLogRepository\\:\\:initMetadata\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#',
'identifier' => 'missingType.iterableValue',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/SubscriptionReminderLogRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Association\\\\Model\\\\Repository\\\\SubscriptionReminderLogRepository\\:\\:initMetadata\\(\\) should return M of CCMBenchmark\\\\Ting\\\\Repository\\\\Metadata but returns CCMBenchmark\\\\Ting\\\\Repository\\\\Metadata\\<object\\>\\.$#',
'identifier' => 'return.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/SubscriptionReminderLogRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$databaseName of method CCMBenchmark\\\\Ting\\\\Repository\\\\Metadata\\<object\\>\\:\\:setDatabase\\(\\) expects string, mixed given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/SubscriptionReminderLogRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Association\\\\Model\\\\Repository\\\\SubscriptionRepository\\:\\:initMetadata\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#',
'identifier' => 'missingType.iterableValue',
Expand Down Expand Up @@ -1681,18 +1615,6 @@
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/UserMembership/AbstractUserReminder.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$email of method AppBundle\\\\Association\\\\Model\\\\SubscriptionReminderLog\\:\\:setEmail\\(\\) expects string, mixed given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/UserMembership/AbstractUserReminder.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$userId of method AppBundle\\\\Association\\\\Model\\\\SubscriptionReminderLog\\:\\:setUserId\\(\\) expects int, mixed given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/UserMembership/AbstractUserReminder.php',
];
$ignoreErrors[] = [
'message' => '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#',
'identifier' => 'foreach.nonIterable',
Expand Down Expand Up @@ -9931,5 +9853,29 @@
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/VideoNotifier/StatusGenerator.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot cast mixed to string\\.$#',
'identifier' => 'cast.string',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/CompanyMembership/AbstractCompanyReminder.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot cast mixed to int\\.$#',
'identifier' => 'cast.int',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/CompanyMembership/AbstractCompanyReminder.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot cast mixed to string\\.$#',
'identifier' => 'cast.string',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/UserMembership/AbstractUserReminder.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot cast mixed to int\\.$#',
'identifier' => 'cast.int',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Association/UserMembership/AbstractUserReminder.php',
];

return ['parameters' => ['ignoreErrors' => $ignoreErrors]];
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use AppBundle\Association\MembershipReminderInterface;
use AppBundle\Association\MemberType;
use AppBundle\Association\Model\Repository\SubscriptionReminderLogRepository;
use AppBundle\Association\Model\SubscriptionReminderLog;
use AppBundle\Association\Entity\Repository\SubscriptionReminderLogRepository;
use AppBundle\Association\Entity\SubscriptionReminderLog;
use AppBundle\Association\NotifiableInterface;
use AppBundle\Email\Mailer\Attachment;
use AppBundle\Email\Mailer\Mailer;
Expand All @@ -31,13 +31,11 @@ abstract protected function getKey(): string;
public function sendReminder(NotifiableInterface $user): void
{
$log = new SubscriptionReminderLog();
$log
->setEmail($user->getEmail())
->setUserId($user->getId())
->setReminderDate(new \DateTime())
->setReminderKey($this->getKey())
->setUserType(MemberType::MemberCompany->value)
;
$log->email = (string) $user->getEmail();
$log->userId = (int) $user->getId();
$log->reminderDate = new \DateTimeImmutable();
$log->reminderKey = $this->getKey();
$log->userType = MemberType::MemberCompany;

$message = new Message($this->getSubject(), MailUserFactory::sponsors(), new MailUser($user->getEmail()));

Expand All @@ -49,7 +47,7 @@ public function sendReminder(NotifiableInterface $user): void
));

$status = $this->mailer->sendTransactional($message, $this->getText());
$log->setMailSent($status);
$log->mailSent = $status;
$this->subscriptionReminderLogRepository->save($log);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace AppBundle\Association\CompanyMembership;

use AppBundle\Association\MembershipReminderInterface;
use AppBundle\Association\Model\Repository\SubscriptionReminderLogRepository;
use AppBundle\Association\Entity\Repository\SubscriptionReminderLogRepository;
use AppBundle\Email\Mailer\Mailer;

class CompanyReminderFactory
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

declare(strict_types=1);

namespace AppBundle\Association\Entity\Repository;

use AppBundle\Association\Entity\SubscriptionReminderLog;
use AppBundle\Association\Entity\SubscriptionReminderLogEntry;
use AppBundle\Doctrine\EntityRepository;
use CuyZ\Valinor\Mapper\Configurator\ConvertKeysToCamelCase;
use CuyZ\Valinor\Mapper\Source\Source;
use CuyZ\Valinor\MapperBuilder;
use Doctrine\DBAL\Connection;
use Doctrine\Persistence\ManagerRegistry;

/**
* @extends EntityRepository<SubscriptionReminderLog>
*/
class SubscriptionReminderLogRepository extends EntityRepository
{
private const int DEFAULT_LIMIT = 50;

public function __construct(
ManagerRegistry $registry,
private readonly MapperBuilder $mapperBuilder,
) {
parent::__construct($registry, SubscriptionReminderLog::class);
}

/**
* @param int $limit Nombre d'éléments de la page ; un élément supplémentaire
* est remonté pour savoir s'il existe une page suivante
* @return list<SubscriptionReminderLogEntry>
*/
public function getPaginatedLogs(int $page = 1, int $limit = self::DEFAULT_LIMIT): array
{
$rows = $this->connection()
->createQueryBuilder()
->select(
'asrl.id',
'asrl.reminder_key',
'asrl.reminder_date',
'asrl.mail_sent',
'app.id AS app_id',
'app.nom',
'app.prenom',
'apm.id AS apm_id',
'apm.raison_sociale',
)
->from('afup_subscription_reminder_log', 'asrl')
->leftJoin('asrl', 'afup_personnes_physiques', 'app', 'app.id = asrl.user_id')
->leftJoin('app', 'afup_personnes_morales', 'apm', 'apm.id = app.id_personne_morale')
->orderBy('asrl.reminder_date', 'DESC')
->setFirstResult(($page - 1) * $limit)
->setMaxResults($limit + 1)
->executeQuery()
->fetchAllAssociative()
;

$entries = [];
foreach ($rows as $row) {
$entries[] = $this->mapperBuilder
// mail_sent est un tinyint en base : Valinor exige
// l'autorisation de cast pour mapper un int vers un bool.
->allowScalarValueCasting()
->supportDateFormats('Y-m-d H:i:s')
->configureWith(new ConvertKeysToCamelCase())
->mapper()
->map(SubscriptionReminderLogEntry::class, Source::array($row));
}

return $entries;
}

private function connection(): Connection
{
return $this->getEntityManager()->getConnection();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace AppBundle\Association\Entity;

use AppBundle\Association\MemberType;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'afup_subscription_reminder_log')]
class SubscriptionReminderLog
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
public ?int $id = null;

#[ORM\Column]
public int $userId;

#[ORM\Column(enumType: MemberType::class)]
public MemberType $userType;

#[ORM\Column(length: 255)]
public string $email;

#[ORM\Column(length: 30)]
public string $reminderKey;

#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
public \DateTimeImmutable $reminderDate;

#[ORM\Column]
public bool $mailSent = false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace AppBundle\Association\Entity;

use DateTimeImmutable;

final readonly class SubscriptionReminderLogEntry
{
public function __construct(
public int $id,
public ?string $nom,
public ?string $prenom,
public ?int $appId,
public ?int $apmId,
public ?string $raisonSociale,
public string $reminderKey,
public DateTimeImmutable $reminderDate,
public bool $mailSent,
) {}
}
Loading
Loading