cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,72 +1,51 @@
<?php
/*
/**
* Chill is a software for social workers
*
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CustomFieldsBundle\Templating\Twig;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Chill\CustomFieldsBundle\Service\CustomFieldsHelper;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
/**
* Add the following Twig Extension :
* * chill_custom_field_widget : to render the value of the custom field,
* * chill_custom_field_label : to render the label of the custom field,
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
* * chill_custom_field_label : to render the label of the custom field,.
*/
class CustomFieldRenderingTwig extends AbstractExtension implements ContainerAwareInterface
{
/** @var Container $container The container */
/**
* @var Container The container
*/
private $container;
/** @var array $defaultParams The default parameters */
private $defaultParams = array(
'label_layout' => 'ChillCustomFieldsBundle:CustomField:render_label.html.twig'
);
/**
* @var CustomFieldsHelper
*/
private $customFieldsHelper;
/**
* @var array The default parameters
*/
private $defaultParams = [
'label_layout' => 'ChillCustomFieldsBundle:CustomField:render_label.html.twig',
];
public function __construct(CustomFieldsHelper $customFieldsHelper)
{
$this->customFieldsHelper = $customFieldsHelper;
}
/*
* (non-PHPdoc)
* @see \Symfony\Component\DependencyInjection\ContainerAwareInterface::setContainer()
*/
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
/*
* (non-PHPdoc)
* @see Twig_Extension::getFunctions()
@@ -74,73 +53,82 @@ class CustomFieldRenderingTwig extends AbstractExtension implements ContainerAwa
public function getFunctions()
{
return [
new TwigFunction('chill_custom_field_widget', array(
new TwigFunction('chill_custom_field_widget', [
$this,
'renderWidget'
), array(
'is_safe' => array(
'html'
)
)),
new TwigFunction('chill_custom_field_label', array(
'renderWidget',
], [
'is_safe' => [
'html',
],
]),
new TwigFunction('chill_custom_field_label', [
$this,
'renderLabel'
), array(
'is_safe' => array(
'html'
)
)),
new TwigFunction('chill_custom_field_is_empty', array(
'renderLabel',
], [
'is_safe' => [
'html',
],
]),
new TwigFunction('chill_custom_field_is_empty', [
$this,
'isEmptyValue'
))
'isEmptyValue',
]),
];
}
/* (non-PHPdoc)
* @see Twig_ExtensionInterface::getName()
*/
public function getName()
{
return 'chill_custom_fields_rendering';
}
public function isEmptyValue($fields, CustomField $customField)
{
return $this->customFieldsHelper
->isEmptyValue($fields, $customField);
}
/* (non-PHPdoc)
* @see Twig_ExtensionInterface::getName()
*/
public function getName()
{
return 'chill_custom_fields_rendering';
}
/**
* Twig Extension that is used to render the label of a custom field.
*
*
* @param CustomField $customField Either a customField OR a customizable_entity OR the FQDN of the entity
* @param array $params The parameters for rendering. Currently, 'label_layout' allow to choose a different label. Default is 'ChillCustomFieldsBundle:CustomField:render_label.html.twig'
*
* @return string HTML representation of the custom field label.
*/
public function renderLabel(CustomField $customField, array $params = array())
public function renderLabel(CustomField $customField, array $params = [])
{
$resolvedParams = array_merge($this->defaultParams, $params);
return $this->container->get('templating')
->render($resolvedParams['label_layout'], array('customField' => $customField));
->render($resolvedParams['label_layout'], ['customField' => $customField]);
}
/**
* Twig extension that is used to render the value of a custom field.
*
*
* The presentation of the value is influenced by the document type.
*
*
* @param array $fields The array raw, as stored in the db
* @param CustomField $customField Either a customField OR a customizable_entity OR the FQDN of the entity
* @param string $documentType The type of the document (csv, html)
* @param string $slug The slug of the custom field ONLY necessary if the first argument is NOT a CustomField instance
*
* @return string HTML representation of the custom field value, as described in the CustomFieldInterface. Is HTML safe
*/
public function renderWidget(array $fields, CustomField $customField, $documentType='html')
public function renderWidget(array $fields, CustomField $customField, $documentType = 'html')
{
return $this->customFieldsHelper
->renderCustomField($fields, $customField, $documentType);
}
}
/*
* (non-PHPdoc)
* @see \Symfony\Component\DependencyInjection\ContainerAwareInterface::setContainer()
*/
public function setContainer(?ContainerInterface $container = null)
{
$this->container = $container;
}
}

