diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 35acac9..b4ab93f 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -6,19 +6,18 @@ on: jobs: phpunit: name: "PHPUnit" - runs-on: "ubuntu-20.04" + runs-on: "ubuntu-24.04" strategy: matrix: php-version: - - "7.4" - - "8.0" - - "8.1" + - "8.2" + - "8.3" deps: - "normal" include: - deps: "low" - php-version: "7.4" + php-version: "8.2" steps: - name: "Checkout" diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 7f7fb9d..4db6e36 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -6,14 +6,13 @@ on: jobs: phpstan: name: "PHPStan" - runs-on: "ubuntu-20.04" + runs-on: "ubuntu-24.04" strategy: matrix: php-version: - - "7.4" - - "8.0" - - "8.1" + - "8.2" + - "8.3" steps: - name: "Checkout" uses: "actions/checkout@v2" diff --git a/composer.json b/composer.json index f575e5e..0a898bd 100644 --- a/composer.json +++ b/composer.json @@ -28,11 +28,12 @@ "symfony/translation-contracts": "^1.0|^2.1|^3.0" }, "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^v0.7.2", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", "escapestudios/symfony2-coding-standard": "^3.0", - "phpunit/phpunit": "^8.0", + "phpunit/phpunit": "^11.4", "phpcompatibility/php-compatibility": "^9.3", - "phpstan/phpstan": "^1.8" + "phpstan/phpstan": "^1.8", + "rector/rector": "^1.2" }, "scripts": { "test": "phpunit", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3414d22..fe80140 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,19 +1,17 @@ - - - - - ./tests/ - - - - - - ./ - - ./Tests - ./vendor - - - + + + + ./tests/ + + + + + ./ + + + ./Tests + ./vendor + + diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..5b1e92f --- /dev/null +++ b/rector.php @@ -0,0 +1,21 @@ +withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + // uncomment to reach your current PHP version + ->withPhpSets(php83: true) + ->withSets([ + PHPUnitSetList::PHPUNIT_110 + ]) + ->withRules([ + AddVoidReturnTypeWhereNoReturnRector::class, + ]); diff --git a/src/Limenius/Liform/FormUtil.php b/src/Limenius/Liform/FormUtil.php index cf5602b..2ceee8d 100644 --- a/src/Limenius/Liform/FormUtil.php +++ b/src/Limenius/Liform/FormUtil.php @@ -27,7 +27,7 @@ class FormUtil public static function typeAncestry(FormInterface $form) { $types = []; - self::typeAncestryForType($form->getConfig()->getType(), $types); + self::typeAncestryForType($types, $form->getConfig()->getType()); return $types; } @@ -38,7 +38,7 @@ public static function typeAncestry(FormInterface $form) * * @return void */ - public static function typeAncestryForType(ResolvedFormTypeInterface $formType = null, array &$types) + public static function typeAncestryForType(array &$types, ResolvedFormTypeInterface $formType = null): void { if (!($formType instanceof ResolvedFormTypeInterface)) { return; @@ -46,17 +46,16 @@ public static function typeAncestryForType(ResolvedFormTypeInterface $formType = $types[] = $formType->getBlockPrefix(); - self::typeAncestryForType($formType->getParent(), $types); + self::typeAncestryForType($types, $formType->getParent()); } /** * Returns the dataClass of the form or its parents, if any * - * @param mixed $formType * * @return string|null the dataClass */ - public static function findDataClass($formType) + public static function findDataClass(mixed $formType) { if ($dataClass = $formType->getConfig()->getDataClass()) { return $dataClass; @@ -71,11 +70,10 @@ public static function findDataClass($formType) /** * @param FormInterface $form - * @param mixed $type * * @return boolean */ - public static function isTypeInAncestry(FormInterface $form, $type) + public static function isTypeInAncestry(FormInterface $form, mixed $type) { return in_array($type, self::typeAncestry($form)); } diff --git a/src/Limenius/Liform/Guesser/ValidatorGuesser.php b/src/Limenius/Liform/Guesser/ValidatorGuesser.php index 959b283..27f7780 100644 --- a/src/Limenius/Liform/Guesser/ValidatorGuesser.php +++ b/src/Limenius/Liform/Guesser/ValidatorGuesser.php @@ -29,9 +29,7 @@ class ValidatorGuesser extends ValidatorTypeGuesser */ public function guessMinLength(string $class, string $property) { - return $this->guess($class, $property, function (Constraint $constraint) { - return $this->guessMinLengthForConstraint($constraint); - }); + return $this->guess($class, $property, fn(Constraint $constraint) => $this->guessMinLengthForConstraint($constraint)); } /** @@ -43,14 +41,14 @@ public function guessMinLength(string $class, string $property) */ public function guessMinLengthForConstraint(Constraint $constraint) { - switch (get_class($constraint)) { + switch ($constraint::class) { case Length::class: if (is_numeric($constraint->min)) { return new ValueGuess($constraint->min, Guess::HIGH_CONFIDENCE); } break; case Type::class: - if (in_array($constraint->type, array('double', 'float', 'numeric', 'real'))) { + if (in_array($constraint->type, ['double', 'float', 'numeric', 'real'])) { return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE); } break; diff --git a/src/Limenius/Liform/Liform.php b/src/Limenius/Liform/Liform.php index e7dd7ab..1149899 100644 --- a/src/Limenius/Liform/Liform.php +++ b/src/Limenius/Liform/Liform.php @@ -19,11 +19,6 @@ */ class Liform implements LiformInterface { - /** - * @var ResolverInterface - */ - private $resolver; - /** * @var ExtensionInterface[] */ @@ -32,9 +27,8 @@ class Liform implements LiformInterface /** * @param ResolverInterface $resolver */ - public function __construct(ResolverInterface $resolver) + public function __construct(private readonly ResolverInterface $resolver) { - $this->resolver = $resolver; } /** diff --git a/src/Limenius/Liform/Resolver.php b/src/Limenius/Liform/Resolver.php index 2dafe1d..b7fca9e 100644 --- a/src/Limenius/Liform/Resolver.php +++ b/src/Limenius/Liform/Resolver.php @@ -30,7 +30,7 @@ class Resolver implements ResolverInterface * @param TransformerInterface $transformer * @param string|null $widget */ - public function setTransformer($formType, TransformerInterface $transformer, $widget = null) + public function setTransformer($formType, TransformerInterface $transformer, $widget = null): void { $this->transformers[$formType] = [ 'transformer' => $transformer, diff --git a/src/Limenius/Liform/Serializer/Normalizer/FormErrorNormalizer.php b/src/Limenius/Liform/Serializer/Normalizer/FormErrorNormalizer.php index d691266..b4a5db9 100644 --- a/src/Limenius/Liform/Serializer/Normalizer/FormErrorNormalizer.php +++ b/src/Limenius/Liform/Serializer/Normalizer/FormErrorNormalizer.php @@ -25,26 +25,20 @@ */ class FormErrorNormalizer implements NormalizerInterface { - /** - * @var TranslatorInterface - */ - private $translator; - /** * @param TranslatorInterface $translator */ - public function __construct(TranslatorInterface $translator) + public function __construct(private readonly TranslatorInterface $translator) { - $this->translator = $translator; } /** * {@inheritdoc} */ - public function normalize($object, $format = null, array $context = []): float|array|\ArrayObject|bool|int|string|null + public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null { return [ - 'code' => isset($context['status_code']) ? $context['status_code'] : null, + 'code' => $context['status_code'] ?? null, 'message' => 'Validation Failed', 'errors' => $this->convertFormToArray($object), ]; @@ -56,11 +50,19 @@ public function normalize($object, $format = null, array $context = []): float|a * @param null $format * @param array $context */ - public function supportsNormalization($data, $format = null, array $context = []): bool + 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 [Form::class => true]; + } + /** * This code has been taken from JMSSerializer. * @@ -120,9 +122,4 @@ private function getErrorMessage(FormError $error) return $this->translator->trans($error->getMessageTemplate(), $error->getMessageParameters(), 'validators'); } - - public function getSupportedTypes(?string $format): array - { - return [Form::class]; - } } diff --git a/src/Limenius/Liform/Serializer/Normalizer/InitialValuesNormalizer.php b/src/Limenius/Liform/Serializer/Normalizer/InitialValuesNormalizer.php index d86d652..d6dd82d 100644 --- a/src/Limenius/Liform/Serializer/Normalizer/InitialValuesNormalizer.php +++ b/src/Limenius/Liform/Serializer/Normalizer/InitialValuesNormalizer.php @@ -66,7 +66,7 @@ private function getValues(FormInterface $form, FormView $formView): mixed 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 @@ -78,13 +78,7 @@ private function getValues(FormInterface $form, FormView $formView): mixed return (array) $data; } - // handle separatedly the case with checkboxes, so the result is - // true/false instead of 1/0 - if (isset($formView->vars['checked'])) { - return $formView->vars['checked']; - } - - return $formView->vars['value']; + return $formView->vars['checked'] ?? $formView->vars['value']; } /** @@ -95,7 +89,7 @@ private function getValues(FormInterface $form, FormView $formView): mixed */ private function normalizeMultipleExpandedChoice(FormView $formView): array { - $data = array(); + $data = []; foreach ($formView->children as $name => $child) { if ($child->vars['checked']) { $data[] = $child->vars['value']; @@ -124,6 +118,6 @@ private function normalizeExpandedChoice(FormView $formView): mixed public function getSupportedTypes(?string $format): array { - return [Form::class]; + return [Form::class => true]; } } diff --git a/src/Limenius/Liform/Transformer/AbstractTransformer.php b/src/Limenius/Liform/Transformer/AbstractTransformer.php index 5dde978..d1ee2cc 100644 --- a/src/Limenius/Liform/Transformer/AbstractTransformer.php +++ b/src/Limenius/Liform/Transformer/AbstractTransformer.php @@ -20,18 +20,12 @@ */ abstract class AbstractTransformer implements TransformerInterface { - protected TranslatorInterface $translator; - - protected ?FormTypeGuesserInterface $validatorGuesser = null; - /** * @param TranslatorInterface $translator * @param FormTypeGuesserInterface|null $validatorGuesser */ - public function __construct(TranslatorInterface $translator, FormTypeGuesserInterface $validatorGuesser = null) + public function __construct(protected TranslatorInterface $translator, protected ?FormTypeGuesserInterface $validatorGuesser = null) { - $this->translator = $translator; - $this->validatorGuesser = $validatorGuesser; } public function isRequired(FormInterface $form): bool @@ -147,8 +141,7 @@ protected function addDescription(FormInterface $form, array $schema): array return $schema; } - /** @param mixed $configWidget */ - protected function addWidget(FormInterface $form, array $schema, $configWidget): array + protected function addWidget(FormInterface $form, array $schema, mixed $configWidget): array { if ($liform = $form->getConfig()->getOption('liform')) { if (isset($liform['widget']) && $widget = $liform['widget']) { diff --git a/src/Limenius/Liform/Transformer/ArrayTransformer.php b/src/Limenius/Liform/Transformer/ArrayTransformer.php index fa19742..00aa771 100644 --- a/src/Limenius/Liform/Transformer/ArrayTransformer.php +++ b/src/Limenius/Liform/Transformer/ArrayTransformer.php @@ -32,7 +32,7 @@ class ArrayTransformer extends AbstractTransformer * @param FormTypeGuesserInterface|null $validatorGuesser * @param ResolverInterface $resolver */ - public function __construct(TranslatorInterface $translator, FormTypeGuesserInterface $validatorGuesser = null, ResolverInterface $resolver) + public function __construct(TranslatorInterface $translator, ResolverInterface $resolver, FormTypeGuesserInterface $validatorGuesser = null) { parent::__construct($translator, $validatorGuesser); $this->resolver = $resolver; diff --git a/src/Limenius/Liform/Transformer/CompoundTransformer.php b/src/Limenius/Liform/Transformer/CompoundTransformer.php index ada775f..332e3ba 100644 --- a/src/Limenius/Liform/Transformer/CompoundTransformer.php +++ b/src/Limenius/Liform/Transformer/CompoundTransformer.php @@ -28,10 +28,10 @@ class CompoundTransformer extends AbstractTransformer /** * @param TranslatorInterface $translator - * @param FormTypeGuesserInterface|null $validatorGuesser * @param ResolverInterface $resolver + * @param FormTypeGuesserInterface|null $validatorGuesser */ - public function __construct(TranslatorInterface $translator, FormTypeGuesserInterface $validatorGuesser = null, ResolverInterface $resolver) + public function __construct(TranslatorInterface $translator, ResolverInterface $resolver, FormTypeGuesserInterface $validatorGuesser = null) { parent::__construct($translator, $validatorGuesser); $this->resolver = $resolver; @@ -47,9 +47,7 @@ public function transform(FormInterface $form, array $extensions = [], $widget = $required = []; $formItems = $form->all(); - uasort($formItems, static function ($a, $b): int { - return $a->getConfig()->getOption('priority') <=> $b->getConfig()->getOption('priority'); - }); + uasort($formItems, static fn($a, $b): int => $a->getConfig()->getOption('priority') <=> $b->getConfig()->getOption('priority')); foreach ($formItems as $name => $field) { $transformerData = $this->resolver->resolve($field); diff --git a/tests/Limenius/Liform/Tests/ResolverTest.php b/tests/Limenius/Liform/Tests/ResolverTest.php index fa1b368..1b05914 100644 --- a/tests/Limenius/Liform/Tests/ResolverTest.php +++ b/tests/Limenius/Liform/Tests/ResolverTest.php @@ -24,13 +24,13 @@ */ class ResolverTest extends TypeTestCase { - public function testConstruct() + public function testConstruct(): void { $resolver = new Resolver(); $this->assertInstanceOf(Resolver::class, $resolver); } - public function testCannotResolve() + public function testCannotResolve(): void { $this->expectException(TransformerException::class); @@ -39,7 +39,7 @@ public function testCannotResolve() $this->assertArrayHasKey('transformer', $resolver->resolve($form)); } - public function testResolve() + public function testResolve(): void { $resolver = new Resolver(); $stub = $this->createMock(StringTransformer::class); diff --git a/tests/Limenius/Liform/Tests/Serializer/InitialValuesNormalizerTest.php b/tests/Limenius/Liform/Tests/Serializer/InitialValuesNormalizerTest.php index 2200d91..1701735 100644 --- a/tests/Limenius/Liform/Tests/Serializer/InitialValuesNormalizerTest.php +++ b/tests/Limenius/Liform/Tests/Serializer/InitialValuesNormalizerTest.php @@ -24,13 +24,13 @@ */ class InitialValuesNormalizerTest extends LiformTestCase { - public function testConstruct() + public function testConstruct(): void { $normalizer = new InitialValuesNormalizer(); $this->assertInstanceOf(InitialValuesNormalizer::class, $normalizer); } - public function testSimpleCase() + public function testSimpleCase(): void { $form = $this->factory->create(FormType::class , ['firstName' => 'Joe']) ->add('firstName', TextType::class) @@ -40,7 +40,7 @@ public function testSimpleCase() $this->assertEquals('Joe', $data['firstName']); } - public function testChoiceExpandedMultiple() + public function testChoiceExpandedMultiple(): void { $form = $this->factory->create(FormType::class, ['firstName' => ['A']]) ->add( @@ -59,7 +59,7 @@ public function testChoiceExpandedMultiple() } - public function testChoiceExpanded() + public function testChoiceExpanded(): void { $form = $this->factory->create(FormType::class, ['firstName' => 'A']) ->add( diff --git a/tests/Limenius/Liform/Tests/Transformer/ChoiceTransformerTest.php b/tests/Limenius/Liform/Tests/Transformer/ChoiceTransformerTest.php index cd7908f..cb2327e 100644 --- a/tests/Limenius/Liform/Tests/Transformer/ChoiceTransformerTest.php +++ b/tests/Limenius/Liform/Tests/Transformer/ChoiceTransformerTest.php @@ -25,7 +25,7 @@ */ class ChoiceTransformerTest extends LiformTestCase { - public function testChoice() + public function testChoice(): void { $form = $this->factory->create(FormType::class) ->add( @@ -39,15 +39,12 @@ public function testChoice() // 4 times: firstName, form, and the two choices $this->translator->expects($this->exactly(4)) ->method('trans') - ->will($this->returnCallback(function ($str) { - return $str.'-translated'; - })); + ->willReturnCallback(fn($str) => $str.'-translated'); $resolver = new Resolver(); $resolver->setTransformer('choice', new Transformer\ChoiceTransformer($this->translator, null)); - $transformer = new CompoundTransformer($this->translator, null, $resolver); + $transformer = new CompoundTransformer($this->translator, $resolver); $transformed = $transformer->transform($form); - $this->assertTrue(is_array($transformed)); $this->assertArrayHasKey('enum_titles', $transformed['properties']['firstName']); $this->assertArrayHasKey('enum_titles', $transformed['properties']['firstName']['options']); $this->assertEquals(['a-translated', 'b-translated'], $transformed['properties']['firstName']['enum_titles']); @@ -56,7 +53,7 @@ public function testChoice() $this->assertEquals(['A', 'B'], $transformed['properties']['firstName']['enum']); } - public function testChoiceExpanded() + public function testChoiceExpanded(): void { $form = $this->factory->create(FormType::class) ->add( @@ -71,15 +68,12 @@ public function testChoiceExpanded() // 4 times: firstName, form, and the two choices $this->translator->expects($this->exactly(4)) ->method('trans') - ->will($this->returnCallback(function ($str) { - return $str.'-translated'; - })); + ->willReturnCallback(fn($str) => $str.'-translated'); $resolver = new Resolver(); $resolver->setTransformer('choice', new Transformer\ChoiceTransformer($this->translator, null)); - $transformer = new CompoundTransformer($this->translator, null, $resolver); + $transformer = new CompoundTransformer($this->translator, $resolver); $transformed = $transformer->transform($form); - $this->assertTrue(is_array($transformed)); $this->assertArrayHasKey('enum_titles', $transformed['properties']['firstName']); $this->assertArrayHasKey('enum_titles', $transformed['properties']['firstName']['options']); $this->assertEquals(['a-translated', 'b-translated'], $transformed['properties']['firstName']['enum_titles']); @@ -90,7 +84,7 @@ public function testChoiceExpanded() $this->assertEquals('choice-expanded', $transformed['properties']['firstName']['widget']); } - public function testChoiceMultiple() + public function testChoiceMultiple(): void { $form = $this->factory->create(FormType::class) ->add( @@ -104,15 +98,14 @@ public function testChoiceMultiple() $resolver = new Resolver(); $resolver->setTransformer('choice', new Transformer\ChoiceTransformer($this->translator, null)); - $transformer = new CompoundTransformer($this->translator, null, $resolver); + $transformer = new CompoundTransformer($this->translator, $resolver); $transformed = $transformer->transform($form); - $this->assertTrue(is_array($transformed)); $this->assertArrayHasKey('items', $transformed['properties']['firstName']); $this->assertEquals('array', $transformed['properties']['firstName']['type']); $this->assertArrayNotHasKey('widget', $transformed['properties']['firstName']); } - public function testChoiceMultipleExpanded() + public function testChoiceMultipleExpanded(): void { $form = $this->factory->create(FormType::class) ->add( @@ -127,9 +120,8 @@ public function testChoiceMultipleExpanded() $resolver = new Resolver(); $resolver->setTransformer('choice', new Transformer\ChoiceTransformer($this->translator, null)); - $transformer = new CompoundTransformer($this->translator, null, $resolver); + $transformer = new CompoundTransformer($this->translator, $resolver); $transformed = $transformer->transform($form); - $this->assertTrue(is_array($transformed)); $this->assertArrayHasKey('items', $transformed['properties']['firstName']); $this->assertEquals('array', $transformed['properties']['firstName']['type']); $this->assertArrayHasKey('widget', $transformed['properties']['firstName']); diff --git a/tests/Limenius/Liform/Tests/Transformer/CommonTransformerTest.php b/tests/Limenius/Liform/Tests/Transformer/CommonTransformerTest.php index 15c5852..4504702 100644 --- a/tests/Limenius/Liform/Tests/Transformer/CommonTransformerTest.php +++ b/tests/Limenius/Liform/Tests/Transformer/CommonTransformerTest.php @@ -25,7 +25,7 @@ */ class CommonTransformerTest extends LiformTestCase { - public function testRequired() + public function testRequired(): void { $form = $this->factory->create(FormType::class) ->add( @@ -35,16 +35,15 @@ public function testRequired() ); $resolver = new Resolver(); $resolver->setTransformer('text', new StringTransformer($this->translator)); - $transformer = new CompoundTransformer($this->translator, null, $resolver); + $transformer = new CompoundTransformer($this->translator, $resolver); $transformed = $transformer->transform($form); - $this->assertTrue(is_array($transformed)); $this->assertArrayHasKey('required', $transformed); $this->assertTrue(is_array($transformed['required'])); $this->assertContains('firstName', $transformed['required']); } - public function testDescription() + public function testDescription(): void { $form = $this->factory->create(FormType::class) ->add( @@ -56,18 +55,15 @@ public function testDescription() $resolver->setTransformer('text', new StringTransformer($this->translator)); $this->translator->method('trans') - ->will($this->returnCallback(function ($description) { - return $description; - })); - $transformer = new CompoundTransformer($this->translator, null, $resolver); + ->willReturnCallback(fn($description) => $description); + $transformer = new CompoundTransformer($this->translator, $resolver); $transformed = $transformer->transform($form); - $this->assertTrue(is_array($transformed)); $this->assertArrayHasKey('description', $transformed['properties']['firstName']); $this->assertSame($description, $transformed['properties']['firstName']['description']); } - public function testDescriptionFromFormHelp() + public function testDescriptionFromFormHelp(): void { $form = $this->factory->create(FormType::class) ->add( @@ -81,18 +77,15 @@ public function testDescriptionFromFormHelp() $resolver = new Resolver(); $resolver->setTransformer('text', new StringTransformer($this->translator)); $this->translator->method('trans') - ->will($this->returnCallback(function ($description) { - return $description; - })); - $transformer = new CompoundTransformer($this->translator, null, $resolver); + ->willReturnCallback(fn($description) => $description); + $transformer = new CompoundTransformer($this->translator, $resolver); $transformed = $transformer->transform($form); - $this->assertTrue(is_array($transformed)); $this->assertArrayHasKey('description', $transformed['properties']['firstName']); $this->assertSame($description, $transformed['properties']['firstName']['description']); } - public function testDescriptionFromFormHelpOverriddenByLiformDescription() + public function testDescriptionFromFormHelpOverriddenByLiformDescription(): void { $form = $this->factory->create(FormType::class) ->add( @@ -108,19 +101,16 @@ public function testDescriptionFromFormHelpOverriddenByLiformDescription() $resolver = new Resolver(); $resolver->setTransformer('text', new StringTransformer($this->translator)); - $transformer = new CompoundTransformer($this->translator, null, $resolver); + $transformer = new CompoundTransformer($this->translator, $resolver); $this->translator->method('trans') - ->will($this->returnCallback(function ($description) { - return $description; - })); + ->willReturnCallback(fn($description) => $description); $transformed = $transformer->transform($form); - $this->assertTrue(is_array($transformed)); $this->assertArrayHasKey('description', $transformed['properties']['firstName']); $this->assertSame($description, $transformed['properties']['firstName']['description']); } - public function testLabel() + public function testLabel(): void { $form = $this->factory->create(FormType::class) ->add( @@ -134,7 +124,7 @@ public function testLabel() ->expects($this->exactly(2)) ->method('trans') ->willReturn('a label'); - $transformer = new CompoundTransformer($this->translator, null, $resolver); + $transformer = new CompoundTransformer($this->translator, $resolver); $transformed = $transformer->transform($form); $this->assertTrue(is_array($transformed)); @@ -142,7 +132,7 @@ public function testLabel() $this->assertEquals('a label', $transformed['properties']['firstName']['title']); } - public function testWidget() + public function testWidget(): void { $form = $this->factory->create(FormType::class) ->add( @@ -152,14 +142,14 @@ public function testWidget() ); $resolver = new Resolver(); $resolver->setTransformer('text', new StringTransformer($this->translator)); - $transformer = new CompoundTransformer($this->translator, null, $resolver); + $transformer = new CompoundTransformer($this->translator, $resolver); $transformed = $transformer->transform($form); $this->assertTrue(is_array($transformed)); $this->assertArrayHasKey('widget', $transformed['properties']['firstName']); } - public function testWidgetViaTransformerDefinition() + public function testWidgetViaTransformerDefinition(): void { $form = $this->factory->create(FormType::class) ->add( @@ -168,7 +158,7 @@ public function testWidgetViaTransformerDefinition() ); $resolver = new Resolver(); $resolver->setTransformer('text', new StringTransformer($this->translator), 'widg'); - $transformer = new CompoundTransformer($this->translator, null, $resolver); + $transformer = new CompoundTransformer($this->translator, $resolver); $transformed = $transformer->transform($form); $this->assertTrue(is_array($transformed)); diff --git a/tests/Limenius/Liform/Tests/Transformer/CompoundTransformerTest.php b/tests/Limenius/Liform/Tests/Transformer/CompoundTransformerTest.php index 2368c28..bb926ef 100644 --- a/tests/Limenius/Liform/Tests/Transformer/CompoundTransformerTest.php +++ b/tests/Limenius/Liform/Tests/Transformer/CompoundTransformerTest.php @@ -26,14 +26,14 @@ */ class CompoundTransformerTest extends LiformTestCase { - public function testOrder() + public function testOrder(): void { $form = $this->factory->create(FormType::class) ->add('firstName', TextType::class) ->add('secondName', TextType::class); $resolver = new Resolver(); $resolver->setTransformer('text', new StringTransformer($this->translator)); - $transformer = new CompoundTransformer($this->translator, null, $resolver); + $transformer = new CompoundTransformer($this->translator, $resolver); $transformed = $transformer->transform($form); $this->assertTrue(is_array($transformed)); @@ -41,14 +41,14 @@ public function testOrder() $this->assertEquals(2, $transformed['properties']['secondName']['propertyOrder']); } - public function testPriority() + public function testPriority(): void { $form = $this->factory->create(FormType::class) ->add('firstName', TextType::class, ['priority' => 1]) ->add('secondName', TextType::class, ['priority' => 0]); $resolver = new Resolver(); $resolver->setTransformer('text', new StringTransformer($this->translator)); - $transformer = new CompoundTransformer($this->translator, null, $resolver); + $transformer = new CompoundTransformer($this->translator, $resolver); $transformed = $transformer->transform($form); $this->assertTrue(is_array($transformed)); diff --git a/tests/Limenius/Liform/Tests/Transformer/NumberTransformerTest.php b/tests/Limenius/Liform/Tests/Transformer/NumberTransformerTest.php index 7e1926e..5ce2a25 100644 --- a/tests/Limenius/Liform/Tests/Transformer/NumberTransformerTest.php +++ b/tests/Limenius/Liform/Tests/Transformer/NumberTransformerTest.php @@ -25,7 +25,7 @@ */ class NumberTransformerTest extends LiformTestCase { - public function testPattern() + public function testPattern(): void { $form = $this->factory->create(FormType::class) ->add( @@ -35,7 +35,7 @@ public function testPattern() ); $resolver = new Resolver(); $resolver->setTransformer('number', new NumberTransformer($this->translator)); - $transformer = new CompoundTransformer($this->translator, null, $resolver); + $transformer = new CompoundTransformer($this->translator, $resolver); $transformed = $transformer->transform($form); $this->assertTrue(is_array($transformed)); $this->assertEquals('number', $transformed['properties']['somefield']['type']); diff --git a/tests/Limenius/Liform/Tests/Transformer/StringTransformerTest.php b/tests/Limenius/Liform/Tests/Transformer/StringTransformerTest.php index cc8c12b..0b6d265 100644 --- a/tests/Limenius/Liform/Tests/Transformer/StringTransformerTest.php +++ b/tests/Limenius/Liform/Tests/Transformer/StringTransformerTest.php @@ -25,7 +25,7 @@ */ class StringTransformerTest extends LiformTestCase { - public function testPattern() + public function testPattern(): void { $form = $this->factory->create(FormType::class) ->add( @@ -35,9 +35,8 @@ public function testPattern() ); $resolver = new Resolver(); $resolver->setTransformer('text', new StringTransformer($this->translator)); - $transformer = new CompoundTransformer($this->translator, null, $resolver); + $transformer = new CompoundTransformer($this->translator, $resolver); $transformed = $transformer->transform($form); - $this->assertTrue(is_array($transformed)); $this->assertEquals('.{5,}', $transformed['properties']['firstName']['pattern']); } }