mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-11-15 00:27:35 +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.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user