Skip to content

Commit

Permalink
Merge pull request #34 from Elao/symfony5.x
Browse files Browse the repository at this point in the history
Symfony 5.0 compatibility
  • Loading branch information
maximecolin authored May 29, 2020
2 parents e467579 + 851e26a commit 293ca4a
Show file tree
Hide file tree
Showing 20 changed files with 255 additions and 148 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/vendor
composer.lock
composer.lock
.php_cs.cache
.phpunit.result.cache
37 changes: 37 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

$header = <<<'EOF'
This file is part of the ElaoFormTranslation bundle.
Copyright (C) Elao
@author Elao <contact@elao.com>
EOF;

$finder = PhpCsFixer\Finder::create()
->in([
__DIR__
])
;

return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setUsingCache(true)
->setFinder($finder)
->setRules([
'@Symfony' => true,
'php_unit_namespaced' => true,
'psr0' => false,
'concat_space' => ['spacing' => 'one'],
'phpdoc_summary' => false,
'phpdoc_annotation_without_dot' => false,
'phpdoc_order' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => true,
'simplified_null_return' => false,
'header_comment' => ['header' => $header],
'yoda_style' => null,
'native_function_invocation' => ['include' => ['@compiler_optimized']],
'single_line_throw' => false,
])
;
64 changes: 50 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,69 @@
sudo: false
language: php

php:
- 7.0
branches:
only:
- master

env:
global:
- CHECK_CODE_STYLE="no"
- COMPOSER_FLAGS=""
- COMPOSER_MEMORY_LIMIT=-1
- ENABLE_CODE_COVERAGE="no"
- SYMFONY_PHPUNIT_DIR="$HOME/symfony-bridge/.phpunit"
- SYMFONY_VERSION=""

matrix:
fast_finish: true
include:
- php: 7.0
env: SYMFONY_VERSION="3.0.*@dev"
- php: 7.1
env: SYMFONY_VERSION="3.0.*@dev"
env: SYMFONY_VERSION="3.0.*"
- php: 7.2
env: SYMFONY_VERSION="3.0.*@dev"
env: SYMFONY_VERSION="3.0.*"
- php: 7.1
env: SYMFONY_VERSION="4.0.*@dev"
env: SYMFONY_VERSION="4.0.*"
- php: 7.2
env: SYMFONY_VERSION="4.0.*@dev"

sudo: false
env: SYMFONY_VERSION="4.0.*"
- php: 7.3
env: SYMFONY_VERSION="4.4.*"
- php: 7.3
env: SYMFONY_VERSION="5.0.*"
- php: 7.4
env: SYMFONY_VERSION="5.0.*"
- php: 7.4
env: SYMFONY_VERSION="5.1.*"
# bleeding edge (unreleased dev versions where failures are allowed):
- php: nightly # PHP 8
env: SYMFONY_VERSION="5.2.*"
allow_failures:
- env: SYMFONY_VERSION="5.2.*"

cache:
directories:
- $HOME/.composer/cache
- $HOME/symfony-bridge/.phpunit

before_install:
- composer selfupdate
- if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi;
- if [[ "$ENABLE_CODE_COVERAGE" != "yes" ]]; then phpenv config-rm xdebug.ini || true; fi;
- if [[ "$SYMFONY_VERSION" != "" ]]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi;
- if [[ "$CHECK_CODE_STYLE" != "yes" ]]; then composer remove "friendsofphp/php-cs-fixer" --no-update --no-interaction --dev; fi;

install: composer update --prefer-dist --no-interaction $COMPOSER_FLAGS
install:
- |
# Set composer's platform to php 7.4 if we're on php 8 & use dev version of phpunit-bridge (which ignores platform reqs)
echo $TRAVIS_PHP_VERSION
if [[ $TRAVIS_PHP_VERSION = 'nightly' ]]; then
echo "Set composer's platform to php 7.4"
composer config platform.php 7.4.99
composer require "symfony/phpunit-bridge:5.1.x-dev" --no-update --no-interaction --dev
fi
- composer update --prefer-dist --no-interaction --optimize-autoloader --prefer-stable --no-progress $COMPOSER_FLAGS
- if [[ "$ENABLE_CODE_COVERAGE" == "yes" ]]; then composer require --dev satooshi/php-coveralls; fi;

script:
- vendor/bin/phpunit --coverage-text
- if [[ "$ENABLE_CODE_COVERAGE" == "yes" ]]; then vendor/bin/simple-phpunit --coverage-text --coverage-clover build/logs/clover.xml; else vendor/bin/simple-phpunit; fi;
- if [[ "$CHECK_CODE_STYLE" == "yes" ]]; then PHP_CS_FIXER_FUTURE_MODE=1 vendor/bin/php-cs-fixer fix --config=.php_cs --dry-run --no-interaction --diff; fi;

after_success:
- if [[ "$ENABLE_CODE_COVERAGE" == "yes" ]]; then php vendor/bin/coveralls -v; fi;
13 changes: 6 additions & 7 deletions Builders/FormKeyBuilder.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

