Skip to content

Commit

Permalink
Added phpstan symfony.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentmuller committed Jan 28, 2025
1 parent e8f0775 commit 888e51d
Show file tree
Hide file tree
Showing 31 changed files with 189 additions and 59 deletions.
19 changes: 10 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 1 addition & 8 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,10 @@ parameters:
-
message: '#no value type specified#'
identifier: missingType.iterableValue
-
message: '#@extends contains generic type#'
identifier: generics.notGeneric
path: src/Form/Extension/*
-
message: '#Call to static method .* will always evaluate to true.#'
path: tests/*

-
message: '#@extends contains generic type#'
identifier: generics.notGeneric
paths:
- src/Form/*
- tests/Fixture/*
path: src/Form/Extension/*
2 changes: 1 addition & 1 deletion src/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ protected function getParameterString(string $name): string
*
* @template T
*
* @psalm-param FormInterface<T> $form the form to validate
* @psalm-param FormInterface<T> $form the form to validate
*
* @see FormInterface::handleRequest()
* @see FormInterface::isSubmitted()
Expand Down
8 changes: 7 additions & 1 deletion src/Controller/AbstractEntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,17 @@ protected function getDefaultRoute(): string
/**
* Gets the form type class name used to edit an entity.
*
* @phpstan-return class-string<FormTypeInterface<mixed>>
*
* @return class-string<FormTypeInterface>
*/
protected function getEditFormType(): string
{
/** @psalm-var class-string<FormTypeInterface> */
/**
* @phpstan-var class-string<FormTypeInterface<mixed>>
*
* @psalm-var class-string<FormTypeInterface>
*/
return \sprintf('App\\Form\\%1$s\\%1$sType', $this->shortName);
}

Expand Down
3 changes: 3 additions & 0 deletions src/Controller/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use App\Attribute\GetPost;
use App\Entity\User;
use App\Form\AbstractEntityType;
use App\Form\User\ProfileEditType;
use App\Form\User\ProfilePasswordType;
use App\Interfaces\RoleInterface;
Expand Down Expand Up @@ -71,6 +72,8 @@ public function password(#[CurrentUser] User $user, Request $request, PasswordTo
}

/**
* @phpstan-param class-string<AbstractEntityType<User>> $type
*
* @psalm-param class-string $type
*/
private function handleForm(
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/TestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -698,9 +698,9 @@ private function getStates(EntityManagerInterface $manager): array
* @template T of AbstractProperty
*
* @psalm-param AbstractParameters<T> $parameters
* @psalm-param class-string<FormTypeInterface<mixed>> $type
* @psalm-param class-string<FormTypeInterface> $type
*
* @phpstan-param class-string<FormTypeInterface> $type
* @phpstan-param class-string<FormTypeInterface<array>> $type
*/
private function renderParameters(
Request $request,
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Extension/AbstractFileTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* Base extension for FileType.
*
* @psalm-template T of \Symfony\Component\Form\FormTypeInterface
* @template T of \Symfony\Component\Form\FormTypeInterface
*
* @extends AbstractTypeExtension<T>
*/
Expand Down
4 changes: 4 additions & 0 deletions src/Form/Extension/FileTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public static function getExtendedTypes(): iterable
}

/**
* @phpstan-param FormInterface<array> $form
*
* @psalm-param FormInterface $form
*
* @psalm-return array<array-key, mixed>
*/
protected function updateOptions(FormInterface $form, array $options): array
Expand Down
4 changes: 4 additions & 0 deletions src/Form/Parameters/AbstractParameterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ private function convertValue(mixed $value): mixed
}

/**
* @phpstan-param FormInterface<array> $form
*
* @psalm-param FormInterface $form
*
* @psalm-return array<string, mixed>
*/
private function getDefaultValues(FormInterface $form): array
Expand Down
4 changes: 4 additions & 0 deletions src/Form/Task/TaskListType.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public function configureOptions(OptionsResolver $resolver): void
}

/**
* @phpstan-param Options<array> $options
*
* @psalm-param Options $options
*
* @throws \Doctrine\ORM\Exception\NotSupported
*/
private function getSortedBuilder(Options $options): QueryBuilder
Expand Down
10 changes: 10 additions & 0 deletions src/Form/Type/CountryFlagType.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,21 @@ public function getParent(): string
return CountryType::class;
}

/**
* @phpstan-param Options<array> $options
*
* @psalm-param Options $options
*/
private function getChoiceLoader(Options $options): ChoiceLoaderInterface
{
return ChoiceList::lazy($this, fn (): array => $this->loadChoices($options));
}

/**
* @phpstan-param Options<array> $options
*
* @psalm-param Options $options
*/
private function loadChoices(Options $options): array
{
/** @psalm-var string|null $locale */
Expand Down
5 changes: 5 additions & 0 deletions src/Form/Type/ReCaptchaType.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ public function onPostSubmit(PostSubmitEvent $event): void
}
}

/**
* @phpstan-param FormConfigInterface<array> $config
*
* @psalm-param FormConfigInterface $config
*/
private function updateService(FormConfigInterface $config): void
{
if ($config->hasOption('expectedAction')) {
Expand Down
5 changes: 5 additions & 0 deletions src/Form/User/AbstractChangePasswordType.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ private function validate(ExecutionContextInterface $context): void
}
}

