Skip to content

Commit

Permalink
Allow symfony 7
Browse files Browse the repository at this point in the history
  • Loading branch information
ropczan committed Jun 6, 2024
1 parent 445ccba commit c3194b5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
composer.lock
coverage/
.phpunit.result.cache
.idea/
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
},
"require": {
"php": "^7.4|^8.0",
"symfony/form": "^5.4|^6.0",
"symfony/translation": "^5.4|^6.0",
"symfony/serializer": "^5.4|^6.0",
"symfony/validator": "^5.4|^6.0"
"symfony/form": "^5.4|^6.0|^7.0",
"symfony/translation": "^5.4|^6.0|^7.0",
"symfony/serializer": "^5.4|^6.0|^7.0",
"symfony/validator": "^5.4|^6.0|^7.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^v0.7.2",
Expand Down
2 changes: 1 addition & 1 deletion src/Limenius/Liform/Form/Extension/AddLiformExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function getExtendedTypes(): iterable
*
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefined(['liform']);
}
Expand Down
12 changes: 10 additions & 2 deletions src/Limenius/Liform/Serializer/Normalizer/FormErrorNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(TranslatorInterface $translator)
/**
* {@inheritdoc}
*/
public function normalize($object, $format = null, array $context = [])
public function normalize(mixed $object, ?string $format = null, array $context = []): float|array|\ArrayObject|bool|int|string|null

Check failure on line 42 in src/Limenius/Liform/Serializer/Normalizer/FormErrorNormalizer.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4)

Method Limenius\Liform\Serializer\Normalizer\FormErrorNormalizer::normalize() uses native union types but they're supported only on PHP 8.0 and later.
{
return [
'code' => isset($context['status_code']) ? $context['status_code'] : null,
Expand All @@ -51,11 +51,19 @@ public function normalize($object, $format = null, array $context = [])
/**
* {@inheritdoc}
*/
public function supportsNormalization($data, $format = null)
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
{
return $data instanceof FormInterface && $data->isSubmitted() && !$data->isValid();
}

/**
* {@inheritdoc}
*/
public function getSupportedTypes(?string $format): array
{
return ['object' => true];
}

/**
* This code has been taken from JMSSerializer.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,34 @@ class InitialValuesNormalizer implements NormalizerInterface
/**
* {@inheritdoc}
*/
public function normalize($form, $format = null, array $context = [])
public function normalize($object, $format = null, array $context = []): float|array|\ArrayObject|bool|int|string|null

Check failure on line 30 in src/Limenius/Liform/Serializer/Normalizer/InitialValuesNormalizer.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4)

Method Limenius\Liform\Serializer\Normalizer\InitialValuesNormalizer::normalize() uses native union types but they're supported only on PHP 8.0 and later.
{
$formView = $form->createView();
$formView = $object->createView();

return $this->getValues($form, $formView);
return $this->getValues($object, $formView);
}

/**
* {@inheritdoc}
*/
public function supportsNormalization($data, $format = null)
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
{
return $data instanceof Form;
}

/**
* {@inheritdoc}
*/
public function getSupportedTypes(?string $format): array
{
return ['object' => true];
}

/**
* Gets the values of the form
* @param Form|FormInterface $form
* @param FormView $formView
*
* @param Form|FormInterface $form
* @param FormView $formView
*
* @return mixed
*/
Expand All @@ -62,7 +71,7 @@ private function getValues(FormInterface $form, FormView $formView)
return $this->normalizeExpandedChoice($formView);
}
// Force serialization as {} instead of []
$data = (object) array();
$data = (object) [];
foreach ($formView->children as $name => $child) {
// Avoid unknown field error when csrf_protection is true
// CSRF token should be extracted another way
Expand All @@ -85,13 +94,14 @@ private function getValues(FormInterface $form, FormView $formView)

/**
* Normalize when choice is multiple
*
* @param FormView $formView
*
* @return array
*/
private function normalizeMultipleExpandedChoice(FormView $formView)
{
$data = array();
$data = [];
foreach ($formView->children as $name => $child) {
if ($child->vars['checked']) {
$data[] = $child->vars['value'];
Expand All @@ -103,6 +113,7 @@ private function normalizeMultipleExpandedChoice(FormView $formView)

/**
* Normalize when choice is expanded
*
* @param FormView $formView
*
* @return mixed
Expand Down

0 comments on commit c3194b5

Please sign in to comment.