Skip to content

Commit

Permalink
Symfony 7 Support
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom32i committed Feb 24, 2024
1 parent a95fa2b commit b4eb5ae
Show file tree
Hide file tree
Showing 16 changed files with 126 additions and 142 deletions.
24 changes: 16 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ jobs:
- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.3'

- name: 'Install dependencies'
run: make php-cs-fixer.phar
run: |
make install
vendor/bin/simple-phpunit --version
- name: 'Check style'
run: ./php-cs-fixer.phar fix --dry-run --no-interaction --diff
run: make lint

test:
name: ${{ matrix.name }}
Expand All @@ -40,10 +42,10 @@ jobs:
matrix:
include:
# Lowest deps
- name: 'Test lowest deps [Linux, PHP 7.4]'
- name: 'Test lowest deps Symfony 5.4 [Linux, PHP 7.4]'
os: 'ubuntu-latest'
php: '7.4'
symfony: '4.4.*@dev'
symfony: '5.4.*@dev'
composer-flags: '--prefer-lowest'
allow-unstable: true

Expand All @@ -60,11 +62,17 @@ jobs:
symfony: '6.0.*@dev'
allow-unstable: true

- name: 'Test next Symfony 6.4 [Linux, PHP 8.2]'
os: 'ubuntu-latest'
php: '8.2'
symfony: '6.4.*@dev'
allow-unstable: true

# Bleeding edge (unreleased dev versions where failures are allowed)
- name: 'Test next Symfony [Linux, PHP 8.1] (allowed failure)'
- name: 'Test next Symfony [Linux, PHP 8.3] (allowed failure)'
os: 'ubuntu-latest'
php: '8.1'
symfony: '6.1.*@dev'
php: '8.3'
symfony: '7.0.*@dev'
composer-flags: '--ignore-platform-req php'
allow-unstable: true
allow-failure: true
Expand Down
3 changes: 0 additions & 3 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,5 @@
'simplified_null_return' => false,
'void_return' => true,
'yoda_style' => [],

