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

@@ -135,7 +135,7 @@ class ReportController extends AbstractController
*
* @return Response The web page.
*/
public function editAction($person_id, $report_id)
public function editAction(int|string $person_id, int|string $report_id)
{
$em = $this->getDoctrine()->getManager();
@@ -542,11 +542,10 @@ class ReportController extends AbstractController
* Creates a form to create a Report entity.
*
* @param Report $entity The entity
* @param mixed $cFGroup
*
* @return \Symfony\Component\Form\Form The form
*/
private function createCreateForm(Report $entity, Person $person, $cFGroup)
private function createCreateForm(Report $entity, Person $person, mixed $cFGroup)
{
return $this->createForm(ReportType::class, $entity, [
'action' => $this->generateUrl(

View File

@@ -168,7 +168,7 @@ class LoadReports extends AbstractFixture implements ContainerAwareInterface, Or
*
* @return string|string[] the array of slug if multiple, a single slug otherwise
*/
private function getRandomChoice(CustomField $field)
private function getRandomChoice(CustomField $field): string|array
{
$choices = $field->getOptions()['choices'];
$multiple = $field->getOptions()['multiple'];

View File

@@ -49,12 +49,6 @@ use function uniqid;
class ReportList implements ExportElementValidatedInterface, ListInterface
{
protected CustomFieldProvider $customFieldProvider;
protected CustomFieldsGroup $customfieldsGroup;
protected EntityManagerInterface $em;
protected array $fields = [
'person_id', 'person_firstName', 'person_lastName', 'person_birthdate',
'person_placeOfBirth', 'person_gender', 'person_memo', 'person_email', 'person_phonenumber',
@@ -66,22 +60,8 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
protected array $slugs = [];
protected TranslatableStringHelper $translatableStringHelper;
protected TranslatorInterface $translator;
public function __construct(
CustomFieldsGroup $customfieldsGroup,
TranslatableStringHelper $translatableStringHelper,
TranslatorInterface $translator,
CustomFieldProvider $customFieldProvider,
EntityManagerInterface $em
) {
$this->customfieldsGroup = $customfieldsGroup;
$this->translatableStringHelper = $translatableStringHelper;
$this->translator = $translator;
$this->customFieldProvider = $customFieldProvider;
$this->em = $em;
public function __construct(protected CustomFieldsGroup $customfieldsGroup, protected TranslatableStringHelper $translatableStringHelper, protected TranslatorInterface $translator, protected CustomFieldProvider $customFieldProvider, protected EntityManagerInterface $em)
{
}
public function buildForm(FormBuilderInterface $builder)
@@ -102,26 +82,19 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
'label' => 'Fields to include in export',
'choice_attr' => static function ($val, $key, $index) {
// add a 'data-display-target' for address fields
if (substr($val, 0, 8) === 'address_') {
if (str_starts_with($val, 'address_')) {
return ['data-display-target' => 'address_date'];
}
return [];
},
'choice_label' => function (string $key, string $label): string {
switch (substr($key, 0, 7)) {
case 'person_':
return $this->translator->trans(substr($key, 7, strlen($key) - 7)) .
' (' . $this->translator->trans('Person') . ')';
case 'report_':
return $this->translator->trans(ucfirst(substr($key, 7, strlen($key) - 7))) .
' (' . $this->translator->trans('Report') . ')';
default:
return $label .
' (' . $this->translator->trans("Report's question") . ')';
}
'choice_label' => fn (string $key, string $label): string => match (substr($key, 0, 7)) {
'person_' => $this->translator->trans(substr($key, 7, strlen($key) - 7)) .
' (' . $this->translator->trans('Person') . ')',
'report_' => $this->translator->trans(ucfirst(substr($key, 7, strlen($key) - 7))) .
' (' . $this->translator->trans('Report') . ')',
default => $label .
' (' . $this->translator->trans("Report's question") . ')',
},
'constraints' => [new Callback([
'callback' => static function ($selected, ExecutionContextInterface $context) {
@@ -391,21 +364,13 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
$prefix = substr($f, 0, 7);
$suffix = substr($f, 7);
switch ($prefix) {
case 'person_':
$qb->addSelect(sprintf('person.%s as %s', $suffix, $f));
break;
case 'report_':
$qb->addSelect(sprintf('report.%s as %s', $suffix, $f));
break;
default:
throw new LogicException("this prefix {$prefix} should "
. "not be encountered. Full field: {$f}");
}
match ($prefix) {
'person_' => $qb->addSelect(sprintf('person.%s as %s', $suffix, $f)),
'report_' => $qb->addSelect(sprintf('report.%s as %s', $suffix, $f)),
// no break
default => throw new LogicException("this prefix {$prefix} should "
. "not be encountered. Full field: {$f}"),
};
}
}
@@ -470,7 +435,7 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
// get the field starting with address_
$addressFields = array_filter(
$this->fields,
static fn (string $el): bool => substr($el, 0, 8) === 'address_'
static fn (string $el): bool => str_starts_with($el, 'address_')
);
// check if there is one field starting with address in data

View File

@@ -19,12 +19,8 @@ use Doctrine\ORM\Query\Expr;
class ReportDateFilter implements FilterInterface
{
private RollingDateConverterInterface $rollingDateConverter;
public function __construct(
RollingDateConverterInterface $rollingDateConverter
) {
$this->rollingDateConverter = $rollingDateConverter;
public function __construct(private RollingDateConverterInterface $rollingDateConverter)
{
}
public function addRole(): ?string

View File

@@ -31,29 +31,16 @@ class ReportSearch extends AbstractSearch implements ContainerAwareInterface
{
use \Symfony\Component\DependencyInjection\ContainerAwareTrait;
/**
* @var EntityManagerInterface
*/
private $em;
/**
* @var AuthorizationHelper
*/
private $helper;
/**
* @var \Chill\MainBundle\Entity\User
*/
private $user;
public function __construct(
EntityManagerInterface $em,
AuthorizationHelper $helper,
private EntityManagerInterface $em,
private AuthorizationHelper $helper,
TokenStorageInterface $tokenStorage
) {
$this->em = $em;
$this->helper = $helper;
if (!$tokenStorage->getToken()->getUser() instanceof \Chill\MainBundle\Entity\User) {
throw new RuntimeException('an user must be associated with token');
}

View File

@@ -103,11 +103,9 @@ final class ReportSearchTest extends WebTestCase
}
/**
* @param mixed $username
*
* @return \Symfony\Component\BrowserKit\Client
*/
private function getAuthenticatedClient($username = 'center a_social')
private function getAuthenticatedClient(mixed $username = 'center a_social')
{
return self::createClient([], [
'PHP_AUTH_USER' => $username,

View File

@@ -35,28 +35,8 @@ use function strtr;
*/
class TimelineReportProvider implements TimelineProviderInterface
{
protected CustomFieldsHelper $customFieldsHelper;
protected EntityManager $em;
protected AuthorizationHelper $helper;
protected bool $showEmptyValues;
private Security $security;
public function __construct(
EntityManager $em,
AuthorizationHelper $helper,
Security $security,
CustomFieldsHelper $customFieldsHelper,
$showEmptyValues
) {
$this->em = $em;
$this->helper = $helper;
$this->security = $security;
$this->customFieldsHelper = $customFieldsHelper;
$this->showEmptyValues = $showEmptyValues;
public function __construct(protected EntityManager $em, protected AuthorizationHelper $helper, private Security $security, protected CustomFieldsHelper $customFieldsHelper, protected $showEmptyValues)
{
}
public function fetchQuery($context, array $args)
@@ -212,16 +192,11 @@ class TimelineReportProvider implements TimelineProviderInterface
private function getWhereClause(string $context, array $args): array
{
switch ($context) {
case 'person':
return $this->getWhereClauseForPerson($context, $args);
case 'center':
return $this->getWhereClauseForCenter($context, $args);
default:
throw new UnexpectedValueException("This context {$context} is not implemented");
}
return match ($context) {
'person' => $this->getWhereClauseForPerson($context, $args),
'center' => $this->getWhereClauseForCenter($context, $args),
default => throw new UnexpectedValueException("This context {$context} is not implemented"),
};
}
private function getWhereClauseForCenter(string $context, array $args): array