Skip to content

Commit b488524

Browse files
committed
[TypeDeclaration] Skip Assert\Callback typed on ParamTypeByMethodCallTypeRector
1 parent efb6a4a commit b488524

4 files changed

Lines changed: 91 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector\Fixture;
4+
5+
use Symfony\Component\Form\AbstractType;
6+
use Symfony\Component\Form\FormBuilderInterface;
7+
use Symfony\Component\Validator\Constraints as Assert;
8+
9+
final class SkipInFormBuilderCallback extends AbstractType
10+
{
11+
public function buildForm(FormBuilderInterface $builder, array $options): void
12+
{
13+
$builder->add('someType', DocumentType::class, [
14+
'class' => SomeType::class,
15+
'required' => false,
16+
'label' => 'Some Type',
17+
'attr' => [
18+
'data-help' => 'some data help',
19+
],
20+
'constraints' => [
21+
new Assert\Callback(function ($someType, ExecutionContextInterface $context): void {
22+
if ($someType === null) {
23+
return;
24+
}
25+
26+
$this->use($someType);
27+
28+
// some logic here
29+
})
30+
]
31+
]);
32+
}
33+
34+
private function use(SomeType $someType): void
35+
{
36+
}
37+
}
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+
if (class_exists('Symfony\Component\Form\AbstractType')) {
6+
return;
7+
}
8+
9+
class AbstractType
10+
{
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Symfony\Component\Form;
4+
5+
if (interface_exists('Symfony\Component\Form\FormBuilderInterface')) {
6+
return;
7+
}
8+
9+
class FormBuilderInterface
10+
{
11+
public function add(string|self $child, ?string $type = null, array $options = []): static;
12+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Validator\Constraints;
13+
14+
use Symfony\Component\Validator\Constraint;
15+
16+
if (class_exists('Symfony\Component\Validator\Constraints\Callback')) {
17+
return;
18+
}
19+
20+
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
21+
class Callback
22+
{
23+
/**
24+
* @var string|callable
25+
*/
26+
public $callback;
27+
28+
public function __construct(array|string|callable|null $callback = null, ?array $groups = null, mixed $payload = null, array $options = [])
29+
{
30+
}
31+
}

0 commit comments

Comments
 (0)