View File

@@ -1,71 +1,48 @@
<?php
/*
/**
* Chill is a software for social workers
*
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\CustomFieldsBundle\Templating\Twig;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
/**
* Add the following Twig Extension :
* * chill_custom_fields_group_widget : to render the value of a custom field
* * group
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
* @author Marc Ducobu <marc.ducobu@champs-libres.coop>
* * group.
*/
class CustomFieldsGroupRenderingTwig extends AbstractExtension implements ContainerAwareInterface
{
/** @var Container $container The container */
private $container;
/** @var array $defaultParams The default parameters */
private $defaultParams = array(
'layout' => 'ChillCustomFieldsBundle:CustomFieldsGroup:render.html.twig',
'show_empty' => True
);
/**
*
* @param boolean $showEmptyValues whether the empty values must be rendered
* @var Container The container
*/
private $container;
/**
* @var array The default parameters
*/
private $defaultParams = [
'layout' => 'ChillCustomFieldsBundle:CustomFieldsGroup:render.html.twig',
'show_empty' => true,
];
/**
* @param bool $showEmptyValues whether the empty values must be rendered
*/
public function __construct($showEmptyValues)
{
$this->defaultParams['show_empty'] = $showEmptyValues;
}
/*
* (non-PHPdoc)
* @see \Symfony\Component\DependencyInjection\ContainerAwareInterface::setContainer()
*/
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
/*
* (non-PHPdoc)
* @see Twig_Extension::getFunctions()
@@ -73,48 +50,58 @@ class CustomFieldsGroupRenderingTwig extends AbstractExtension implements Contai
public function getFunctions()
{
return [
new TwigFunction('chill_custom_fields_group_widget', array(
new TwigFunction('chill_custom_fields_group_widget', [
$this,
'renderWidget'
), array(
'is_safe' => array(
'html'
)
)),
'renderWidget',
], [
'is_safe' => [
'html',
],
]),
];
}
/* (non-PHPdoc)
* @see Twig_ExtensionInterface::getName()
*/
public function getName()
public function getName()
{
return 'chill_custom_fields_group_rendering';
}
/**
* Twig extension that is used to render the value of a custom field group.
*
*
* The presentation of the value is influenced by the document type.
*
*
* @param array $fields The array raw, as stored in the db
* @param CustomFieldsGroud $customFielsGroup The custom field group
* @param string $documentType The type of the document (csv, html)
* @param array $params The parameters for rendering :
* @param array $params The parameters for rendering :
* - layout : allow to choose a different layout by default :
* ChillCustomFieldsBundle:CustomFieldsGroup:render.html.twig
* - show_empty : force show empty field
* @return string HTML representation of the custom field group value, as described in
*
* @return string HTML representation of the custom field group value, as described in
* the CustomFieldInterface. Is HTML safe
*/
public function renderWidget(array $fields, $customFielsGroup, $documentType='html', array $params = array())
public function renderWidget(array $fields, $customFielsGroup, $documentType = 'html', array $params = [])
{
$resolvedParams = array_merge($this->defaultParams, $params);
return $this->container->get('templating')
->render($resolvedParams['layout'], array(
'cFGroup' => $customFielsGroup,
'cFData' => $fields,
'show_empty' => $resolvedParams['show_empty']));
->render($resolvedParams['layout'], [
'cFGroup' => $customFielsGroup,
'cFData' => $fields,
'show_empty' => $resolvedParams['show_empty'], ]);
}
}
/*
* (non-PHPdoc)
* @see \Symfony\Component\DependencyInjection\ContainerAwareInterface::setContainer()
*/
public function setContainer(?ContainerInterface $container = null)
{
$this->container = $container;
}
}