Skip to content

Commit e8d2c54

Browse files
committed
Update code with rector
1 parent 3447e1b commit e8d2c54

7 files changed

Lines changed: 16 additions & 25 deletions

File tree

rector.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
SetList::DEAD_CODE,
2020
SetList::TYPE_DECLARATION,
2121
])
22+
->withImportNames()
2223
->withPhpVersion(PhpVersion::PHP_84)
2324
->withComposerBased(symfony: true)
2425
->withSkip([

src/Form/DataTransformer/NodeDataTransformer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function transform(mixed $value): mixed
5454

5555
return $data;
5656
} catch (ReflectionException $e) {
57-
throw new TransformationFailedException(sprintf('The "%s" class not exists', is_object($value) ? get_class($value) : $value));
57+
throw new TransformationFailedException(sprintf('The "%s" class not exists', is_object($value) ? get_class($value) : $value), $e->getCode(), $e);
5858
}
5959
}
6060

@@ -95,11 +95,11 @@ public function reverseTransform($value): mixed
9595

9696
return $element;
9797
} catch (ReflectionException $e) {
98-
throw new TransformationFailedException(sprintf('The "%s" class not exists', is_object($value) ? get_class($value) : $value));
98+
throw new TransformationFailedException(sprintf('The "%s" class not exists', is_object($value) ? get_class($value) : $value), $e->getCode(), $e);
9999
}
100100
}
101101

102-
protected function reverseTransformInitialValue($value): mixed
102+
protected function reverseTransformInitialValue(array $value): mixed
103103
{
104104
$className = $this->nodeDiscriminator->getClassNameForDiscriminator($value[$this->discriminatorField]);
105105

@@ -111,7 +111,7 @@ protected function reverseTransformInitialValue($value): mixed
111111
}
112112

113113
return $element;
114-
} elseif ('array' == $className) {
114+
} elseif ('array' === $className) {
115115
return [];
116116
}
117117

src/Form/Discriminator/DoctrineNodeDiscriminator.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,15 @@ public function getClassNameForDiscriminator($discriminator): string
2828
return $this->em->getClassMetadata($this->abstractClass)->discriminatorMap[$discriminator];
2929
}
3030

31-
public function getIdFieldForObject($object)
31+
public function getIdFieldForObject($object): null
3232
{
3333
$classMetadata = $this->em->getClassMetadata(get_class($object));
3434

35-
if (sizeof($classMetadata->identifier) > 1) {
35+
if (count($classMetadata->identifier) > 1) {
3636
throw new RuntimeException('DoctrinePolymorphicCollection only supports entities with one identity field');
3737
}
3838

39-
$idField = $classMetadata->identifier[0];
40-
41-
return $idField;
39+
return $classMetadata->identifier[0];
4240
}
4341

4442
public function findObjectById($className, $id): ?object

src/Form/Discriminator/NodeDiscriminator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function getDiscriminatorForObject($object): string
5555
return $discr;
5656
}
5757

58-
public function getIdFieldForObject($object)
58+
public function getIdFieldForObject($object): null
5959
{
6060
return null;
6161
}

src/Form/EventListener/NodesResizeFormListener.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static function getSubscribedEvents(): array
3939
/**
4040
* Before data is set, add the existing collection subforms.
4141
*/
42-
public function preSetData(FormEvent $event)
42+
public function preSetData(FormEvent $event): void
4343
{
4444
$nodes = $event->getData() ?? [];
4545
$form = $event->getForm();
@@ -55,7 +55,7 @@ public function preSetData(FormEvent $event)
5555
/**
5656
* After submitted data is set (and before validation), add the new collection subforms.
5757
*/
58-
public function preSubmit(FormEvent $event)
58+
public function preSubmit(FormEvent $event): void
5959
{
6060
$nodes = $event->getData();
6161
$form = $event->getForm();
@@ -73,11 +73,11 @@ public function preSubmit(FormEvent $event)
7373
}
7474
}
7575

76-
protected function addSubform($name, string $discr, FormInterface $form)
76+
protected function addSubform(self|string $name, string $discr, FormInterface $form)
7777
{
7878
$formClass = $this->nodeDiscriminator->getFormTypeFromDiscriminator($discr);
7979

80-
if (empty($formClass)) {
80+
if ('' === $formClass || '0' === $formClass) {
8181
throw new RuntimeException(sprintf('No form type was found for %s discriminator value', $discr));
8282
}
8383

src/Form/Type/DoctrinePolymorphicCollectionType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected function getEntityManager(array $options): EntityManagerInterface
5959
}
6060

6161
return $options['entity_manager'];
62-
} elseif ($this->em) {
62+
} elseif ($this->em instanceof EntityManagerInterface) {
6363
return $this->em;
6464
}
6565

src/Form/Type/PolymorphicCollectionType.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Softspring\Component\PolymorphicFormType\Form\DataTransformer\NodeDataTransformer;
66
use Softspring\Component\PolymorphicFormType\Form\Discriminator\NodeDiscriminator;
77
use Softspring\Component\PolymorphicFormType\Form\EventListener\NodesResizeFormListener;
8-
use Softspring\Component\PolymorphicFormType\Form\Type\Node\AbstractNodeType;
98
use Symfony\Component\Form\AbstractType;
109
use Symfony\Component\Form\Exception\RuntimeException;
1110
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
@@ -71,14 +70,7 @@ public function buildView(FormView $view, FormInterface $form, array $options):
7170
$prototypes = [];
7271

7372
foreach ($options['types_map'] as $discr => $formClass) {
74-
/* @var AbstractNodeType $formType */
75-
if (is_object($formClass)) {
76-
$formType = $formClass;
77-
} elseif (class_exists($formClass)) {
78-
$formType = $formClass;
79-
} else {
80-
$formType = $formClass;
81-
}
73+
$formType = $formClass;
8274

8375
$formOptions = $options['types_options'][$discr] ?? [];
8476
$formOptions['discriminator_field'] = $options['discriminator_field'];
@@ -103,7 +95,7 @@ protected function getFormFactory(array $options): FormFactory
10395
}
10496

10597
return $options['form_factory'];
106-
} elseif ($this->formFactory) {
98+
} elseif ($this->formFactory instanceof FormFactory) {
10799
return $this->formFactory;
108100
}
109101

0 commit comments

Comments
 (0)