// @see https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/5495
'binary_operator_spaces' => ['operators' => ['|' => null]]
])
;
4 changes: 3 additions & 1 deletion Builders/FormTreeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class FormTreeBuilder
{
/**
* Form type with no children labels
*
* @var array<string>
*/
private array $noChildren = ['date', 'time', 'datetime', 'choice'];

Expand All @@ -47,7 +49,7 @@ public function getTree(FormView $view): FormTree
/**
* Set form type that should not be treated as having children
*
* @param array $types An array of types
* @param array<string> $types An array of types
*/
public function setNoChildren(array $types): void
{
Expand Down
12 changes: 6 additions & 6 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('elao_form_translation');
Expand Down Expand Up @@ -78,18 +75,22 @@ public function getConfigTreeBuilder(): TreeBuilder
->children()
->scalarNode('children')
->defaultValue('children')
->treatNullLike(false)
->info('Prefix for children nodes (string|false)')
->end()
->scalarNode('prototype')
->defaultValue('prototype')
->treatNullLike(false)
->info('Prefix for prototype nodes (string|false)')
->end()
->scalarNode('root')
->defaultValue('form')
->treatNullLike(false)
->info('Prefix at the root of the key (string|false)')
->end()
->scalarNode('separator')
->defaultValue('.')
->treatNullLike(false)
->info('Separator te be used between nodes (string|false)')
->end()
->end()
Expand All @@ -106,12 +107,11 @@ public function getConfigTreeBuilder(): TreeBuilder
/**
* Add Keys Config
*
* @param string $key
* @param array $default
* @param array<string,string> $default
*
* @return ArrayNodeDefinition|NodeDefinition
*/
public function addKeysConfig($key, $default = [])
public function addKeysConfig(string $key, array $default = [])
{
$treeBuilder = new TreeBuilder($key);
$node = $treeBuilder->getRootNode();
Expand Down
9 changes: 3 additions & 6 deletions DependencyInjection/ElaoFormTranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
*/
class ElaoFormTranslationExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
Expand All @@ -45,9 +42,9 @@ public function load(array $configs, ContainerBuilder $container): void
/**
* Load Tree configuration
*
* @param ContainerBuilder $container The container builder
* @param LoaderInterface $loader The loader
* @param array $config An array of config keys
* @param ContainerBuilder $container The container builder
* @param LoaderInterface $loader The loader
* @param array<string,mixed> $config An array of config keys
*/
private function loadTreeConfig(ContainerBuilder $container, LoaderInterface $loader, array $config): void
{
Expand Down
14 changes: 0 additions & 14 deletions Form/Extension/ButtonTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,11 @@
*/
class ButtonTypeExtension extends TreeAwareExtension
{
/**
* {@inheritdoc}
*/
public static function getExtendedTypes(): iterable
{
return [ButtonType::class];
}

/**
* {@inheritdoc}
*/
public function getExtendedType()
{
return self::getExtendedTypes()[0];
}

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver): void
{
if ($this->autoGenerate) {
Expand Down
14 changes: 0 additions & 14 deletions Form/Extension/ChoiceTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,11 @@
*/
class ChoiceTypeExtension extends TreeAwareExtension
{
/**
* {@inheritdoc}
*/
public static function getExtendedTypes(): iterable
{
return [ChoiceType::class];
}

/**
* {@inheritdoc}
*/
public function getExtendedType()
{
return self::getExtendedTypes()[0];
}

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver): void
{
if ($this->defaultTranslationDomain !== null) {
Expand Down
17 changes: 0 additions & 17 deletions Form/Extension/CollectionTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,11 @@
*/
class CollectionTypeExtension extends TreeAwareExtension
{
/**
* {@inheritdoc}
*/
public static function getExtendedTypes(): iterable
{
return [CollectionType::class];
}

/**
* {@inheritdoc}
*/
public function getExtendedType()
{
return self::getExtendedTypes()[0];
}

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver): void
{
if ($this->autoGenerate) {
Expand All @@ -47,9 +33,6 @@ public function configureOptions(OptionsResolver $resolver): void
}
}

/**
* {@inheritdoc}
*/
public function finishView(FormView $view, FormInterface $form, array $options): void
{
if (isset($this->treeBuilder) && isset($this->keyBuilder) && $options['allow_add'] && $options['prototype']) {
Expand Down
14 changes: 0 additions & 14 deletions Form/Extension/FormTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,11 @@
*/
class FormTypeExtension extends TreeAwareExtension
{
/**
* {@inheritdoc}
*/
public static function getExtendedTypes(): iterable
{
return [FormType::class];
}

/**
* {@inheritdoc}
*/
public function getExtendedType()
{
return self::getExtendedTypes()[0];
}

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver): void
{
if ($this->autoGenerate) {
Expand Down
21 changes: 13 additions & 8 deletions Form/Extension/TreeAwareExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ abstract class TreeAwareExtension extends AbstractTypeExtension

/**
* Buildable keys list
*
* @var array<string,string>
*/
protected array $keys;

Expand Down Expand Up @@ -67,7 +69,7 @@ public function setAutoGenerate(bool $enabled): void
*
* @param FormTreeBuilder $treeBuilder The FormKeyBuilder
*/
public function setTreeBuilder(FormTreeBuilder $treeBuilder = null): void
public function setTreeBuilder(FormTreeBuilder $treeBuilder): void
{
$this->treeBuilder = $treeBuilder;
}
Expand All @@ -77,15 +79,15 @@ public function setTreeBuilder(FormTreeBuilder $treeBuilder = null): void
*
* @param FormKeyBuilder $keyBuilder The FormKeyBuilder
*/
public function setKeyBuilder(FormKeyBuilder $keyBuilder = null): void
public function setKeyBuilder(FormKeyBuilder $keyBuilder): void
{
$this->keyBuilder = $keyBuilder;
}

/**
* Set buildable keys
*
* @param array $keys Array of keys
* @param array<string,string> $keys Array of keys
*/
public function setKeys(array $keys): void
{
Expand All @@ -102,9 +104,6 @@ public function setDefaultTranslationDomain($defaultTranslationDomain): void
$this->defaultTranslationDomain = $defaultTranslationDomain;
}

/**
* {@inheritdoc}
*/
public function finishView(FormView $view, FormInterface $form, array $options): void
{
if (isset($this->treeBuilder) && isset($this->keyBuilder)) {
Expand Down Expand Up @@ -132,7 +131,10 @@ protected function generateKey(FormView &$view, $key, $value): void
$this->setVar($view->vars, $key, $this->keyBuilder->buildKeyFromTree($view->vars['tree'], $value));
}

protected function setVar(array &$vars, string $key, $value): void
/**
* @param array<string,mixed> &$vars
*/
protected function setVar(array &$vars, string $key, mixed $value): void
{
if ($this->getPropertyAccessor()->isWritable($vars, $key)) {
$this->getPropertyAccessor()->setValue($vars, $key, $value);
Expand All @@ -141,7 +143,10 @@ protected function setVar(array &$vars, string $key, $value): void
}
}

protected function optionEquals(array $options, string $key, $value): bool
/**
* @param array<string,mixed> $options
*/
protected function optionEquals(array $options, string $key, mixed $value): bool
{
if ($this->getPropertyAccessor()->isReadable($options, $key)) {
return $this->getPropertyAccessor()->getValue($options, $key) === $value;
Expand Down
Loading

0 comments on commit b4eb5ae

Please sign in to comment.