Skip to content

Commit

Permalink
Add more type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Feb 9, 2025
1 parent ce2b797 commit 4e680ca
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/Action/RequestResetAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ private function getFlashBag(Request $request): ?FlashBagInterface
return $session->getFlashBag();
}

/**
* @return FormInterface<mixed>
*/
private function createForm(): FormInterface
{
return $this->formFactory
Expand Down
3 changes: 3 additions & 0 deletions src/Action/UpdateSecurityAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ public function __invoke(Request $request): Response
]));
}

/**
* @return FormInterface<UserInterface>
*/
private function createForm(UserInterface $model): FormInterface
{
return $this->formFactory
Expand Down
12 changes: 12 additions & 0 deletions src/Event/FormEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,32 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\EventDispatcher\Event;

/**
* @template T
*/
class FormEvent extends Event
{
/**
* @var FormInterface<T>
*/
private readonly FormInterface $form;

private readonly Request $request;

private ?Response $response = null;

/**
* @param FormInterface<T> $form
*/
public function __construct(FormInterface $form, Request $request)
{
$this->form = $form;
$this->request = $request;
}

/**
* @return FormInterface<T>
*/
public function getForm(): FormInterface
{
return $this->form;
Expand Down
7 changes: 3 additions & 4 deletions src/EventListener/ResettingListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ public function onResettingResetInitialize(GetResponseUserEvent $event): void
}
}

/**
* @param FormEvent<Resetting> $event
*/
public function onResettingResetSuccess(FormEvent $event): void
{
$model = $event->getForm()->getData();

if (!$model instanceof Resetting) {
return;
}

$user = $model->getUser();

$user->setConfirmationToken(null);
Expand Down
3 changes: 3 additions & 0 deletions src/Form/Type/AccountDeletionFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;
use Symfony\Component\Validator\Constraints\NotBlank;

/**
* @extends AbstractType<AccountDeletion>
*/
final class AccountDeletionFormType extends AbstractType
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Form/Type/LoginFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* @extends AbstractType<mixed>
*/
final class LoginFormType extends AbstractType
{
private readonly AuthenticationUtils $authenticationUtils;
Expand Down
3 changes: 3 additions & 0 deletions src/Form/Type/RequestPasswordFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @extends AbstractType<mixed>
*/
final class RequestPasswordFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
Expand Down
3 changes: 3 additions & 0 deletions src/Form/Type/ResettingFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @extends AbstractType<Resetting>
*/
final class ResettingFormType extends AbstractType
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Form/Type/UpdateSecurityFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;
use Symfony\Component\Validator\Constraints\NotBlank;

/**
* @extends AbstractType<UserInterface>
*/
final class UpdateSecurityFormType extends AbstractType
{
/**
Expand Down
6 changes: 3 additions & 3 deletions tests/App/Entity/TestUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Nucleos\UserBundle\Model\GroupInterface;
use Nucleos\UserBundle\Model\User;

/**
* @phpstan-extends User<GroupInterface>
* @phpstan-extends User<TestGroup>
*/
#[ORM\Entity]
#[ORM\Table(name: 'user__user')]
Expand All @@ -31,11 +30,12 @@ class TestUser extends User
protected int $id;

/**
* @var Collection<array-key, GroupInterface>
* @var Collection<array-key, TestGroup>
*/
#[ORM\ManyToMany(targetEntity: TestGroup::class)]
#[ORM\JoinTable(name: 'user__user_group')]
protected Collection $groups;

private static int $index = 1;

public function __construct()
Expand Down

0 comments on commit 4e680ca

Please sign in to comment.