Skip to content

Commit 9a7f96a

Browse files
committed
[TypeDeclaration] Skip callback with instanceof check on ParamTypeByMethodCallTypeRector (part 2)
1 parent d349cfd commit 9a7f96a

1 file changed

Lines changed: 37 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 SkipInFormBuilderCallbackInstanceof 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 instanceof SomeType) {
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+
}

0 commit comments

Comments
 (0)