DX: apply rector rules up to php8.0

This commit is contained in:
2023-04-15 01:05:37 +02:00
parent d8870e906f
commit dde3002100
714 changed files with 2348 additions and 9263 deletions

View File

@@ -38,25 +38,6 @@ class CreateFieldsOnGroupCommand extends Command
public const ARG_PATH = 'path';
private $availableLanguages;
/**
* @var CustomFieldProvider
*/
private $customFieldProvider;
private $customizablesEntities;
/**
* @var EntityManager
*/
private $entityManager;
/**
* @var ValidatorInterface
*/
private $validator;
/**
* CreateFieldsOnGroupCommand constructor.
*
@@ -64,17 +45,12 @@ class CreateFieldsOnGroupCommand extends Command
* @param $customizablesEntities
*/
public function __construct(
CustomFieldProvider $customFieldProvider,
EntityManager $entityManager,
ValidatorInterface $validator,
$availableLanguages,
$customizablesEntities
private CustomFieldProvider $customFieldProvider,
private EntityManager $entityManager,
private ValidatorInterface $validator,
private $availableLanguages,
private $customizablesEntities
) {
$this->customFieldProvider = $customFieldProvider;
$this->entityManager = $entityManager;
$this->validator = $validator;
$this->availableLanguages = $availableLanguages;
$this->customizablesEntities = $customizablesEntities;
parent::__construct();
}

View File

