Skip to content

Commit a56f44a

Browse files
authored
Forms stubs (#138)
1 parent 2d164b8 commit a56f44a

28 files changed

+865
-2
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"vimeo/psalm": "^4.6.1"
1717
},
1818
"require-dev": {
19+
"symfony/form": "^4.0 || ^5.0",
1920
"doctrine/orm": "^2.7",
2021
"phpunit/phpunit": "~7.5 || ~9.5",
2122
"symfony/cache-contracts": "^1.0 || ^2.0",

src/Plugin.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Psalm\SymfonyPsalmPlugin;
44

5+
use function array_merge;
56
use Doctrine\Common\Annotations\AnnotationRegistry;
67
use Psalm\Exception\ConfigException;
78
use Psalm\Plugin\PluginEntryPointInterface;
@@ -32,7 +33,7 @@ class Plugin implements PluginEntryPointInterface
3233
*/
3334
protected function getCommonStubs(): array
3435
{
35-
return glob(__DIR__.'/Stubs/common/*.stubphp') ?: [];
36+
return glob(__DIR__.'/Stubs/common/{*,*/*}.stubphp', GLOB_BRACE) ?: [];
3637
}
3738

3839
/**
@@ -85,7 +86,8 @@ public function __invoke(RegistrationInterface $api, SimpleXMLElement $config =
8586
$api->registerHooksFromClass(ContainerHandler::class);
8687

8788
$stubs = array_merge(
88-
$this->getCommonStubs(), $this->getStubsForMajorVersion(Kernel::MAJOR_VERSION)
89+
$this->getCommonStubs(),
90+
$this->getStubsForMajorVersion(Kernel::MAJOR_VERSION)
8991
);
9092

9193
foreach ($stubs as $stubFilePath) {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Symfony\Component\Form;
4+
5+
/**
6+
* @template T
7+
* @implements FormTypeInterface<T>
8+
*/
9+
abstract class AbstractType implements FormTypeInterface
10+
{
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Symfony\Component\Form;
4+
5+
/**
6+
* @template T
7+
* @implements FormTypeExtensionInterface<T>
8+
*/
9+
abstract class AbstractTypeExtension implements FormTypeExtensionInterface
10+
{
11+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Symfony\Component\Form;
4+
5+
use Symfony\Component\Form\Exception\TransformationFailedException;
6+
7+
/**
8+
* @template T
9+
* @template R
10+
*/
11+
interface DataTransformerInterface
12+
{
13+
/**
14+
* @psalm-param ?T $value The value in the original representation
15+
*
16+
* @psalm-return ?R The value in the transformed representation
17+
*/
18+
public function transform($value);
19+
20+
/**
21+
* @psalm-param ?R $value The value in the transformed representation
22+
*
23+
* @psalm-return ?T The value in the original representation
24+
*/
25+
public function reverseTransform($value);
26+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Symfony\Component\Form;
4+
5+
/**
6+
* @template T
7+
* @implements FormInterface<T>
8+
*/
9+
class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterface
10+
{
11+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Symfony\Component\Form;
4+
5+
use Symfony\Component\Form\FormTypeInterface;
6+
7+
/**
8+
* @template T
9+
* @template-extends FormConfigBuilderInterface<T>
10+
*/
11+
interface FormBuilderInterface extends \Traversable, \Countable, FormConfigBuilderInterface
12+
{
13+
/**
14+
* @psalm-return FormInterface<T>
15+
*/
16+
public function getForm();
17+
18+
/**
19+
* @psalm-param null|class-string<FormTypeInterface> $type
20+
*/
21+
public function create(string $name, $type = null, array $options = []);
22+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Symfony\Component\Form;
4+
5+
use Symfony\Component\Form\Event\PreSetDataEvent;
6+
use Symfony\Component\Form\Event\PreSubmitEvent;
7+
use Symfony\Component\Form\Event\PostSetDataEvent;
8+
use Symfony\Component\Form\Event\SubmitEvent;
9+
10+
/**
11+
* @template T
12+
* @template-extends FormConfigInterface<T>
13+
*/
14+
interface FormConfigBuilderInterface extends FormConfigInterface
15+
{
16+
/**
17+
* @psalm-return FormConfigInterface<T>
18+
*/
19+
public function getFormConfig();
20+
21+
/**
22+
* @psalm-param FormEvents::* $eventName
23+
*
24+
* @psalm-param callable(PreSetDataEvent<T>)|callable(PostSetDataEvent<T>)|callable(PreSubmitEvent)|callable(SubmitEvent<T>) $listener
25+
*/
26+
public function addEventListener($eventName, $listener, $priority = 0);
27+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Symfony\Component\Form;
4+
5+
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
6+
use Symfony\Component\PropertyAccess\PropertyPathInterface;
7+
8+
/**
9+
* @template T
10+
*/
11+
interface FormConfigInterface
12+
{
13+
/**
14+
* @psalm-return ?T
15+
*/
16+
public function getData();
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Symfony\Component\Form;
4+
5+
use Symfony\Component\EventDispatcher\Event;
6+
7+
/**
8+
* @template T
9+
*/
10+
class FormEvent extends Event
11+
{
12+
/**
13+
* @psalm-return FormInterface<T>
14+
*/
15+
public function getForm() {}
16+
17+
/**
18+
* @psalm-return ?T
19+
*/
20+
public function getData() {}
21+
}

0 commit comments

Comments
 (0)