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:
@@ -16,7 +16,6 @@ use Chill\CustomFieldsBundle\Service\CustomFieldProvider;
|
||||
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use LogicException;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
@@ -54,14 +53,14 @@ class CustomFieldType extends AbstractType
|
||||
$builder->get('customFieldsGroup')
|
||||
->addViewTransformer(new CustomFieldsGroupToIdTransformer($this->om));
|
||||
} else {
|
||||
throw new LogicException('The value of group_widget is not handled');
|
||||
throw new \LogicException('The value of group_widget is not handled');
|
||||
}
|
||||
|
||||
$builder
|
||||
->add('ordering', NumberType::class)
|
||||
->add('required', CheckboxType::class, [
|
||||
'required' => false,
|
||||
//'expanded' => TRUE,
|
||||
// 'expanded' => TRUE,
|
||||
'label' => 'Required field',
|
||||
])
|
||||
->add('type', HiddenType::class, ['data' => $options['type']])
|
||||
|
||||
@@ -21,22 +21,20 @@ use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
use function count;
|
||||
|
||||
class CustomFieldsGroupType extends AbstractType
|
||||
{
|
||||
public function __construct(
|
||||
private readonly array $customizableEntities,
|
||||
//TODO : add comment about this variable
|
||||
// TODO : add comment about this variable
|
||||
private readonly TranslatorInterface $translator
|
||||
) {}
|
||||
|
||||
//TODO : details about the function
|
||||
// TODO : details about the function
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
//prepare translation
|
||||
// prepare translation
|
||||
$entities = [];
|
||||
$customizableEntities = []; //TODO : change name too close than $this->customizableEntities
|
||||
$customizableEntities = []; // TODO : change name too close than $this->customizableEntities
|
||||
|
||||
foreach ($this->customizableEntities as $key => $definition) {
|
||||
$entities[$definition['class']] = $this->translator->trans($definition['name']);
|
||||
@@ -55,14 +53,14 @@ class CustomFieldsGroupType extends AbstractType
|
||||
$form = $event->getForm();
|
||||
$group = $event->getData();
|
||||
|
||||
//stop the function if entity is not set
|
||||
if ($group->getEntity() === null) {
|
||||
// stop the function if entity is not set
|
||||
if (null === $group->getEntity()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$optionBuilder = null;
|
||||
|
||||
if (count($customizableEntities[$group->getEntity()]['options']) > 0) {
|
||||
if (\count($customizableEntities[$group->getEntity()]['options']) > 0) {
|
||||
$optionBuilder = $builder
|
||||
->getFormFactory()
|
||||
->createBuilderForProperty(CustomFieldsGroup::class, 'options')
|
||||
|
||||
@@ -16,8 +16,6 @@ use Doctrine\Persistence\ObjectManager;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
|
||||
use function gettype;
|
||||
|
||||
class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
|
||||
{
|
||||
public function __construct(private readonly ObjectManager $om) {}
|
||||
@@ -25,35 +23,25 @@ class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
|
||||
/**
|
||||
* Transforms a string (id) to an object (CustomFieldsGroup).
|
||||
*
|
||||
* @param string $id
|
||||
* @param string $id
|
||||
*
|
||||
* @throws TransformationFailedException if object (report) is not found.
|
||||
* @throws TransformationFailedException if object (report) is not found
|
||||
*/
|
||||
public function reverseTransform($id): ?\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup
|
||||
public function reverseTransform($id): ?CustomFieldsGroup
|
||||
{
|
||||
if (!$id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($id instanceof CustomFieldsGroup) {
|
||||
throw new TransformationFailedException(
|
||||
'The transformation failed: the expected argument on '
|
||||
. 'reverseTransform is an object of type int,'
|
||||
. 'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup, '
|
||||
. 'given'
|
||||
);
|
||||
throw new TransformationFailedException('The transformation failed: the expected argument on reverseTransform is an object of type int,Chill\CustomFieldsBundle\Entity\CustomFieldsGroup, given');
|
||||
}
|
||||
|
||||
$customFieldsGroup = $this->om
|
||||
->getRepository(CustomFieldsGroup::class)->find($id);
|
||||
|
||||
if (null === $customFieldsGroup) {
|
||||
throw new TransformationFailedException(
|
||||
sprintf(
|
||||
'Le group avec le numéro "%s" ne peut pas être trouvé!',
|
||||
$id
|
||||
)
|
||||
);
|
||||
throw new TransformationFailedException(sprintf('Le group avec le numéro "%s" ne peut pas être trouvé!', $id));
|
||||
}
|
||||
|
||||
return $customFieldsGroup;
|
||||
@@ -62,7 +50,7 @@ class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
|
||||
/**
|
||||
* Transforms an custom_field_group to a string (id).
|
||||
*
|
||||
* @param CustomFieldsGroup|null $customFieldsGroup
|
||||
* @param CustomFieldsGroup|null $customFieldsGroup
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -73,14 +61,7 @@ class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
|
||||
}
|
||||
|
||||
if (!$customFieldsGroup instanceof CustomFieldsGroup) {
|
||||
throw new TransformationFailedException(sprintf(
|
||||
'Transformation failed: '
|
||||
. 'the expected type of the transforme function is an '
|
||||
. 'object of type Chill\CustomFieldsBundle\Entity\CustomFieldsGroup, '
|
||||
. '%s given (value : %s)',
|
||||
gettype($customFieldsGroup),
|
||||
$customFieldsGroup
|
||||
));
|
||||
throw new TransformationFailedException(sprintf('Transformation failed: the expected type of the transforme function is an object of type Chill\CustomFieldsBundle\Entity\CustomFieldsGroup, %s given (value : %s)', \gettype($customFieldsGroup), $customFieldsGroup));
|
||||
}
|
||||
|
||||
return $customFieldsGroup->getId();
|
||||
|
||||
@@ -15,10 +15,6 @@ use Chill\CustomFieldsBundle\Entity\CustomField;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
|
||||
use function array_key_exists;
|
||||
|
||||
use const JSON_THROW_ON_ERROR;
|
||||
|
||||
/**
|
||||
* Not in use ? Deprecated ?
|
||||
*/
|
||||
@@ -58,22 +54,22 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface
|
||||
echo "<br> - - 9 - <br>";
|
||||
*/
|
||||
|
||||
//var_dump($customFieldsArray);
|
||||
// var_dump($customFieldsArray);
|
||||
|
||||
$customFieldsArrayRet = [];
|
||||
|
||||
foreach ($customFieldsArray as $key => $value) {
|
||||
$traited = false;
|
||||
|
||||
if (array_key_exists($key, $this->customField)) {
|
||||
if (\array_key_exists($key, $this->customField)) {
|
||||
$type = $this->customField[$key]->getType();
|
||||
|
||||
if (str_starts_with((string) $type, 'ManyToOne')) {
|
||||
// pour le manytoone() faire
|
||||
// un update du form en js ? : http://symfony.com/fr/doc/current/cookbook/form/form_collections.html
|
||||
//
|
||||
//$entityClass = substr($type, 10, -1);
|
||||
//echo $entityClasss;
|
||||
// $entityClass = substr($type, 10, -1);
|
||||
// echo $entityClasss;
|
||||
if (str_starts_with((string) $type, 'ManyToOnePersist')) {
|
||||
// PEUT ETRE A FAIRE SI SEULEMENT $value->getId() ne renvoie rien...
|
||||
//
|
||||
@@ -100,9 +96,9 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface
|
||||
}
|
||||
}
|
||||
|
||||
//echo json_encode($customFieldsArrayRet);
|
||||
// echo json_encode($customFieldsArrayRet);
|
||||
|
||||
return json_encode($customFieldsArrayRet, JSON_THROW_ON_ERROR);
|
||||
return json_encode($customFieldsArrayRet, \JSON_THROW_ON_ERROR);
|
||||
}
|
||||
|
||||
public function transform($customFieldsJSON)
|
||||
@@ -112,7 +108,7 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface
|
||||
if (null === $customFieldsJSON) {
|
||||
$customFieldsArray = [];
|
||||
} else {
|
||||
$customFieldsArray = json_decode((string) $customFieldsJSON, true, 512, JSON_THROW_ON_ERROR);
|
||||
$customFieldsArray = json_decode((string) $customFieldsJSON, true, 512, \JSON_THROW_ON_ERROR);
|
||||
}
|
||||
|
||||
$customFieldsArrayRet = [];
|
||||
@@ -120,7 +116,7 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface
|
||||
foreach ($customFieldsArray as $key => $value) {
|
||||
$traited = false;
|
||||
|
||||
if (array_key_exists($key, $this->customField)) {
|
||||
if (\array_key_exists($key, $this->customField)) {
|
||||
$type = $this->customField[$key]->getType();
|
||||
|
||||
if (str_starts_with((string) $type, 'ManyToOne')) {
|
||||
@@ -131,7 +127,7 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface
|
||||
}
|
||||
|
||||
$customFieldsArrayRet[$key] = $this->om
|
||||
->getRepository('ChillCustomFieldsBundle:' . $entityClass)
|
||||
->getRepository('ChillCustomFieldsBundle:'.$entityClass)
|
||||
->findOneById($value);
|
||||
$traited = true;
|
||||
} elseif ('ManyToMany(Adress)' === $type) {
|
||||
|
||||
@@ -16,8 +16,6 @@ use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
use function array_key_exists;
|
||||
|
||||
/**
|
||||
* This extension create the possibility to add some text
|
||||
* after the input.
|
||||
@@ -30,8 +28,8 @@ abstract class PostTextExtension extends AbstractTypeExtension
|
||||
{
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
if (array_key_exists('post_text', $options)) {
|
||||
//set the post text variable to the view
|
||||
if (\array_key_exists('post_text', $options)) {
|
||||
// set the post text variable to the view
|
||||
$view->vars['post_text'] = $options['post_text'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,9 +29,9 @@ class ChoiceWithOtherType extends AbstractType
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
//add an 'other' entry in choices array
|
||||
// add an 'other' entry in choices array
|
||||
$options['choices'][$this->otherValueLabel] = '_other';
|
||||
//ChoiceWithOther must always be expanded
|
||||
// ChoiceWithOther must always be expanded
|
||||
$options['expanded'] = true;
|
||||
// adding a default value for choice
|
||||
$options['empty_data'] = null;
|
||||
|
||||
@@ -108,7 +108,7 @@ class LinkedCustomFieldsType extends AbstractType
|
||||
*/
|
||||
private function getRootForm(FormInterface $form)
|
||||
{
|
||||
if ($form->getParent() === null) {
|
||||
if (null === $form->getParent()) {
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user