@@ -57,10 +57,8 @@ class CustomFieldController extends AbstractController
/**
* Displays a form to edit an existing CustomField entity.
*
* @param mixed $id
*/
public function editAction($id)
public function editAction(mixed $id)
{
$em = $this->getDoctrine()->getManager();
@@ -112,10 +110,8 @@ class CustomFieldController extends AbstractController
* Finds and displays a CustomField entity.
*
* @deprecated is not used since there is no link to show action
*
* @param mixed $id
*/
public function showAction($id)
public function showAction(mixed $id)
{
$em = $this->getDoctrine()->getManager();
@@ -131,10 +127,8 @@ class CustomFieldController extends AbstractController
/**
* Edits an existing CustomField entity.
*
* @param mixed $id
*/
public function updateAction(Request $request, $id)
public function updateAction(Request $request, mixed $id)
{
$em = $this->getDoctrine()->getManager();
@@ -170,11 +164,10 @@ class CustomFieldController extends AbstractController
*
* @param CustomField $entity The entity
* @param string
* @param mixed $type
*
* @return \Symfony\Component\Form\Form The form
*/
private function createCreateForm(CustomField $entity, $type)
private function createCreateForm(CustomField $entity, mixed $type)
{
$form = $this->createForm(CustomFieldType::class, $entity, [
'action' => $this->generateUrl(
@@ -195,11 +188,10 @@ class CustomFieldController extends AbstractController
* Creates a form to edit a CustomField entity.
*
* @param CustomField $entity The entity
* @param mixed $type
*
* @return \Symfony\Component\Form\Form The form
*/
private function createEditForm(CustomField $entity, $type)
private function createEditForm(CustomField $entity, mixed $type)
{
$form = $this->createForm(CustomFieldType::class, $entity, [
'action' => $this->generateUrl('customfield_update', ['id' => $entity->getId()]),

View File

@@ -33,25 +33,11 @@ use function in_array;
*/
class CustomFieldsGroupController extends AbstractController
{
/**
* @var CustomFieldProvider
*/
private $customfieldProvider;
/**
* @var TranslatorInterface
*/
private $translator;
/**
* CustomFieldsGroupController constructor.
*/
public function __construct(
CustomFieldProvider $customFieldProvider,
TranslatorInterface $translator
) {
$this->customfieldProvider = $customFieldProvider;
$this->translator = $translator;
public function __construct(private CustomFieldProvider $customfieldProvider, private TranslatorInterface $translator)
{
}
/**
@@ -85,10 +71,8 @@ class CustomFieldsGroupController extends AbstractController
/**
* Displays a form to edit an existing CustomFieldsGroup entity.
*
* @param mixed $id
*/
public function editAction($id)
public function editAction(mixed $id)
{
$em = $this->getDoctrine()->getManager();
@@ -241,10 +225,8 @@ class CustomFieldsGroupController extends AbstractController
/**
* Finds and displays a CustomFieldsGroup entity.
*
* @param mixed $id
*/
public function showAction($id)
public function showAction(mixed $id)
{
$em = $this->getDoctrine()->getManager();
@@ -265,10 +247,8 @@ class CustomFieldsGroupController extends AbstractController
/**
* Edits an existing CustomFieldsGroup entity.
*
* @param mixed $id
*/
public function updateAction(Request $request, $id)
public function updateAction(Request $request, mixed $id)
{
$em = $this->getDoctrine()->getManager();

View File

@@ -44,27 +44,18 @@ class CustomFieldChoice extends AbstractCustomField
private $defaultLocales;
/**
* @var TwigEngine
*/
private $templating;
/**
* @var TranslatableStringHelper Helper that find the string in current locale from an array of translation
*/
private $translatableStringHelper;
/**
* CustomFieldChoice constructor.
*/
public function __construct(
TranslatorInterface $translator,
TwigEngine $templating,
TranslatableStringHelper $translatableStringHelper
private TwigEngine $templating,
/**
* @var TranslatableStringHelper Helper that find the string in current locale from an array of translation
*/
private TranslatableStringHelper $translatableStringHelper
) {
$this->defaultLocales = $translator->getFallbackLocales();
$this->templating = $templating;
$this->translatableStringHelper = $translatableStringHelper;
}
public function allowOtherChoice(CustomField $cf)
@@ -228,7 +219,7 @@ class CustomFieldChoice extends AbstractCustomField
*
* @return bool
*/
public function isChecked(CustomField $cf, $choiceSlug, $data)
public function isChecked(CustomField $cf, $choiceSlug, array|string $data)
{
if (null === $data) {
return false;
@@ -330,10 +321,9 @@ class CustomFieldChoice extends AbstractCustomField
* deserialized the data from the database to a multiple
* field.
*
* @param mixed $serialized
* @param bool $allowOther
*/
private function deserializeToMultiple($serialized, $allowOther)
private function deserializeToMultiple(mixed $serialized, $allowOther)
{
$value = $this->guessValue($serialized);
@@ -387,7 +377,7 @@ class CustomFieldChoice extends AbstractCustomField
*
* @return mixed
*/
private function guessValue($value)
private function guessValue(array|string $value)
{
if (null === $value) {
return null;

View File

@@ -44,20 +44,8 @@ class CustomFieldDate extends AbstractCustomField
*/
public const MIN = 'min';
/**
* @var TwigEngine
*/
private $templating;
/**
* @var TranslatableStringHelper
*/
private $translatableStringHelper;
public function __construct(TwigEngine $templating, TranslatableStringHelper $translatableStringHelper)
public function __construct(private TwigEngine $templating, private TranslatableStringHelper $translatableStringHelper)
{
$this->templating = $templating;
$this->translatableStringHelper = $translatableStringHelper;
}
public function buildForm(FormBuilderInterface $builder, CustomField $customField)
@@ -82,7 +70,7 @@ class CustomFieldDate extends AbstractCustomField
$validatorFunction = static function ($value, ExecutionContextInterface $context) {
try {
$date = new DateTime($value);
} catch (Exception $e) {
} catch (Exception) {
$context->buildViolation('The expression "%expression%" is invalid', [
'%expression%' => $value,
])

View File

@@ -30,20 +30,8 @@ class CustomFieldLongChoice extends AbstractCustomField
{
public const KEY = 'key';
private OptionRepository $optionRepository;
private TwigEngine $templating;
private TranslatableStringHelper $translatableStringHelper;
public function __construct(
OptionRepository $optionRepository,
TranslatableStringHelper $translatableStringHelper,
TwigEngine $twigEngine
) {
$this->optionRepository = $optionRepository;
$this->translatableStringHelper = $translatableStringHelper;
$this->templating = $twigEngine;
public function __construct(private OptionRepository $optionRepository, private TranslatableStringHelper $translatableStringHelper, private TwigEngine $templating)
{
}
public function buildForm(FormBuilderInterface $builder, CustomField $customField)
@@ -130,7 +118,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) ? get_class($value) : gettype($value) . ' given');
. is_object($value) ? $value::class : gettype($value) . ' given');
}
// we place the id in array, to allow in the future multiple select

View File

@@ -39,20 +39,8 @@ class CustomFieldNumber extends AbstractCustomField
public const SCALE = 'scale';
/**
* @var TwigEngine
*/
private $templating;
/**
* @var TranslatableStringHelper
*/
private $translatableStringHelper;
public function __construct(TwigEngine $templating, TranslatableStringHelper $translatableStringHelper)
public function __construct(private TwigEngine $templating, private TranslatableStringHelper $translatableStringHelper)
{
$this->templating = $templating;
$this->translatableStringHelper = $translatableStringHelper;
}
public function buildForm(FormBuilderInterface $builder, CustomField $customField)

View File

@@ -29,26 +29,14 @@ class CustomFieldText extends AbstractCustomField
public const MULTIPLE_CF_INLINE = 'multipleCFInline';
private $requestStack;
/**
* @var TwigEngine
*/
private $templating;
/**
* @var TranslatableStringHelper Helper that find the string in current locale from an array of translation
*/
private $translatableStringHelper;
public function __construct(
RequestStack $requestStack,
TwigEngine $templating,
TranslatableStringHelper $translatableStringHelper
private RequestStack $requestStack,
private TwigEngine $templating,
/**
* @var TranslatableStringHelper Helper that find the string in current locale from an array of translation
*/
private TranslatableStringHelper $translatableStringHelper
) {
$this->requestStack = $requestStack;
$this->templating = $templating;
$this->translatableStringHelper = $translatableStringHelper;
}
/**

View File

@@ -27,26 +27,14 @@ class CustomFieldTitle extends AbstractCustomField
public const TYPE_TITLE = 'title';
private $requestStack;
/**
* @var TwigEngine
*/
private $templating;
/**
* @var TranslatableStringHelper Helper that find the string in current locale from an array of translation
*/
private $translatableStringHelper;
public function __construct(
RequestStack $requestStack,
TwigEngine $templating,
TranslatableStringHelper $translatableStringHelper
private RequestStack $requestStack,
private TwigEngine $templating,
/**
* @var TranslatableStringHelper Helper that find the string in current locale from an array of translation
*/
private TranslatableStringHelper $translatableStringHelper
) {
$this->requestStack = $requestStack;
$this->templating = $templating;
$this->translatableStringHelper = $translatableStringHelper;
}
public function buildForm(FormBuilderInterface $builder, CustomField $customField)

View File

@@ -18,12 +18,10 @@ class OptionRepository extends EntityRepository
{
/**
* @param string $key
* @param mixed $includeParents
* @param mixed $active
*
* @return Option[]
*/
public function findFilteredByKey($key, $includeParents = true, $active = true)
public function findFilteredByKey($key, mixed $includeParents = true, mixed $active = true)
{
$qb = $this->createQueryBuilder('option');
$qb->where('option.key = :key');

View File

@@ -30,29 +30,8 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
class CustomFieldType extends AbstractType
{
/**
* @var CustomFieldProvider
*/
private $customFieldProvider;
/**
* @var ObjectManager
*/
private $om;
/**
* @var TranslatableStringHelper
*/
private $translatableStringHelper;
public function __construct(
CustomFieldProvider $compiler,
ObjectManager $om,
TranslatableStringHelper $translatableStringHelper
) {
$this->customFieldProvider = $compiler;
$this->om = $om;
$this->translatableStringHelper = $translatableStringHelper;
public function __construct(private CustomFieldProvider $customFieldProvider, private ObjectManager $om, private TranslatableStringHelper $translatableStringHelper)
{
}
public function buildForm(FormBuilderInterface $builder, array $options)

View File

@@ -25,17 +25,11 @@ use function count;
class CustomFieldsGroupType extends AbstractType
{
private $customizableEntities; //TODO : add comment about this variable
/**
* @var \Symfony\Component\Translation\TranslatorInterface
*/
private $translator;
public function __construct(array $customizableEntities, TranslatorInterface $translator)
{
$this->customizableEntities = $customizableEntities;
$this->translator = $translator;
public function __construct(
private array $customizableEntities,
//TODO : add comment about this variable
private TranslatorInterface $translator
) {
}
//TODO : details about the function

View File

@@ -17,19 +17,8 @@ use Symfony\Component\Form\DataTransformerInterface;
class CustomFieldDataTransformer implements DataTransformerInterface
{
/**
* @var \Chill\CustomFieldsBundle\Entity\CustomField
*/
private $customField;
private $customFieldDefinition;
public function __construct(
CustomFieldInterface $customFieldDefinition,
CustomField $customField
) {
$this->customFieldDefinition = $customFieldDefinition;
$this->customField = $customField;
public function __construct(private CustomFieldInterface $customFieldDefinition, private CustomField $customField)
{
}
public function reverseTransform($value)

View File

@@ -20,14 +20,8 @@ use function gettype;
class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
{
/**
* @var ObjectManager
*/
private $om;
public function __construct(ObjectManager $om)
public function __construct(private ObjectManager $om)
{
$this->om = $om;
}
/**
@@ -36,10 +30,8 @@ class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
* @param string $id
*
* @throws TransformationFailedException if object (report) is not found.
*
* @return CustomFieldsGroup|null
*/
public function reverseTransform($id)
public function reverseTransform($id): ?\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup
{
if (!$id) {
return null;

View File

@@ -26,12 +26,8 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface
{
private array $customField;
private ObjectManager $om;
public function __construct(ObjectManager $om)
public function __construct(private ObjectManager $om)
{
$this->om = $om;
$customFields = $this->om
->getRepository(CustomField::class)
->findAll();
@@ -72,13 +68,13 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface
if (array_key_exists($key, $this->customField)) {
$type = $this->customField[$key]->getType();
if (strpos($type, 'ManyToOne') === 0) {
if (str_starts_with($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;
if (strpos($type, 'ManyToOnePersist') === 0) {
if (str_starts_with($type, 'ManyToOnePersist')) {
// PEUT ETRE A FAIRE SI SEULEMENT $value->getId() ne renvoie rien...
//
//
@@ -127,8 +123,8 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface
if (array_key_exists($key, $this->customField)) {
$type = $this->customField[$key]->getType();
if (strpos($type, 'ManyToOne') === 0) {
if (strpos($type, 'ManyToOnePersist') === 0) {
if (str_starts_with($type, 'ManyToOne')) {
if (str_starts_with($type, 'ManyToOnePersist')) {
$entityClass = substr($type, 17, -1);
} else {
$entityClass = substr($type, 10, -1);

View File

@@ -24,14 +24,8 @@ class CustomFieldType extends AbstractType
*/
private $customFieldCompiler;
/**
* @var ObjectManager
*/
private $om;
public function __construct(ObjectManager $om, CustomFieldProvider $compiler)
public function __construct(private ObjectManager $om, CustomFieldProvider $compiler)
{
$this->om = $om;
$this->customFieldCompiler = $compiler;
}

View File

@@ -46,14 +46,8 @@ class LinkedCustomFieldsType extends AbstractType
*/
private $options = [];
/**
* @var TranslatableStringHelper
*/
private $translatableStringHelper;
public function __construct(TranslatableStringHelper $helper)
public function __construct(private TranslatableStringHelper $translatableStringHelper)
{
$this->translatableStringHelper = $helper;
}
/**

View File

@@ -22,15 +22,6 @@ use Doctrine\ORM\EntityManagerInterface;
*/
class CustomFieldsHelper
{
/**
* @var EntityManagerInterface The entity manager
*/
private $em;
/** @var CustomFieldProvider Provider of all the declared custom
* fields */
private $provider;
/**
* Constructor.
*
@@ -38,12 +29,8 @@ class CustomFieldsHelper
* @param CustomFieldProvider $provider The customfield provider that
* contains all the declared custom fields
*/
public function __construct(
EntityManagerInterface $em,
CustomFieldProvider $provider
) {
$this->em = $em;
$this->provider = $provider;
public function __construct(private EntityManagerInterface $em, private CustomFieldProvider $provider)
{
}
public function isEmptyValue(array $fields, CustomField $customField)

View File

@@ -31,11 +31,6 @@ class CustomFieldRenderingTwig extends AbstractExtension implements ContainerAwa
*/
private $container;
/**
* @var CustomFieldsHelper
*/
private $customFieldsHelper;
/**
* @var array The default parameters
*/
@@ -43,9 +38,8 @@ class CustomFieldRenderingTwig extends AbstractExtension implements ContainerAwa
'label_layout' => 'ChillCustomFieldsBundle:CustomField:render_label.html.twig',
];
public function __construct(CustomFieldsHelper $customFieldsHelper)
public function __construct(private CustomFieldsHelper $customFieldsHelper)
{
$this->customFieldsHelper = $customFieldsHelper;
}
/**

View File

@@ -400,7 +400,7 @@ final class CustomFieldsChoiceTest extends KernelTestCase
*
* @param mixed $data deserialized data
*/
public function testIsEmptyValueEmpty($data)
public function testIsEmptyValueEmpty(mixed $data)
{
$customField = $this->generateCustomField([
CustomFieldChoice::ALLOW_OTHER => false,
@@ -417,14 +417,12 @@ final class CustomFieldsChoiceTest extends KernelTestCase
// test function isEmptyValue
//
////////////////////////////////////////
/**
* test the not empty with the not-empty data provider.
*
* @param mixed $data
* @dataProvider serializedRepresentationDataProvider
*/
public function testIsEmptyValueNotEmpty($data)
public function testIsEmptyValueNotEmpty(mixed $data)
{
$customField = $this->generateCustomField([
CustomFieldChoice::ALLOW_OTHER => false,

View File

@@ -99,12 +99,10 @@ final class CustomFieldsGroupRenderingTwigTest extends KernelTestCase
}
/**
* @param mixed $slug
* @param mixed $name
*
* @return CustomField
*/
private function getSimpleCustomFieldText($slug, $name)
private function getSimpleCustomFieldText(mixed $slug, mixed $name)
{
return (new CustomField())
->setSlug($slug)