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 60cd4cc
Show file tree
Hide file tree
Showing 16 changed files with 137 additions and 159 deletions.
56 changes: 31 additions & 25 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,6 @@ on:

jobs:

lint:
name: Lint
runs-on: 'ubuntu-latest'
timeout-minutes: 5

steps:
- name: 'Checkout'
uses: actions/checkout@v2

- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'

- name: 'Install dependencies'
run: make php-cs-fixer.phar

- name: 'Check style'
run: ./php-cs-fixer.phar fix --dry-run --no-interaction --diff

test:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
Expand All @@ -40,10 +20,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 +40,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 Expand Up @@ -108,3 +94,23 @@ jobs:

- name: 'Run PHPUnit tests'
run: vendor/bin/simple-phpunit --testdox --verbose ${{ matrix.code-coverage && '--coverage-text --coverage-clover build/logs/clover.xml' }}

lint:
name: Lint
runs-on: 'ubuntu-latest'
timeout-minutes: 5

steps:
- name: 'Checkout'
uses: actions/checkout@v2

- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'

- name: 'Install dependencies'
run: make install

- name: 'Check style'
run: make lint
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
8 changes: 2 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 @@ -106,12 +103,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 60cd4cc

Please sign in to comment.