Skip to content

Commit

Permalink
Fixed compatibility with symfony/forms ^6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
zmitic committed Jan 4, 2024
1 parent 0372122 commit ec35ce2
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 34 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
"php": "^7.1 || ^8.0",
"ext-simplexml": "*",
"symfony/framework-bundle": "^4.0 || ^5.0 || ^6.0",
"vimeo/psalm": "^4.12"
"vimeo/psalm": "^5"
},
"require-dev": {
"symfony/form": "^4.0 || ^5.0 || ^6.0",
"symfony/form": "^6.4",
"doctrine/annotations": "^1.8",
"doctrine/orm": "^2.7",
"phpunit/phpunit": "~7.5 || ~9.5",
Expand Down
22 changes: 22 additions & 0 deletions src/Stubs/common/Component/Form/AbstractType.stubphp
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,26 @@ namespace Symfony\Component\Form;
*/
abstract class AbstractType implements FormTypeInterface
{
/**
* @param FormBuilderInterface<T> $builder
*
* @return void
*/
public function buildForm(FormBuilderInterface $builder, array $options){}

/**
* @param FormInterface<T> $form
* @param FormView<T> $view
*
* @return void
*/
public function buildView(FormView $view, FormInterface $form, array $options){}

/**
* @param FormInterface<T> $form
* @param FormView<T> $view
*
* @return void
*/
public function finishView(FormView $view, FormInterface $form, array $options){}
}
24 changes: 24 additions & 0 deletions src/Stubs/common/Component/Form/AbstractTypeExtension.stubphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,34 @@

namespace Symfony\Component\Form;

use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @template T
* @implements FormTypeExtensionInterface<T>
*/
abstract class AbstractTypeExtension implements FormTypeExtensionInterface
{
/**
* @param FormBuilderInterface<T> $builder
*
* @return void
*/
public function buildForm(FormBuilderInterface $builder, array $options){}

/**
* @param FormInterface<T> $form
* @param FormView<T> $view
*
* @return void
*/
public function buildView(FormView $view, FormInterface $form, array $options){}

/**
* @param FormInterface<T> $form
* @param FormView<T> $view
*
* @return void
*/
public function finishView(FormView $view, FormInterface $form, array $options){}
}
1 change: 1 addition & 0 deletions src/Stubs/common/Component/Form/Form.stubphp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Symfony\Component\Form;
/**
* @template T
* @implements FormInterface<T>
* @implements \IteratorAggregate<string, FormInterface>
*/
class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use Symfony\Component\Form\FormTypeInterface;

/**
* @template T
* @template-extends \Traversable<string, FormBuilderInterface>
* @template-extends FormConfigBuilderInterface<T>
*/
interface FormBuilderInterface extends \Traversable, \Countable, FormConfigBuilderInterface
Expand Down
2 changes: 2 additions & 0 deletions src/Stubs/common/Component/Form/FormInterface.stubphp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace Symfony\Component\Form;
/**
* @template T
* @method void clearErrors(bool $deep)
* @extends \ArrayAccess<string, FormInterface>
* @extends \Traversable<string, FormInterface>
*/
interface FormInterface extends \ArrayAccess, \Traversable, \Countable
{
Expand Down
35 changes: 18 additions & 17 deletions src/Stubs/common/Component/Form/FormTypeExtensionInterface.stubphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,32 @@

namespace Symfony\Component\Form;

use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @template T
*/
interface FormTypeExtensionInterface
{
/**
* @psalm-param FormBuilderInterface<T> $builder
* @return iterable<class-string<FormTypeInterface>>
*/
public function buildForm(FormBuilderInterface $builder, array $options);
public static function getExtendedTypes();

/**
* @psalm-param FormView<T> $view
* @psalm-param FormInterface<T> $form
*/
public function buildView(FormView $view, FormInterface $form, array $options);
/**
* @psalm-param FormBuilderInterface<T> $builder
*/
public function buildForm(FormBuilderInterface $builder, array $options);

/**
* @psalm-param FormView<T> $view
* @psalm-param FormInterface<T> $form
* @psalm-param array<array-key, mixed> $options
*/
public function finishView(FormView $view, FormInterface $form, array $options);
/**
* @psalm-param FormView<T> $view
* @psalm-param FormInterface<T> $form
*/
public function buildView(FormView $view, FormInterface $form, array $options);

/**
* @psalm-return iterable<class-string<FormTypeInterface>>
*/
public static function getExtendedTypes();
/**
* @psalm-param FormView<T> $view
* @psalm-param FormInterface<T> $form
*/
public function finishView(FormView $view, FormInterface $form, array $options);
}
1 change: 0 additions & 1 deletion src/Stubs/common/Component/Form/FormTypeInterface.stubphp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ interface FormTypeInterface
/**
* @psalm-param FormView<T> $view
* @psalm-param FormInterface<T> $form
* @psalm-param array<array-key, mixed> $options
*/
public function finishView(FormView $view, FormInterface $form, array $options);
}
15 changes: 7 additions & 8 deletions src/Stubs/common/Component/Form/FormView.stubphp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ use Symfony\Component\Form\Exception\BadMethodCallException;

/**
* @template T
* @implements \ArrayAccess<int|string, FormView>
* @implements \IteratorAggregate<int|string, FormView>
*/
class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
{
/**
* @psalm-suppress MixedArrayAssignment
* @psalm-suppress InvalidArrayOffset
*
* @psalm-var array{value: ?T, attr: array<array-key, mixed>}&array<string, mixed>
*/
public array $vars = [
/**
* @psalm-var array{value: ?T, attr: array<string, mixed>, ...}
*/
public $vars = [
'value' => null,
'attr' => [],
];
Expand All @@ -26,7 +25,7 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
public $parent;

/**
* @psalm-var array<string, FormView>
* @psalm-var array<int|string, FormView>
*/
public $children = [];
}
11 changes: 5 additions & 6 deletions tests/acceptance/acceptance/forms/FormView.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ Feature: Form view
"""
When I run Psalm
Then I see these errors
| Type | Message |
| Trace | $parentView: Symfony\Component\Form\FormView\|null |
| Trace | $children: array<string, Symfony\Component\Form\FormView> |
| Trace | $viewData: User\|null |
| Trace | $attr: array<array-key, mixed> |
| Type | Message |
| Trace | $parentView: Symfony\Component\Form\FormView\|null |
| Trace | $children: array<int\|string, Symfony\Component\Form\FormView |
| Trace | $viewData: User\|null |
| Trace | $attr: array<string, mixed> |
And I see no other errors

0 comments on commit ec35ce2

Please sign in to comment.