/**
* @phpstan-param FormInterface<array> $target
*
* @psalm-param FormInterface $target
*/
private function validateConstraint(
ExecutionContextInterface $context,
Constraint $constraint,
Expand Down
1 change: 1 addition & 0 deletions src/Repository/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* @template-extends AbstractRepository<User>
*
* @implements UserProviderInterface<User>
* @implements PasswordUpgraderInterface<User>
*/
class UserRepository extends AbstractRepository implements PasswordUpgraderInterface, ResetPasswordRequestRepositoryInterface, UserProviderInterface
{
Expand Down
3 changes: 3 additions & 0 deletions tests/Form/Admin/ApplicationParametersTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ protected function getPreloadedExtensions(): array
];
}

/**
* @return TextTypeExtension[]
*/
protected function getTypeExtensions(): array
{
return [
Expand Down
8 changes: 8 additions & 0 deletions tests/Form/EntityTypeTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ protected function getPreloadedExtensions(): array
return [];
}

/**
* @return array{
* FileTypeExtension,
* TextTypeExtension,
* UrlTypeExtension,
* VichImageTypeExtension
* }
*/
protected function getTypeExtensions(): array
{
return [
Expand Down
3 changes: 3 additions & 0 deletions tests/Form/Extension/FileTypeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ protected function createView(array $options = []): FormView
->createView();
}

/**
* @return FileTypeExtension[]
*/
protected function getTypeExtensions(): array
{
return [
Expand Down
3 changes: 3 additions & 0 deletions tests/Form/Extension/TextTypeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public function testFormViewWithNoValue(): void
self::assertArrayNotHasKey('append_class', $attr);
}

/**
* @return TextTypeExtension[]
*/
protected function getTypeExtensions(): array
{
return [
Expand Down
3 changes: 3 additions & 0 deletions tests/Form/Extension/UrlTypeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public function testFormViewWithFtpProtocol(): void
self::assertSame('ftp', $attr['data-protocol']);
}

/**
* @return UrlTypeExtension[]
*/
protected function getTypeExtensions(): array
{
return [
Expand Down
3 changes: 3 additions & 0 deletions tests/Form/Extension/VichImageTypeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ protected function getPreloadedExtensions(): array
];
}

/**
* @return VichImageTypeExtension[]
*/
protected function getTypeExtensions(): array
{
return [
Expand Down
11 changes: 11 additions & 0 deletions tests/Form/FormHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,14 @@ protected function getPreloadedExtensions(): array
];
}

/**
* @return array{
* FileTypeExtension,
* TextTypeExtension,
* UrlTypeExtension,
* VichImageTypeExtension
* }
*/
protected function getTypeExtensions(): array
{
return [
Expand All @@ -690,6 +698,9 @@ private function getFormHelper(?string $labelPrefix = null): FormHelper
return new FormHelper($builder, $labelPrefix);
}

/**
* @phpstan-param FormConfigInterface<mixed> $config
*/
private static function validateAttribute(FormConfigInterface $config, string $option, string $name, mixed $expected): void
{
self::assertTrue($config->hasOption($option));
Expand Down
4 changes: 2 additions & 2 deletions tests/Form/Type/ReCaptchaTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function testSubmitError(): void

self::assertCount(1, $form->getErrors());
$errorForm = $form->getErrors()[0];
self::assertSame($error, $errorForm->getMessage()); // @phpstan-ignore method.notFound
self::assertSame($error, $errorForm->getMessage());
}

public function testSubmitNoRequest(): void
Expand All @@ -103,7 +103,7 @@ public function testSubmitNoRequest(): void

self::assertCount(1, $form->getErrors());
$errorForm = $form->getErrors()[0];
self::assertSame('no-request', $errorForm->getMessage()); // @phpstan-ignore method.notFound
self::assertSame('no-request', $errorForm->getMessage());
}

public function testSubmitSuccess(): void
Expand Down
3 changes: 3 additions & 0 deletions tests/Form/User/RequestChangePasswordTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ protected function getPreloadedExtensions(): array
];
}

/**
* @return TextTypeExtension[]
*/
protected function getTypeExtensions(): array
{
return [
Expand Down
3 changes: 3 additions & 0 deletions tests/Form/User/UserCommentTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ protected function getPreloadedExtensions(): array
];
}

/**
* @return FileTypeExtension[]
*/
protected function getTypeExtensions(): array
{
return [
Expand Down
3 changes: 3 additions & 0 deletions tests/Form/User/UserLoginTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ protected function getPreloadedExtensions(): array
];
}

/**
* @return TextTypeExtension[]
*/
protected function getTypeExtensions(): array
{
return [
Expand Down
3 changes: 3 additions & 0 deletions tests/Form/User/UserParametersTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ protected function getPreloadedExtensions(): array
];
}

/**
* @return TextTypeExtension[]
*/
protected function getTypeExtensions(): array
{
return [
Expand Down
3 changes: 3 additions & 0 deletions tests/Form/User/UserRegistrationTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ protected function getPreloadedExtensions(): array
];
}

/**
* @return TextTypeExtension[]
*/
protected function getTypeExtensions(): array
{
return [
Expand Down
Loading

0 comments on commit 888e51d

Please sign in to comment.