Skip to content

Commit

Permalink
Symfony 6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlyPoppins authored and nacmartin committed Jun 28, 2023
1 parent 7f47fca commit 96f9cb4
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 85 deletions.
1 change: 1 addition & 0 deletions .php-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8.1
95 changes: 20 additions & 75 deletions src/Limenius/Liform/Transformer/AbstractTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,23 @@
*/
abstract class AbstractTransformer implements TransformerInterface
{
/**
* @var TranslatorInterface
*/
protected $translator;

/**
* @var FormTypeGuesserInterface|null
*/
protected $validatorGuesser;

/**
* @param TranslatorInterface $translator
* @param FormTypeGuesserInterface|null $validatorGuesser
*/
protected TranslatorInterface $translator;

protected ?FormTypeGuesserInterface $validatorGuesser = null;

public function __construct(TranslatorInterface $translator, FormTypeGuesserInterface $validatorGuesser = null)
{
$this->translator = $translator;
$this->validatorGuesser = $validatorGuesser;
}

/**
* @param FormInterface $form
*
* @return boolean
*/
public function isRequired(FormInterface $form)
public function isRequired(FormInterface $form): bool
{
return $form->getConfig()->getOption('required');
}

/**
* @param ExtensionInterface[] $extensions
* @param FormInterface $form
* @param array $schema
*
* @return array
*/
protected function applyExtensions(array $extensions, FormInterface $form, array $schema)
/** @param ExtensionInterface[] $extensions */
protected function applyExtensions(array $extensions, FormInterface $form, array $schema): array
{
$newSchema = $schema;
foreach ($extensions as $extension) {
Expand All @@ -67,16 +46,13 @@ protected function applyExtensions(array $extensions, FormInterface $form, array
return $newSchema;
}

/**
* @param FormInterface $form
* @param array $schema
* @param ExtensionInterface[] $extensions
* @param string $widget
*
* @return array
*/
protected function addCommonSpecs(FormInterface $form, array $schema, $extensions = [], $widget = null)
{
/** @param ExtensionInterface[] $extensions */
protected function addCommonSpecs(
FormInterface $form,
array $schema,
array $extensions = [],
?string $widget = null
): array {
$schema = $this->addLabel($form, $schema);
$schema = $this->addAttr($form, $schema);
$schema = $this->addPattern($form, $schema);
Expand All @@ -87,14 +63,7 @@ protected function addCommonSpecs(FormInterface $form, array $schema, $extension
return $schema;
}


/**
* @param FormInterface $form
* @param array $schema
*
* @return array
*/
protected function addPattern(FormInterface $form, array $schema)
protected function addPattern(FormInterface $form, array $schema): array
{
if ($attr = $form->getConfig()->getOption('attr')) {
if (isset($attr['pattern'])) {
Expand All @@ -105,13 +74,7 @@ protected function addPattern(FormInterface $form, array $schema)
return $schema;
}

/**
* @param FormInterface $form
* @param array $schema
*
* @return array
*/
protected function addLabel(FormInterface $form, array $schema)
protected function addLabel(FormInterface $form, array $schema): array
{
$translationDomain = $form->getConfig()->getOption('translation_domain');
if ($label = $form->getConfig()->getOption('label')) {
Expand All @@ -123,13 +86,7 @@ protected function addLabel(FormInterface $form, array $schema)
return $schema;
}

/**
* @param FormInterface $form
* @param array $schema
*
* @return array
*/
protected function addAttr(FormInterface $form, array $schema)
protected function addAttr(FormInterface $form, array $schema): array
{
if ($attr = $form->getConfig()->getOption('attr')) {
$schema['attr'] = $attr;
Expand All @@ -138,13 +95,7 @@ protected function addAttr(FormInterface $form, array $schema)
return $schema;
}

/**
* @param FormInterface $form
* @param array $schema
*
* @return array
*/
protected function addDescription(FormInterface $form, array $schema)
protected function addDescription(FormInterface $form, array $schema): array
{
$formConfig = $form->getConfig();
if ($help = $formConfig->getOption('help', '')) {
Expand All @@ -160,14 +111,8 @@ protected function addDescription(FormInterface $form, array $schema)
return $schema;
}

/**
* @param FormInterface $form
* @param array $schema
* @param mixed $configWidget
*
* @return array
*/
protected function addWidget(FormInterface $form, array $schema, $configWidget)
/** @param mixed $configWidget */
protected function addWidget(FormInterface $form, array $schema, $configWidget): array
{
if ($liform = $form->getConfig()->getOption('liform')) {
if (isset($liform['widget']) && $widget = $liform['widget']) {
Expand Down
2 changes: 1 addition & 1 deletion src/Limenius/Liform/Transformer/ArrayTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(TranslatorInterface $translator, FormTypeGuesserInte
/**
* {@inheritdoc}
*/
public function transform(FormInterface $form, array $extensions = [], $widget = null)
public function transform(FormInterface $form, array $extensions = [], $widget = null): array
{
$children = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Limenius/Liform/Transformer/BooleanTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BooleanTransformer extends AbstractTransformer
/**
* {@inheritdoc}
*/
public function transform(FormInterface $form, array $extensions = [], $widget = null)
public function transform(FormInterface $form, array $extensions = [], $widget = null): array
{
$schema = ['type' => 'boolean'];
$schema = $this->addCommonSpecs($form, $schema, $extensions, $widget);
Expand Down
2 changes: 1 addition & 1 deletion src/Limenius/Liform/Transformer/ChoiceTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ChoiceTransformer extends AbstractTransformer
/**
* {@inheritdoc}
*/
public function transform(FormInterface $form, array $extensions = [], $widget = null)
public function transform(FormInterface $form, array $extensions = [], $widget = null): array
{
$formView = $form->createView();

Expand Down
2 changes: 1 addition & 1 deletion src/Limenius/Liform/Transformer/CompoundTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(TranslatorInterface $translator, FormTypeGuesserInte
/**
* {@inheritdoc}
*/
public function transform(FormInterface $form, array $extensions = [], $widget = null)
public function transform(FormInterface $form, array $extensions = [], $widget = null): array
{
$data = [];
$order = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/Limenius/Liform/Transformer/IntegerTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class IntegerTransformer extends AbstractTransformer
/**
* {@inheritdoc}
*/
public function transform(FormInterface $form, array $extensions = [], $widget = null)
public function transform(FormInterface $form, array $extensions = [], $widget = null): array
{
$schema = ['type' => 'integer'];
$schema = $this->addCommonSpecs($form, $schema, $extensions, $widget);
Expand Down
2 changes: 1 addition & 1 deletion src/Limenius/Liform/Transformer/NumberTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class NumberTransformer extends AbstractTransformer
/**
* {@inheritdoc}
*/
public function transform(FormInterface $form, array $extensions = [], $widget = null)
public function transform(FormInterface $form, array $extensions = [], $widget = null): array
{
$schema = ['type' => 'number'];
$schema = $this->addCommonSpecs($form, $schema, $extensions, $widget);
Expand Down
2 changes: 1 addition & 1 deletion src/Limenius/Liform/Transformer/StringTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class StringTransformer extends AbstractTransformer
/**
* {@inheritdoc}
*/
public function transform(FormInterface $form, array $extensions = [], $widget = null)
public function transform(FormInterface $form, array $extensions = [], $widget = null): array
{
$schema = ['type' => 'string'];
$schema = $this->addCommonSpecs($form, $schema, $extensions, $widget);
Expand Down
6 changes: 3 additions & 3 deletions src/Limenius/Liform/Transformer/TransformerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
interface TransformerInterface
{
/**
* @param FormInterface $form
* @param FormInterface $form
* @param ExtensionInterface[] $extensions
* @param string|null $widget
* @param string|null $widget
*
* @return array
*/
public function transform(FormInterface $form, array $extensions = [], $widget = null);
public function transform(FormInterface $form, array $extensions = [], ?string $widget = null): array;
}

0 comments on commit 96f9cb4

Please sign in to comment.