fix: SA: Fix "...an unused use..." rule.

Also fix a critical bug in `ListPerson.php`.

SA stands for Static Analysis.
This commit is contained in:
Pol Dellaiera
2021-11-16 15:06:43 +01:00
parent 8bebe1f904
commit 7462babbeb
4 changed files with 83 additions and 268 deletions

View File

@@ -1,21 +1,6 @@
<?php
/*
* Copyright (C) 2015 Julien Fastré <julien.fastre@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/>.
*/
declare(strict_types=1);
namespace Chill\CustomFieldsBundle\CustomFields;
@@ -29,36 +14,21 @@ use Symfony\Bridge\Twig\TwigEngine;
use Chill\MainBundle\Form\Type\Select2ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class CustomFieldLongChoice extends AbstractCustomField
{
/**
*
* @var OptionRepository
*/
private $optionRepository;
private OptionRepository $optionRepository;
/**
*
* @var TranslatableStringHelper
*/
private $translatableStringHelper;
private TranslatableStringHelper $translatableStringHelper;
/**
* @var TwigEngine
*/
private $templating;
private TwigEngine $templating;
const KEY = 'key';
public const KEY = 'key';
public function __construct(OptionRepository $optionRepository,
public function __construct(
OptionRepository $optionRepository,
TranslatableStringHelper $translatableStringHelper,
TwigEngine $twigEngine)
{
TwigEngine $twigEngine
) {
$this->optionRepository = $optionRepository;
$this->translatableStringHelper = $translatableStringHelper;
$this->templating = $twigEngine;
@@ -76,12 +46,7 @@ class CustomFieldLongChoice extends AbstractCustomField
'choice_label' => function(Option $option) use ($translatableStringHelper) {
return $translatableStringHelper->localize($option->getText());
},
'choice_value' => function ($key) use ($entries) {
if ($key === NULL) {
return null;
}
return $key->getId();
},
'choice_value' => static fn (Option $key): ?int => $key === null ? null : $key->getId(),
'multiple' => false,
'expanded' => false,
'required' => $customField->isRequired(),
@@ -89,15 +54,16 @@ class CustomFieldLongChoice extends AbstractCustomField
'group_by' => function(Option $option) use ($translatableStringHelper) {
if ($option->hasParent()) {
return $translatableStringHelper->localize($option->getParent()->getText());
} else {
return $translatableStringHelper->localize($option->getText());
}
return $translatableStringHelper->localize($option->getText());
},
'label' => $translatableStringHelper->localize($customField->getName())
));
$builder->get($customField->getSlug())
->addModelTransformer(new CustomFieldDataTransformer($this, $customField));
$builder
->get($customField->getSlug())
->addModelTransformer(new CustomFieldDataTransformer($this, $customField));
}
public function buildOptionsForm(FormBuilderInterface $builder)