/**
/*
* This file is part of the ElaoFormTranslation bundle.
*
* Copyright (C) 2014 Elao
* Copyright (C) Elao
*
* @author Elao <contact@elao.com>
*/
Expand Down Expand Up @@ -55,11 +55,11 @@ class FormKeyBuilder
* @param string $children Prefix for children nodes
* @param string $prototype Prefix for prototype nodes
*/
public function __construct($separator = ".", $root = "form", $children = "children", $prototype = "prototype")
public function __construct($separator = '.', $root = 'form', $children = 'children', $prototype = 'prototype')
{
$this->separator = $separator;
$this->root = $root;
$this->children = $children;
$this->root = $root;
$this->children = $children;
$this->prototype = $prototype;
}

Expand All @@ -73,7 +73,7 @@ public function __construct($separator = ".", $root = "form", $children = "child
*/
public function buildKeyFromTree(FormTree $tree, $parent)
{
$key = array();
$key = [];

if ($this->root) {
$key[] = $this->root;
Expand All @@ -82,7 +82,6 @@ public function buildKeyFromTree(FormTree $tree, $parent)
$last = \count($tree) - 1;

foreach ($tree as $index => $node) {

if (!$node->isPrototype()) {
$key[] = $node->getName();
}
Expand Down
23 changes: 10 additions & 13 deletions Builders/FormTreeBuilder.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
<?php

/**
/*
* This file is part of the ElaoFormTranslation bundle.
*
* Copyright (C) 2014 Elao
* Copyright (C) Elao
*
* @author Elao <contact@elao.com>
*/

namespace Elao\Bundle\FormTranslationBundle\Builders;

use Symfony\Component\Form\FormView;

use Elao\Bundle\FormTranslationBundle\Model\FormTree;
use Elao\Bundle\FormTranslationBundle\Model\FormTreeNode;
use Symfony\Component\Form\FormView;

/**
* Responsible form building tree for forms.
Expand All @@ -27,7 +26,7 @@ class FormTreeBuilder
*
* @var array
*/
private $noChildren = array('date', 'time', 'datetime', 'choice');
private $noChildren = ['date', 'time', 'datetime', 'choice'];

/**
* Get the full tree for a given view
Expand All @@ -41,7 +40,7 @@ public function getTree(FormView $view)
if ($view->parent !== null) {
$tree = $this->getTree($view->parent);
} else {
$tree = new FormTree;
$tree = new FormTree();
}

$tree->addChild($this->createNodeFromView($view));
Expand All @@ -62,15 +61,13 @@ public function setNoChildren(array $types)
/**
* Create a FormTreeNode for the given view
*
* @param FormView $view
*
* @return FormTreeNode
*/
private function createNodeFromView(FormView $view)
{
$haschildren = $this->hasChildrenWithLabel($view);
$haschildren = $this->hasChildrenWithLabel($view);
$isCollection = $haschildren ? $this->isCollection($view) : false;
$isPrototype = $this->isPrototype($view);
$isPrototype = $this->isPrototype($view);

return new FormTreeNode($view->vars['name'], $haschildren, $isCollection, $isPrototype);
}
Expand All @@ -80,7 +77,7 @@ private function createNodeFromView(FormView $view)
*
* @param FormView $view The FormView
*
* @return boolean
* @return bool
*/
private function hasChildrenWithLabel(FormView $view)
{
Expand All @@ -102,7 +99,7 @@ private function hasChildrenWithLabel(FormView $view)
*
* @param FormView $view The FormView
*
* @return boolean
* @return bool
*/
private function isCollection(FormView $view)
{
Expand All @@ -118,7 +115,7 @@ private function isCollection(FormView $view)
*
* @param FormView $view The FormView
*
* @return boolean
* @return bool
*/
private function isPrototype(FormView $view)
{
Expand Down
32 changes: 16 additions & 16 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

/**
/*
* This file is part of the ElaoFormTranslation bundle.
*
* Copyright (C) 2014 Elao
* Copyright (C) Elao
*
* @author Elao <contact@elao.com>
*/
Expand All @@ -23,7 +23,7 @@
class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
Expand All @@ -45,27 +45,27 @@ public function getConfigTreeBuilder()
->append(
$this->addKeysConfig(
'form',
array(
'label' => "label",
'help' => "help",
)
[
'label' => 'label',
'help' => 'help',
]
)
)
->append(
$this->addKeysConfig(
'collection',
array(
'label_add' => "label_add",
'label_delete' => "label_delete",
)
[
'label_add' => 'label_add',
'label_delete' => 'label_delete',
]
)
)
->append(
$this->addKeysConfig(
'choice',
array(
'empty_value' => "empty_value",
)
[
'empty_value' => 'empty_value',
]
)
)
->end()
Expand Down Expand Up @@ -105,11 +105,11 @@ public function getConfigTreeBuilder()
* Add Keys Config
*
* @param string $key
* @param array $default
* @param array $default
*
* @return ArrayNodeDefinition|NodeDefinition
*/
public function addKeysConfig($key, $default = array())
public function addKeysConfig($key, $default = [])
{
$treeBuilder = new TreeBuilder($key);
$node = method_exists($treeBuilder, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root($key);
Expand Down
Loading

0 comments on commit 293ca4a

Please sign in to comment.