Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI

on: [push]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.5'
coverage: none

- name: Install dependencies
uses: ramsey/composer-install@v3

- name: Run tests
run: make test
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
'vendor',
'Tests/Fixtures/TestProject/var',
])
->notPath('Tests/Fixtures/TestProject/config/reference.php')
->in(__DIR__)
)
;
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/FormPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class FormPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
$resources = $container->getParameter('twig.form.resources');

Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('imatic_form');
$rootNode = $treeBuilder->getRootNode();
Expand Down
8 changes: 4 additions & 4 deletions DependencyInjection/ImaticFormExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* This is the class that loads and manages your bundle configuration.
Expand All @@ -13,15 +13,15 @@
*/
class ImaticFormExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$container->setParameter('imatic_form.default_theme', $config['default_theme']);
$container->setParameter('imatic_form.select2', $config['select2']);

$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yaml');
}
}
16 changes: 8 additions & 8 deletions Form/DataTransformer/ArrayToStringTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@

class ArrayToStringTransformer implements DataTransformerInterface
{
public function transform($array)
public function transform(mixed $value): mixed
{
if (null === $array || !\is_array($array)) {
if (null === $value || !\is_array($value)) {
return '';
}

return \implode(',', $array);
return \implode(',', $value);
}

public function reverseTransform($string)
public function reverseTransform(mixed $value): mixed
{
if ('' === $string) {
if ('' === $value) {
return null;
}
if (\is_array($string)) {
return $string;
if (\is_array($value)) {
return $value;
}

return \explode(',', $string);
return \explode(',', $value);
}
}
12 changes: 6 additions & 6 deletions Form/DataTransformer/CollectionToScalarTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ public function __construct(QueryBuilder $qb, callable $idProvider)
$this->idProvider = $idProvider;
}

public function transform($collection)
public function transform(mixed $value): mixed
{
// handle value
if (null === $collection) {
if (null === $value) {
return '';
}
if (!$collection instanceof \Traversable && !\is_array($collection)) {
throw new UnexpectedTypeException($collection, 'Traversable, array or null');
if (!$value instanceof \Traversable && !\is_array($value)) {
throw new UnexpectedTypeException($value, 'Traversable, array or null');
}

// fetch collection members
$output = null;
foreach ($collection as $entity) {
foreach ($value as $entity) {
if (null === $output) {
$output = '';
} else {
Expand All @@ -51,7 +51,7 @@ public function transform($collection)
return $output;
}

public function reverseTransform($value)
public function reverseTransform(mixed $value): mixed
{
if (null === $value || '' === $value) {
return new ArrayCollection();
Expand Down
5 changes: 2 additions & 3 deletions Form/DataTransformer/EmptyEntityToNullTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(array $properties, $strict = false)
$this->strict = $strict;
}

public function reverseTransform($value)
public function reverseTransform(mixed $value): mixed
{
if (!\is_object($value)) {
return $value;
Expand All @@ -34,7 +34,6 @@ public function reverseTransform($value)
$hasNonEmptyValue = false;
foreach ($this->properties as $property) {
$reflProperty = new \ReflectionProperty($value, $property);
$reflProperty->setAccessible(true);
$reflPropertyValue = $reflProperty->getValue($value);

if (
Expand All @@ -50,7 +49,7 @@ public function reverseTransform($value)
return $hasNonEmptyValue ? $value : null;
}

public function transform($value)
public function transform(mixed $value): mixed
{
return $value;
}
Expand Down
12 changes: 6 additions & 6 deletions Form/DataTransformer/EntityToScalarTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ public function __construct(QueryBuilder $qb, callable $idProvider)
$this->idProvider = $idProvider;
}

public function transform($entity)
public function transform(mixed $value): mixed
{
if (!\is_object($entity)) {
if (null === $entity) {
if (!\is_object($value)) {
if (null === $value) {
return '';
}
throw new UnexpectedTypeException($entity, 'object or null');
throw new UnexpectedTypeException($value, 'object or null');
}

return (string) \call_user_func($this->idProvider, $entity);
return (string) \call_user_func($this->idProvider, $value);
}

public function reverseTransform($value)
public function reverseTransform(mixed $value): mixed
{
if (null !== $value && '' !== $value) {
$qb = clone $this->qb;
Expand Down
2 changes: 1 addition & 1 deletion Form/EventListener/RemoveUnsentFieldsSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
class RemoveUnsentFieldsSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
public static function getSubscribedEvents(): array
{
return [
FormEvents::PRE_SUBMIT => 'preSubmit',
Expand Down
6 changes: 3 additions & 3 deletions Form/Extension/ChoiceExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public function __construct(TranslatorInterface $translator, $select2Config)
$this->translator = $translator;
}

public function buildForm(FormBuilderInterface $builder, array $options)
public function buildForm(FormBuilderInterface $builder, array $options): void
{
if ($options['tags']) {
$builder->resetViewTransformers();
}
}

public function buildView(FormView $view, FormInterface $form, array $options)
public function buildView(FormView $view, FormInterface $form, array $options): void
{
if ($options['rich']) {
$placeholder = $options['placeholder'] ?: '';
Expand All @@ -53,7 +53,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
}
}

public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'rich' => function (Options $options) {
Expand Down
4 changes: 2 additions & 2 deletions Form/Extension/CollectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
class CollectionExtension extends AbstractTypeExtension
{
public function buildView(FormView $view, FormInterface $form, array $options)
public function buildView(FormView $view, FormInterface $form, array $options): void
{
if (isset($view->vars['prototype'])) {
$view->vars['prototype_name'] = $options['prototype_name'];
Expand All @@ -28,7 +28,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
}
}

public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'template' => function (Options $options, $default) {
Expand Down
4 changes: 2 additions & 2 deletions Form/Extension/DatepickerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
class DatepickerExtension extends AbstractTypeExtension
{
public function buildView(FormView $view, FormInterface $form, array $options)
public function buildView(FormView $view, FormInterface $form, array $options): void
{
if ($options['rich']) {
$pickDate = false;
Expand Down Expand Up @@ -59,7 +59,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
}
}

public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'rich' => true,
Expand Down
2 changes: 1 addition & 1 deletion Form/Extension/EntityExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function __construct(EntityManagerInterface $manager)
$this->manager = $manager;
}

public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
// specify `choice_value` option prevent unmanaged entity exception in case `UnitOfWork` state which is cleared before constructing the form
Expand Down
4 changes: 2 additions & 2 deletions Form/Extension/FormThemeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(FormRendererInterface $renderer, $defaultTheme = nul
$this->defaultTheme = $defaultTheme;
}

public function buildView(FormView $view, FormInterface $form, array $options)
public function buildView(FormView $view, FormInterface $form, array $options): void
{
$theme = $options['template'];

Expand All @@ -44,7 +44,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
$view->vars += $options['template_parameters'];
}

public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'template' => null,
Expand Down
8 changes: 4 additions & 4 deletions Form/Type/AjaxChoiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ public function __construct(array $select2Config, UrlGeneratorInterface $urlGene
$this->urlGenerator = $urlGenerator;
}

public function getBlockPrefix()
public function getBlockPrefix(): string
{
return 'imatic_ajax_choice';
}

public function buildForm(FormBuilderInterface $builder, array $options)
public function buildForm(FormBuilderInterface $builder, array $options): void
{
if ($options['multiple']) {
$builder->addViewTransformer(new ArrayToStringTransformer(), true);
}
}

public function buildView(FormView $view, FormInterface $form, array $options)
public function buildView(FormView $view, FormInterface $form, array $options): void
{
if ($options['multiple'] && $options['allow_clear']) {
throw new \RuntimeException('The "allow_clear" option has no effect in multiple choice mode');
Expand Down Expand Up @@ -71,7 +71,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
}
}

public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setRequired([
'route',
Expand Down
4 changes: 2 additions & 2 deletions Form/Type/AjaxEntityChoiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(array $select2Config, UrlGeneratorInterface $urlGene
$this->registry = $registry;
}

public function buildForm(FormBuilderInterface $builder, array $options)
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$em = $this->registry->getManager(isset($options['entity_manager']) ? $options['entity_manager'] : null);

Expand All @@ -45,7 +45,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
);
}

public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
parent::configureOptions($resolver);

Expand Down
4 changes: 2 additions & 2 deletions Form/Type/DateRangeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class DateRangeType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add(
'start',
Expand All @@ -23,7 +23,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
);
}

public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults(
[
Expand Down
4 changes: 2 additions & 2 deletions Form/Type/DateTimeRangeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class DateTimeRangeType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add(
'start',
Expand All @@ -22,7 +22,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
);
}

public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults(
[
Expand Down
4 changes: 2 additions & 2 deletions Form/Type/RangeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
*/
class RangeType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('start', $options['field_type'], $options['field_options'])
->add('end', $options['field_type'], $options['field_options']);
}

public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'field_type' => NumberType::class,
Expand Down
Loading
Loading