mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -13,14 +13,10 @@ namespace Chill\ThirdPartyBundle\Form\ChoiceLoader;
|
||||
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
|
||||
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
|
||||
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
|
||||
|
||||
use function call_user_func;
|
||||
use function in_array;
|
||||
|
||||
/**
|
||||
* Lazy load third parties.
|
||||
*
|
||||
@@ -61,8 +57,8 @@ class ThirdPartyChoiceLoader implements ChoiceLoaderInterface
|
||||
foreach ($values as $value) {
|
||||
$party = $this->partyRepository->find($value);
|
||||
|
||||
if (false === in_array($this->center, $party->getCenters()->toArray(), true)) {
|
||||
throw new RuntimeException("the party's center is not authorized");
|
||||
if (false === \in_array($this->center, $party->getCenters()->toArray(), true)) {
|
||||
throw new \RuntimeException("the party's center is not authorized");
|
||||
}
|
||||
|
||||
$choices[] = $party;
|
||||
@@ -82,7 +78,7 @@ class ThirdPartyChoiceLoader implements ChoiceLoaderInterface
|
||||
continue;
|
||||
}
|
||||
|
||||
$id = call_user_func($value, $choice);
|
||||
$id = \call_user_func($value, $choice);
|
||||
$values[] = $id;
|
||||
$this->lazyLoadedParties[$id] = $choice;
|
||||
}
|
||||
|
@@ -34,8 +34,6 @@ use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
|
||||
use function array_key_exists;
|
||||
|
||||
class ThirdPartyType extends AbstractType
|
||||
{
|
||||
private readonly bool $askCenter;
|
||||
@@ -71,7 +69,7 @@ class ThirdPartyType extends AbstractType
|
||||
if ($this->askCenter) {
|
||||
$builder
|
||||
->add('centers', PickCenterType::class, [
|
||||
'role' => (array_key_exists('data', $options) && $this->om->contains($options['data'])) ?
|
||||
'role' => (\array_key_exists('data', $options) && $this->om->contains($options['data'])) ?
|
||||
ThirdPartyVoter::UPDATE : ThirdPartyVoter::CREATE,
|
||||
'choice_options' => [
|
||||
'multiple' => true,
|
||||
|
@@ -24,13 +24,9 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
use function array_diff;
|
||||
use function array_merge;
|
||||
use function count;
|
||||
use function is_array;
|
||||
|
||||
/**
|
||||
* @deprecated use the @link{PickThirdPartyDynamicType::class}
|
||||
* @deprecated use the @see{PickThirdPartyDynamicType::class}
|
||||
*
|
||||
* @note do remove ThirdPartyChoiceLoader if this class is removed
|
||||
*/
|
||||
class PickThirdPartyType extends AbstractType
|
||||
@@ -69,7 +65,7 @@ class PickThirdPartyType extends AbstractType
|
||||
|
||||
public function buildView(\Symfony\Component\Form\FormView $view, \Symfony\Component\Form\FormInterface $form, array $options)
|
||||
{
|
||||
$view->vars['attr']['class'] = array_merge(['select2 '], $view->vars['attr']['class'] ?? []);
|
||||
$view->vars['attr']['class'] = \array_merge(['select2 '], $view->vars['attr']['class'] ?? []);
|
||||
$view->vars['attr']['data-3party-picker'] = true;
|
||||
$view->vars['attr']['data-select-interactive-loading'] = true;
|
||||
$view->vars['attr']['data-search-url'] = $this->urlGenerator
|
||||
@@ -94,11 +90,12 @@ class PickThirdPartyType extends AbstractType
|
||||
->setDefined('types')
|
||||
->setRequired('types')
|
||||
->setAllowedValues('types', function ($types) {
|
||||
if (false === is_array($types)) {
|
||||
if (false === \is_array($types)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// return false if one element is not contained in allowed types
|
||||
return count(array_diff($types, $this->typesManager->getTypes())) === 0;
|
||||
return 0 === \count(\array_diff($types, $this->typesManager->getTypes()));
|
||||
});
|
||||
|
||||
$resolver
|
||||
|
@@ -20,12 +20,6 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
use function array_merge;
|
||||
use function implode;
|
||||
use function is_array;
|
||||
use function is_string;
|
||||
use function uasort;
|
||||
|
||||
class PickThirdPartyTypeCategoryType extends \Symfony\Component\Form\AbstractType
|
||||
{
|
||||
private const PREFIX_TYPE = 'chill_3party.key_label.';
|
||||
@@ -34,16 +28,16 @@ class PickThirdPartyTypeCategoryType extends \Symfony\Component\Form\AbstractTyp
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$choices = array_merge(
|
||||
$choices = \array_merge(
|
||||
$this->thirdPartyCategoryRepository->findBy(['active' => true]),
|
||||
$this->thirdPartyTypeManager->getTypes()
|
||||
);
|
||||
|
||||
uasort($choices, function ($itemA, $itemB) {
|
||||
\uasort($choices, function ($itemA, $itemB) {
|
||||
$strA = $itemA instanceof ThirdPartyCategory ? $this->translatableStringHelper
|
||||
->localize($itemA->getName()) : $this->translator->trans(self::PREFIX_TYPE . $itemA);
|
||||
->localize($itemA->getName()) : $this->translator->trans(self::PREFIX_TYPE.$itemA);
|
||||
$strB = $itemB instanceof ThirdPartyCategory ? $this->translatableStringHelper
|
||||
->localize($itemB->getName()) : $this->translator->trans(self::PREFIX_TYPE . $itemB);
|
||||
->localize($itemB->getName()) : $this->translator->trans(self::PREFIX_TYPE.$itemB);
|
||||
|
||||
return $strA <=> $strB;
|
||||
});
|
||||
@@ -57,7 +51,7 @@ class PickThirdPartyTypeCategoryType extends \Symfony\Component\Form\AbstractTyp
|
||||
return $this->translatableStringHelper->localize($item->getName());
|
||||
}
|
||||
|
||||
return self::PREFIX_TYPE . $item;
|
||||
return self::PREFIX_TYPE.$item;
|
||||
},
|
||||
'choice_value' => fn ($item) => $this->reverseTransform($item),
|
||||
]);
|
||||
@@ -75,13 +69,13 @@ class PickThirdPartyTypeCategoryType extends \Symfony\Component\Form\AbstractTyp
|
||||
}
|
||||
|
||||
if ($value instanceof ThirdPartyCategory) {
|
||||
return 'category:' . $value->getId();
|
||||
return 'category:'.$value->getId();
|
||||
}
|
||||
|
||||
if (is_string($value)) {
|
||||
return 'type:' . $value;
|
||||
if (\is_string($value)) {
|
||||
return 'type:'.$value;
|
||||
}
|
||||
|
||||
throw new UnexpectedTypeException($value, implode(' or ', ['array', 'string', ThirdPartyCategory::class]));
|
||||
throw new UnexpectedTypeException($value, \implode(' or ', ['array', 'string', ThirdPartyCategory::class]));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user