mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-08 15:54:59 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -18,18 +18,9 @@ use Chill\CustomFieldsBundle\Form\Type\ChoicesType;
|
||||
use Chill\CustomFieldsBundle\Form\Type\ChoiceWithOtherType;
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use LogicException;
|
||||
use Symfony\Bridge\Twig\TwigEngine;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
use Twig\Environment;
|
||||
use function array_key_exists;
|
||||
use function count;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function LogicException;
|
||||
|
||||
class CustomFieldChoice extends AbstractCustomField
|
||||
{
|
||||
@@ -61,7 +52,7 @@ class CustomFieldChoice extends AbstractCustomField
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, CustomField $customField)
|
||||
{
|
||||
//prepare choices
|
||||
// prepare choices
|
||||
$choices = [];
|
||||
$customFieldOptions = $customField->getOptions();
|
||||
|
||||
@@ -71,7 +62,7 @@ class CustomFieldChoice extends AbstractCustomField
|
||||
}
|
||||
}
|
||||
|
||||
//prepare $options
|
||||
// prepare $options
|
||||
$options = [
|
||||
'multiple' => $customFieldOptions[self::MULTIPLE],
|
||||
'choices' => array_combine(array_values($choices), array_keys($choices)),
|
||||
@@ -79,11 +70,11 @@ class CustomFieldChoice extends AbstractCustomField
|
||||
'label' => $this->translatableStringHelper->localize($customField->getName()),
|
||||
];
|
||||
|
||||
//if allow_other = true
|
||||
// if allow_other = true
|
||||
if (true === $customFieldOptions[self::ALLOW_OTHER]) {
|
||||
$otherValueLabel = null;
|
||||
|
||||
if (array_key_exists(self::OTHER_VALUE_LABEL, $customFieldOptions)) {
|
||||
if (\array_key_exists(self::OTHER_VALUE_LABEL, $customFieldOptions)) {
|
||||
$otherValueLabel = $this->translatableStringHelper->localize(
|
||||
$customFieldOptions[self::OTHER_VALUE_LABEL]
|
||||
);
|
||||
@@ -99,8 +90,8 @@ class CustomFieldChoice extends AbstractCustomField
|
||||
)
|
||||
->addModelTransformer(new CustomFieldDataTransformer($this, $customField))
|
||||
);
|
||||
} else { //if allow_other = false
|
||||
//we add the 'expanded' to options
|
||||
} else { // if allow_other = false
|
||||
// we add the 'expanded' to options
|
||||
$options['expanded'] = $customFieldOptions[self::EXPANDED];
|
||||
|
||||
$builder->add(
|
||||
@@ -164,7 +155,7 @@ class CustomFieldChoice extends AbstractCustomField
|
||||
return $serialized;
|
||||
}
|
||||
|
||||
public function extractOtherValue(CustomField $cf, ?array $data = null)
|
||||
public function extractOtherValue(CustomField $cf, array $data = null)
|
||||
{
|
||||
return $data['_other'];
|
||||
}
|
||||
@@ -185,7 +176,7 @@ class CustomFieldChoice extends AbstractCustomField
|
||||
if ($this->allowOtherChoice($cf)) {
|
||||
$labels = $cf->getOptions()[self::OTHER_VALUE_LABEL];
|
||||
|
||||
if (!is_array($labels) || count($labels) === 0) {
|
||||
if (!\is_array($labels) || 0 === \count($labels)) {
|
||||
$labels['back'] = 'other value';
|
||||
}
|
||||
$choices['_other'] = $this->translatableStringHelper
|
||||
@@ -210,8 +201,8 @@ class CustomFieldChoice extends AbstractCustomField
|
||||
*
|
||||
* Used in list exports.
|
||||
*
|
||||
* @param string $choiceSlug the slug of the choice we want to know if it was checked
|
||||
* @param array|string $data the data of the field
|
||||
* @param string $choiceSlug the slug of the choice we want to know if it was checked
|
||||
* @param array|string $data the data of the field
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -223,10 +214,10 @@ class CustomFieldChoice extends AbstractCustomField
|
||||
|
||||
if ($cf->getOptions()[self::MULTIPLE]) {
|
||||
if ($cf->getOptions()[self::ALLOW_OTHER]) {
|
||||
return in_array($choiceSlug, $this->deserialize($data, $cf)['_choices'], true);
|
||||
return \in_array($choiceSlug, $this->deserialize($data, $cf)['_choices'], true);
|
||||
}
|
||||
|
||||
return in_array($choiceSlug, $this->deserialize($data, $cf), true);
|
||||
return \in_array($choiceSlug, $this->deserialize($data, $cf), true);
|
||||
}
|
||||
|
||||
if ($cf->getOptions()[self::ALLOW_OTHER]) {
|
||||
@@ -243,9 +234,9 @@ class CustomFieldChoice extends AbstractCustomField
|
||||
}
|
||||
|
||||
// if multiple choice OR multiple/single choice with other
|
||||
if (is_array($value)) {
|
||||
if (\is_array($value)) {
|
||||
// if allow other
|
||||
if (array_key_exists('_choices', $value)) {
|
||||
if (\array_key_exists('_choices', $value)) {
|
||||
if (null === $value['_choices']) {
|
||||
return true;
|
||||
}
|
||||
@@ -253,7 +244,7 @@ class CustomFieldChoice extends AbstractCustomField
|
||||
return empty($value['_choices']);
|
||||
} // we do not have 'allow other'
|
||||
|
||||
if (count($value) === 1) {
|
||||
if (1 === \count($value)) {
|
||||
return empty($value[0]);
|
||||
}
|
||||
|
||||
@@ -262,7 +253,7 @@ class CustomFieldChoice extends AbstractCustomField
|
||||
|
||||
return empty($value);
|
||||
|
||||
throw LogicException('This case is not expected.');
|
||||
throw \LogicException('This case is not expected.');
|
||||
}
|
||||
|
||||
public function isMultiple(CustomField $cf)
|
||||
@@ -273,19 +264,16 @@ class CustomFieldChoice extends AbstractCustomField
|
||||
/**
|
||||
* @internal this function is able to receive data whichever is the value of "other", "multiple"
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param mixed $documentType
|
||||
*
|
||||
* @return string html representation
|
||||
*/
|
||||
public function render($value, CustomField $customField, $documentType = 'html')
|
||||
{
|
||||
//extract the data. They are under a _choice key if they are stored with allow_other
|
||||
// extract the data. They are under a _choice key if they are stored with allow_other
|
||||
$data = $value['_choices'] ?? $value;
|
||||
$selected = (is_array($data)) ? $data : [$data];
|
||||
$selected = (\is_array($data)) ? $data : [$data];
|
||||
$choices = $customField->getOptions()[self::CHOICES];
|
||||
|
||||
if (in_array('_other', $selected, true)) {
|
||||
if (\in_array('_other', $selected, true)) {
|
||||
$choices[] = ['name' => $value['_other'], 'slug' => '_other'];
|
||||
}
|
||||
|
||||
@@ -323,7 +311,7 @@ class CustomFieldChoice extends AbstractCustomField
|
||||
$value = $this->guessValue($serialized);
|
||||
|
||||
// set in an array : we want a multiple
|
||||
$fixedValue = is_array($value) ? $value : [$value];
|
||||
$fixedValue = \is_array($value) ? $value : [$value];
|
||||
|
||||
if ($allowOther) {
|
||||
return $this->deserializeWithAllowOther($serialized, $fixedValue);
|
||||
@@ -337,9 +325,9 @@ class CustomFieldChoice extends AbstractCustomField
|
||||
$value = $this->guessValue($serialized);
|
||||
|
||||
// set in a single value. We must have a single string
|
||||
$fixedValue = is_array($value) ?
|
||||
$fixedValue = \is_array($value) ?
|
||||
// check if the array has an element, if not replace by empty string
|
||||
count($value) > 0 ? end($value) : ''
|
||||
\count($value) > 0 ? end($value) : ''
|
||||
:
|
||||
$value;
|
||||
|
||||
@@ -372,16 +360,17 @@ class CustomFieldChoice extends AbstractCustomField
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!is_array($value)) {
|
||||
if (!\is_array($value)) {
|
||||
return $value;
|
||||
}
|
||||
// we have a field with "allow other"
|
||||
if (array_key_exists('_choices', $value)) {
|
||||
if (\array_key_exists('_choices', $value)) {
|
||||
return $value['_choices'];
|
||||
}
|
||||
|
||||
// we have a field with "multiple"
|
||||
return $value;
|
||||
|
||||
throw LogicException('This case is not expected.');
|
||||
throw \LogicException('This case is not expected.');
|
||||
}
|
||||
}
|
||||
|
@@ -15,9 +15,6 @@ use Chill\CustomFieldsBundle\Entity\CustomField;
|
||||
use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldDataTransformer;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use Symfony\Bundle\TwigBundle\TwigEngine;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
@@ -34,7 +31,7 @@ use Twig\Environment;
|
||||
*/
|
||||
class CustomFieldDate extends AbstractCustomField
|
||||
{
|
||||
final public const DATE_FORMAT = DateTime::RFC3339;
|
||||
final public const DATE_FORMAT = \DateTime::RFC3339;
|
||||
|
||||
final public const FORMAT = 'format';
|
||||
|
||||
@@ -71,8 +68,8 @@ class CustomFieldDate extends AbstractCustomField
|
||||
{
|
||||
$validatorFunction = static function ($value, ExecutionContextInterface $context) {
|
||||
try {
|
||||
$date = new DateTime($value);
|
||||
} catch (Exception) {
|
||||
$date = new \DateTime($value);
|
||||
} catch (\Exception) {
|
||||
$context->buildViolation('The expression "%expression%" is invalid', [
|
||||
'%expression%' => $value,
|
||||
])
|
||||
@@ -107,7 +104,7 @@ class CustomFieldDate extends AbstractCustomField
|
||||
return null;
|
||||
}
|
||||
|
||||
return DateTime::createFromFormat(self::DATE_FORMAT, $serialized);
|
||||
return \DateTime::createFromFormat(self::DATE_FORMAT, $serialized);
|
||||
}
|
||||
|
||||
public function getName()
|
||||
@@ -129,7 +126,7 @@ class CustomFieldDate extends AbstractCustomField
|
||||
|
||||
default:
|
||||
$template = 'ChillCustomFieldsBundle:CustomFieldsRendering:date.'
|
||||
. $documentType . '.twig';
|
||||
.$documentType.'.twig';
|
||||
|
||||
return $this->templating
|
||||
->render($template, [
|
||||
@@ -165,7 +162,7 @@ class CustomFieldDate extends AbstractCustomField
|
||||
// add required
|
||||
$fieldOptions['required'] = false;
|
||||
|
||||
//add label
|
||||
// add label
|
||||
$fieldOptions['label'] = $this->translatableStringHelper->localize($customField->getName());
|
||||
|
||||
// add constraints if required
|
||||
@@ -176,8 +173,8 @@ class CustomFieldDate extends AbstractCustomField
|
||||
return;
|
||||
}
|
||||
|
||||
$value = DateTime::createFromFormat(self::DATE_FORMAT, $timestamp);
|
||||
$after = new DateTime($options[self::MIN]);
|
||||
$value = \DateTime::createFromFormat(self::DATE_FORMAT, $timestamp);
|
||||
$after = new \DateTime($options[self::MIN]);
|
||||
|
||||
if ($value < $after) {
|
||||
$context
|
||||
@@ -197,8 +194,8 @@ class CustomFieldDate extends AbstractCustomField
|
||||
return;
|
||||
}
|
||||
|
||||
$value = DateTime::createFromFormat(self::DATE_FORMAT, $timestamp);
|
||||
$before = new DateTime($options[self::MAX]);
|
||||
$value = \DateTime::createFromFormat(self::DATE_FORMAT, $timestamp);
|
||||
$before = new \DateTime($options[self::MAX]);
|
||||
|
||||
if ($value > $before) {
|
||||
$context
|
||||
|
@@ -21,7 +21,7 @@ interface CustomFieldInterface
|
||||
* user.
|
||||
*
|
||||
* @param \Chill\CustomFieldsBundle\CustomField\FormBuilderInterface $builder
|
||||
* @param \Chill\CustomFieldsBundle\CustomField\CustomField $customField
|
||||
* @param \Chill\CustomFieldsBundle\CustomField\CustomField $customField
|
||||
*
|
||||
* @return \Symfony\Component\Form\FormTypeInterface the form type
|
||||
*/
|
||||
@@ -42,7 +42,6 @@ interface CustomFieldInterface
|
||||
* value which may be used in the process.
|
||||
*
|
||||
* @param \Chill\CustomFieldsBundle\CustomField\CustomField $customField
|
||||
* @param mixed $serialized
|
||||
*/
|
||||
public function deserialize($serialized, CustomField $customField);
|
||||
|
||||
@@ -58,9 +57,8 @@ interface CustomFieldInterface
|
||||
/**
|
||||
* Return a repsentation of the value of the CustomField.
|
||||
*
|
||||
* @param mixed $value the raw value, **not deserialized** (= as stored in the db)
|
||||
* @param mixed $value the raw value, **not deserialized** (= as stored in the db)
|
||||
* @param \Chill\CustomFieldsBundle\CustomField\CustomField $customField
|
||||
* @param mixed $documentType
|
||||
*
|
||||
* @return string an html representation of the value
|
||||
*/
|
||||
@@ -69,7 +67,6 @@ interface CustomFieldInterface
|
||||
/**
|
||||
* Transform the value into a format that can be stored in DB.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param \Chill\CustomFieldsBundle\CustomField\CustomField $customField
|
||||
*/
|
||||
public function serialize($value, CustomField $customField);
|
||||
|
@@ -15,19 +15,11 @@ use Chill\CustomFieldsBundle\Entity\CustomField;
|
||||
use Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option;
|
||||
use Chill\CustomFieldsBundle\EntityRepository\CustomFieldLongChoice\OptionRepository;
|
||||
use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldDataTransformer;
|
||||
use Chill\FamilyMembersBundle\Templating\Twig;
|
||||
use Chill\MainBundle\Form\Type\Select2ChoiceType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use LogicException;
|
||||
use Symfony\Bridge\Twig\TwigEngine;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
use function get_class;
|
||||
use function gettype;
|
||||
use function is_object;
|
||||
|
||||
class CustomFieldLongChoice extends AbstractCustomField
|
||||
{
|
||||
final public const KEY = 'key';
|
||||
@@ -46,7 +38,7 @@ class CustomFieldLongChoice extends AbstractCustomField
|
||||
false,
|
||||
true
|
||||
);
|
||||
//create a local copy of translatable string helper
|
||||
// create a local copy of translatable string helper
|
||||
$translatableStringHelper = $this->translatableStringHelper;
|
||||
$builder->add($customField->getSlug(), Select2ChoiceType::class, [
|
||||
'choices' => $entries,
|
||||
@@ -73,7 +65,7 @@ class CustomFieldLongChoice extends AbstractCustomField
|
||||
|
||||
public function buildOptionsForm(FormBuilderInterface $builder)
|
||||
{
|
||||
//create a selector between different keys
|
||||
// create a selector between different keys
|
||||
$keys = $this->optionRepository->getKeys();
|
||||
$choices = [];
|
||||
|
||||
@@ -105,7 +97,7 @@ class CustomFieldLongChoice extends AbstractCustomField
|
||||
{
|
||||
$option = $this->deserialize($value, $customField);
|
||||
$template = 'ChillCustomFieldsBundle:CustomFieldsRendering:choice_long.'
|
||||
. $documentType . '.twig';
|
||||
.$documentType.'.twig';
|
||||
|
||||
return $this->templating
|
||||
->render($template, [
|
||||
@@ -120,9 +112,7 @@ class CustomFieldLongChoice extends AbstractCustomField
|
||||
}
|
||||
|
||||
if (!$value instanceof Option) {
|
||||
throw new LogicException('the value should be an instance of '
|
||||
. 'Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option, '
|
||||
. is_object($value) ? $value::class : gettype($value) . ' given');
|
||||
throw new \LogicException('the value should be an instance of Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option, '.\is_object($value) ? $value::class : \gettype($value).' given');
|
||||
}
|
||||
|
||||
// we place the id in array, to allow in the future multiple select
|
||||
|
@@ -13,7 +13,6 @@ namespace Chill\CustomFieldsBundle\CustomFields;
|
||||
|
||||
use Chill\CustomFieldsBundle\Entity\CustomField;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Symfony\Bundle\TwigBundle\TwigEngine;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
@@ -49,10 +48,10 @@ class CustomFieldNumber extends AbstractCustomField
|
||||
{
|
||||
$options = $customField->getOptions();
|
||||
|
||||
//select the type depending to the SCALE
|
||||
// select the type depending to the SCALE
|
||||
$type = (0 === $options[self::SCALE] || null === $options[self::SCALE]) ?
|
||||
IntegerType::class : NumberType::class;
|
||||
//'integer' : 'number';
|
||||
// 'integer' : 'number';
|
||||
|
||||
$fieldOptions = $this->prepareFieldOptions($customField, $type);
|
||||
|
||||
@@ -97,7 +96,7 @@ class CustomFieldNumber extends AbstractCustomField
|
||||
public function render($value, CustomField $customField, $documentType = 'html')
|
||||
{
|
||||
$template = 'ChillCustomFieldsBundle:CustomFieldsRendering:number.'
|
||||
. $documentType . '.twig';
|
||||
.$documentType.'.twig';
|
||||
$options = $customField->getOptions();
|
||||
|
||||
return $this->templating
|
||||
@@ -132,7 +131,7 @@ class CustomFieldNumber extends AbstractCustomField
|
||||
// add required
|
||||
$fieldOptions['required'] = false;
|
||||
|
||||
//add label
|
||||
// add label
|
||||
$fieldOptions['label'] = $this->translatableStringHelper->localize($customField->getName());
|
||||
|
||||
// add constraints if required
|
||||
|
@@ -13,16 +13,12 @@ namespace Chill\CustomFieldsBundle\CustomFields;
|
||||
|
||||
use Chill\CustomFieldsBundle\Entity\CustomField;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Symfony\Bundle\TwigBundle\TwigEngine;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
use Twig\Environment;
|
||||
use function array_key_exists;
|
||||
|
||||
class CustomFieldText extends AbstractCustomField
|
||||
{
|
||||
@@ -51,7 +47,7 @@ class CustomFieldText extends AbstractCustomField
|
||||
$attrArray = [];
|
||||
|
||||
if (
|
||||
array_key_exists(self::MULTIPLE_CF_INLINE, $options)
|
||||
\array_key_exists(self::MULTIPLE_CF_INLINE, $options)
|
||||
&& $options[self::MULTIPLE_CF_INLINE]
|
||||
) {
|
||||
$attrArray['class'] = 'multiple-cf-inline';
|
||||
|
@@ -14,10 +14,8 @@ namespace Chill\CustomFieldsBundle\CustomFields;
|
||||
use Chill\CustomFieldsBundle\Entity\CustomField;
|
||||
use Chill\CustomFieldsBundle\Form\Type\CustomFieldsTitleType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Symfony\Bundle\TwigBundle\TwigEngine;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Twig\Environment;
|
||||
|
||||
class CustomFieldTitle extends AbstractCustomField
|
||||
|
Reference in New Issue
Block a user