apply rules rector

This commit is contained in:
2023-07-19 22:48:26 +02:00
parent 6e6f19c499
commit 74ed34ba97
40 changed files with 250 additions and 697 deletions

View File

@@ -45,28 +45,13 @@ class ListHouseholdInPeriod implements ListInterface, GroupedExportInterface
'compositionType',
];
private ExportAddressHelper $addressHelper;
private AggregateStringHelper $aggregateStringHelper;
private EntityManagerInterface $entityManager;
private RollingDateConverterInterface $rollingDateConverter;
private TranslatableStringExportLabelHelper $translatableStringHelper;
public function __construct(
ExportAddressHelper $addressHelper,
AggregateStringHelper $aggregateStringHelper,
EntityManagerInterface $entityManager,
RollingDateConverterInterface $rollingDateConverter,
TranslatableStringExportLabelHelper $translatableStringHelper
private ExportAddressHelper $addressHelper,
private AggregateStringHelper $aggregateStringHelper,
private EntityManagerInterface $entityManager,
private RollingDateConverterInterface $rollingDateConverter,
private TranslatableStringExportLabelHelper $translatableStringHelper
) {
$this->addressHelper = $addressHelper;
$this->aggregateStringHelper = $aggregateStringHelper;
$this->entityManager = $entityManager;
$this->rollingDateConverter = $rollingDateConverter;
$this->translatableStringHelper = $translatableStringHelper;
}
public function buildForm(FormBuilderInterface $builder)
@@ -100,27 +85,21 @@ class ListHouseholdInPeriod implements ListInterface, GroupedExportInterface
public function getLabels($key, array $values, $data)
{
if (substr($key, 0, strlen('address_fields')) === 'address_fields') {
if (str_starts_with($key, 'address_fields')) {
return $this->addressHelper->getLabel($key, $values, $data, 'address_fields');
}
switch ($key) {
case 'membersId':
case 'membersName':
return $this->aggregateStringHelper->getLabelMulti($key, $values, 'export.list.household.' . $key);
return match ($key) {
'membersId', 'membersName' => $this->aggregateStringHelper->getLabelMulti($key, $values, 'export.list.household.' . $key),
'compositionType' => $this->translatableStringHelper->getLabel($key, $values, 'export.list.household.' . $key),
default => static function ($value) use ($key) {
if ('_header' === $value) {
return 'export.list.household.' . $key;
}
case 'compositionType':
return $this->translatableStringHelper->getLabel($key, $values, 'export.list.household.' . $key);
default:
return static function ($value) use ($key) {
if ('_header' === $value) {
return 'export.list.household.' . $key;
}
return (string) $value;
};
}
return (string) $value;
},
};
}
public function getQueryKeys($data): array

View File

@@ -39,16 +39,8 @@ class StepFilterBetweenDates implements FilterInterface
'course.inactive_long' => AccompanyingPeriod::STEP_CONFIRMED_INACTIVE_LONG,
];
private RollingDateConverterInterface $rollingDateConverter;
private TranslatorInterface $translator;
public function __construct(
RollingDateConverterInterface $rollingDateConverter,
TranslatorInterface $translator
) {
$this->rollingDateConverter = $rollingDateConverter;
$this->translator = $translator;
public function __construct(private RollingDateConverterInterface $rollingDateConverter, private TranslatorInterface $translator)
{
}
public function addRole(): ?string

View File

@@ -92,129 +92,104 @@ final readonly class ListAccompanyingPeriodHelper
return $this->addressHelper->getLabel($key, $values, $data, 'acp_address_fields');
}
switch ($key) {
case 'stepSince':
case 'openingDate':
case 'closingDate':
case 'referrerSince':
case 'acpCreatedAt':
case 'acpUpdatedAt':
return $this->dateTimeHelper->getLabel('export.list.acp.' . $key);
return match ($key) {
'stepSince', 'openingDate', 'closingDate', 'referrerSince', 'acpCreatedAt', 'acpUpdatedAt' => $this->dateTimeHelper->getLabel('export.list.acp.' . $key),
'origin', 'closingMotive', 'job' => function ($value) use ($key) {
if ('_header' === $value) {
return 'export.list.acp.' . $key;
}
case 'origin':
case 'closingMotive':
case 'job':
return function ($value) use ($key) {
if ('_header' === $value) {
return 'export.list.acp.' . $key;
}
if (null === $value) {
return '';
}
if (null === $value) {
return '';
}
return $this->translatableStringHelper->localize(json_decode($value, true, 512, JSON_THROW_ON_ERROR));
},
'locationPersonName', 'requestorPerson' => function ($value) use ($key) {
if ('_header' === $value) {
return 'export.list.acp.' . $key;
}
return $this->translatableStringHelper->localize(json_decode($value, true, 512, JSON_THROW_ON_ERROR));
};
if (null === $value || null === $person = $this->personRepository->find($value)) {
return '';
}
case 'locationPersonName':
case 'requestorPerson':
return function ($value) use ($key) {
if ('_header' === $value) {
return 'export.list.acp.' . $key;
}
return $this->personRender->renderString($person, []);
},
'requestorThirdParty' => function ($value) use ($key) {
if ('_header' === $value) {
return 'export.list.acp.' . $key;
}
if (null === $value || null === $person = $this->personRepository->find($value)) {
return '';
}
if (null === $value || null === $thirdparty = $this->thirdPartyRepository->find($value)) {
return '';
}
return $this->personRender->renderString($person, []);
};
return $this->thirdPartyRender->renderString($thirdparty, []);
},
'scopes' => function ($value) use ($key) {
if ('_header' === $value) {
return 'export.list.acp.' . $key;
}
case 'requestorThirdParty':
return function ($value) use ($key) {
if ('_header' === $value) {
return 'export.list.acp.' . $key;
}
if (null === $value) {
return '';
}
if (null === $value || null === $thirdparty = $this->thirdPartyRepository->find($value)) {
return '';
}
return implode(
'|',
array_map(
fn ($s) => $this->translatableStringHelper->localize($s),
json_decode($value, true, 512, JSON_THROW_ON_ERROR)
)
);
},
'socialIssues' => function ($value) use ($key) {
if ('_header' === $value) {
return 'export.list.acp.' . $key;
}
return $this->thirdPartyRender->renderString($thirdparty, []);
};
if (null === $value) {
return '';
}
case 'scopes':
return function ($value) use ($key) {
if ('_header' === $value) {
return 'export.list.acp.' . $key;
}
return implode(
'|',
array_map(
fn ($s) => $this->socialIssueRender->renderString($this->socialIssueRepository->find($s), []),
json_decode($value, true, 512, JSON_THROW_ON_ERROR)
)
);
},
'step' => fn ($value) => match ($value) {
'_header' => 'export.list.acp.step',
null => '',
AccompanyingPeriod::STEP_DRAFT => $this->translator->trans('course.draft'),
AccompanyingPeriod::STEP_CONFIRMED => $this->translator->trans('course.confirmed'),
AccompanyingPeriod::STEP_CLOSED => $this->translator->trans('course.closed'),
AccompanyingPeriod::STEP_CONFIRMED_INACTIVE_SHORT => $this->translator->trans('course.inactive_short'),
AccompanyingPeriod::STEP_CONFIRMED_INACTIVE_LONG => $this->translator->trans('course.inactive_long'),
default => $value,
},
'intensity' => fn ($value) => match ($value) {
'_header' => 'export.list.acp.intensity',
null => '',
AccompanyingPeriod::INTENSITY_OCCASIONAL => $this->translator->trans('occasional'),
AccompanyingPeriod::INTENSITY_REGULAR => $this->translator->trans('regular'),
default => $value,
},
default => static function ($value) use ($key) {
if ('_header' === $value) {
return 'export.list.acp.' . $key;
}
if (null === $value) {
return '';
}
if (null === $value) {
return '';
}
return implode(
'|',
array_map(
fn ($s) => $this->translatableStringHelper->localize($s),
json_decode($value, true, 512, JSON_THROW_ON_ERROR)
)
);
};
case 'socialIssues':
return function ($value) use ($key) {
if ('_header' === $value) {
return 'export.list.acp.' . $key;
}
if (null === $value) {
return '';
}
return implode(
'|',
array_map(
fn ($s) => $this->socialIssueRender->renderString($this->socialIssueRepository->find($s), []),
json_decode($value, true, 512, JSON_THROW_ON_ERROR)
)
);
};
case 'step':
return fn ($value) => match ($value) {
'_header' => 'export.list.acp.step',
null => '',
AccompanyingPeriod::STEP_DRAFT => $this->translator->trans('course.draft'),
AccompanyingPeriod::STEP_CONFIRMED => $this->translator->trans('course.confirmed'),
AccompanyingPeriod::STEP_CLOSED => $this->translator->trans('course.closed'),
AccompanyingPeriod::STEP_CONFIRMED_INACTIVE_SHORT => $this->translator->trans('course.inactive_short'),
AccompanyingPeriod::STEP_CONFIRMED_INACTIVE_LONG => $this->translator->trans('course.inactive_long'),
default => $value,
};
case 'intensity':
return fn ($value) => match ($value) {
'_header' => 'export.list.acp.intensity',
null => '',
AccompanyingPeriod::INTENSITY_OCCASIONAL => $this->translator->trans('occasional'),
AccompanyingPeriod::INTENSITY_REGULAR => $this->translator->trans('regular'),
default => $value,
};
default:
return static function ($value) use ($key) {
if ('_header' === $value) {
return 'export.list.acp.' . $key;
}
if (null === $value) {
return '';
}
return $value;
};
}
return $value;
},
};
}
public function addSelectClauses(QueryBuilder $qb, \DateTimeImmutable $calcDate): void

View File

@@ -24,12 +24,9 @@ class HouseholdMenuBuilder implements LocalMenuBuilderInterface
*/
protected $translator;
private Security $security;
public function __construct(TranslatorInterface $translator, Security $security)
public function __construct(TranslatorInterface $translator, private Security $security)
{
$this->translator = $translator;
$this->security = $security;
}
public function buildMenu($menuId, MenuItem $menu, array $parameters): void

View File

@@ -19,11 +19,8 @@ use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkEvalu
final class AccompanyingPeriodWorkEvaluationDocumentNotificationHandler implements NotificationHandlerInterface
{
private AccompanyingPeriodWorkEvaluationDocumentRepository $accompanyingPeriodWorkEvaluationDocumentRepository;
public function __construct(AccompanyingPeriodWorkEvaluationDocumentRepository $accompanyingPeriodWorkEvaluationDocumentRepository)
public function __construct(private AccompanyingPeriodWorkEvaluationDocumentRepository $accompanyingPeriodWorkEvaluationDocumentRepository)
{
$this->accompanyingPeriodWorkEvaluationDocumentRepository = $accompanyingPeriodWorkEvaluationDocumentRepository;
}
public function getTemplate(Notification $notification, array $options = []): string

View File

@@ -19,11 +19,8 @@ use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepos
final class AccompanyingPeriodWorkNotificationHandler implements NotificationHandlerInterface
{
private AccompanyingPeriodWorkRepository $accompanyingPeriodWorkRepository;
public function __construct(AccompanyingPeriodWorkRepository $accompanyingPeriodWorkRepository)
public function __construct(private AccompanyingPeriodWorkRepository $accompanyingPeriodWorkRepository)
{
$this->accompanyingPeriodWorkRepository = $accompanyingPeriodWorkRepository;
}
public function getTemplate(Notification $notification, array $options = []): string

View File

@@ -37,24 +37,12 @@ use function count;
*/
final readonly class AccompanyingPeriodACLAwareRepository implements AccompanyingPeriodACLAwareRepositoryInterface
{
private AccompanyingPeriodRepository $accompanyingPeriodRepository;
private AuthorizationHelperForCurrentUserInterface $authorizationHelper;
private CenterResolverManagerInterface $centerResolver;
private Security $security;
public function __construct(
AccompanyingPeriodRepository $accompanyingPeriodRepository,
Security $security,
AuthorizationHelperForCurrentUserInterface $authorizationHelper,
CenterResolverManagerInterface $centerResolverDispatcher
private AccompanyingPeriodRepository $accompanyingPeriodRepository,
private Security $security,
private AuthorizationHelperForCurrentUserInterface $authorizationHelper,
private CenterResolverManagerInterface $centerResolver
) {
$this->accompanyingPeriodRepository = $accompanyingPeriodRepository;
$this->security = $security;
$this->authorizationHelper = $authorizationHelper;
$this->centerResolver = $centerResolverDispatcher;
}
public function buildQueryOpenedAccompanyingCourseByUserAndPostalCodes(?User $user, array $postalCodes = []): QueryBuilder
@@ -178,7 +166,6 @@ final readonly class AccompanyingPeriodACLAwareRepository implements Accompanyin
* @param QueryBuilder $qb where the accompanying period have the `ap` alias
* @param array<Scope> $scopesCanSee
* @param array<Scope> $scopesCanSeeConfidential
* @return QueryBuilder
*/
public function addACLClauses(QueryBuilder $qb, array $scopesCanSee, array $scopesCanSeeConfidential): QueryBuilder
{
@@ -272,10 +259,8 @@ final readonly class AccompanyingPeriodACLAwareRepository implements Accompanyin
}
/**
* @param QueryBuilder $qb
* @param list<array{center: Center, scopeOnRole: list<Scope>, scopeCanSeeConfidential: list<Scope>}> $centerScopes
* @param bool $allowNoCenter if true, will allow to see the periods linked to person which does not have any center. Very few edge case when some Person are not associated to a center.
* @return QueryBuilder
*/
public function addACLMultiCenterOnQuery(QueryBuilder $qb, array $centerScopes, bool $allowNoCenter = false): QueryBuilder
{

View File

@@ -107,15 +107,12 @@ class AccompanyingPeriodVoter extends AbstractChillVoter implements ProvideRoleH
*/
public const SEE_CONFIDENTIAL_ALL = 'CHILL_PERSON_ACCOMPANYING_PERIOD_SEE_CONFIDENTIAL';
private Security $security;
private VoterHelperInterface $voterHelper;
public function __construct(
Security $security,
private Security $security,
VoterHelperFactoryInterface $voterHelperFactory
) {
$this->security = $security;
$this->voterHelper = $voterHelperFactory
->generate(self::class)
->addCheckFor(null, [self::CREATE, self::REASSIGN_BULK])

View File

@@ -51,48 +51,18 @@ class AccompanyingPeriodContext implements
DocGeneratorContextWithAdminFormInterface,
DocGeneratorContextWithPublicFormInterface
{
private BaseContextData $baseContextData;
private DocumentCategoryRepository $documentCategoryRepository;
private EntityManagerInterface $em;
private NormalizerInterface $normalizer;
private PersonRenderInterface $personRender;
private PersonRepository $personRepository;
private TranslatableStringHelperInterface $translatableStringHelper;
private TranslatorInterface $translator;
private ThirdPartyRender $thirdPartyRender;
private ThirdPartyRepository $thirdPartyRepository;
public function __construct(
DocumentCategoryRepository $documentCategoryRepository,
NormalizerInterface $normalizer,
TranslatableStringHelperInterface $translatableStringHelper,
EntityManagerInterface $em,
PersonRenderInterface $personRender,
PersonRepository $personRepository,
TranslatorInterface $translator,
BaseContextData $baseContextData,
ThirdPartyRender $thirdPartyRender,
ThirdPartyRepository $thirdPartyRepository
private DocumentCategoryRepository $documentCategoryRepository,
private NormalizerInterface $normalizer,
private TranslatableStringHelperInterface $translatableStringHelper,
private EntityManagerInterface $em,
private PersonRenderInterface $personRender,
private PersonRepository $personRepository,
private TranslatorInterface $translator,
private BaseContextData $baseContextData,
private ThirdPartyRender $thirdPartyRender,
private ThirdPartyRepository $thirdPartyRepository
) {
$this->documentCategoryRepository = $documentCategoryRepository;
$this->normalizer = $normalizer;
$this->translatableStringHelper = $translatableStringHelper;
$this->em = $em;
$this->personRender = $personRender;
$this->personRepository = $personRepository;
$this->translator = $translator;
$this->baseContextData = $baseContextData;
$this->thirdPartyRender = $thirdPartyRender;
$this->thirdPartyRepository = $thirdPartyRepository;
}
public function adminFormReverseTransform(array $data): array

View File

@@ -38,36 +38,8 @@ class AccompanyingPeriodWorkEvaluationContext implements
DocGeneratorContextWithAdminFormInterface,
DocGeneratorContextWithPublicFormInterface
{
private AccompanyingPeriodWorkContext $accompanyingPeriodWorkContext;
private EntityManagerInterface $em;
private EvaluationRepository $evaluationRepository;
private NormalizerInterface $normalizer;
private TranslatableStringHelperInterface $translatableStringHelper;
private ThirdPartyRender $thirdPartyRender;
private TranslatorInterface $translator;
public function __construct(
AccompanyingPeriodWorkContext $accompanyingPeriodWorkContext,
EntityManagerInterface $em,
EvaluationRepository $evaluationRepository,
NormalizerInterface $normalizer,
TranslatableStringHelperInterface $translatableStringHelper,
ThirdPartyRender $thirdPartyRender,
TranslatorInterface $translator
) {
$this->accompanyingPeriodWorkContext = $accompanyingPeriodWorkContext;
$this->em = $em;
$this->evaluationRepository = $evaluationRepository;
$this->normalizer = $normalizer;
$this->translatableStringHelper = $translatableStringHelper;
$this->thirdPartyRender = $thirdPartyRender;
$this->translator = $translator;
public function __construct(private AccompanyingPeriodWorkContext $accompanyingPeriodWorkContext, private EntityManagerInterface $em, private EvaluationRepository $evaluationRepository, private NormalizerInterface $normalizer, private TranslatableStringHelperInterface $translatableStringHelper, private ThirdPartyRender $thirdPartyRender, private TranslatorInterface $translator)
{
}
public function adminFormReverseTransform(array $data): array

View File

@@ -56,64 +56,25 @@ use function count;
*/
final class PersonContext implements PersonContextInterface
{
private AuthorizationHelperInterface $authorizationHelper;
private BaseContextData $baseContextData;
private CenterResolverManagerInterface $centerResolverManager;
private DocumentCategoryRepository $documentCategoryRepository;
private EntityManagerInterface $em;
private NormalizerInterface $normalizer;
private ScopeRepositoryInterface $scopeRepository;
private Security $security;
private bool $showScopes;
private TranslatableStringHelperInterface $translatableStringHelper;
private TranslatorInterface $translator;
private ThirdPartyRender $thirdPartyRender;
private ThirdPartyRepository $thirdPartyRepository;
private ResidentialAddressRepository $residentialAddressRepository;
public function __construct(
AuthorizationHelperInterface $authorizationHelper,
BaseContextData $baseContextData,
CenterResolverManagerInterface $centerResolverManager,
DocumentCategoryRepository $documentCategoryRepository,
EntityManagerInterface $em,
NormalizerInterface $normalizer,
private AuthorizationHelperInterface $authorizationHelper,
private BaseContextData $baseContextData,
private CenterResolverManagerInterface $centerResolverManager,
private DocumentCategoryRepository $documentCategoryRepository,
private EntityManagerInterface $em,
private NormalizerInterface $normalizer,
ParameterBagInterface $parameterBag,
ScopeRepositoryInterface $scopeRepository,
Security $security,
TranslatorInterface $translator,
TranslatableStringHelperInterface $translatableStringHelper,
ThirdPartyRender $thirdPartyRender,
ThirdPartyRepository $thirdPartyRepository,
ResidentialAddressRepository $residentialAddressRepository
private ScopeRepositoryInterface $scopeRepository,
private Security $security,
private TranslatorInterface $translator,
private TranslatableStringHelperInterface $translatableStringHelper,
private ThirdPartyRender $thirdPartyRender,
private ThirdPartyRepository $thirdPartyRepository,
private ResidentialAddressRepository $residentialAddressRepository
) {
$this->authorizationHelper = $authorizationHelper;
$this->centerResolverManager = $centerResolverManager;
$this->baseContextData = $baseContextData;
$this->documentCategoryRepository = $documentCategoryRepository;
$this->em = $em;
$this->normalizer = $normalizer;
$this->scopeRepository = $scopeRepository;
$this->security = $security;
$this->showScopes = $parameterBag->get('chill_main')['acl']['form_show_scopes'];
$this->translator = $translator;
$this->translatableStringHelper = $translatableStringHelper;
$this->thirdPartyRender = $thirdPartyRender;
$this->thirdPartyRepository = $thirdPartyRepository;
$this->residentialAddressRepository = $residentialAddressRepository;
}
public function adminFormReverseTransform(array $data): array

View File

@@ -488,9 +488,7 @@ class AccompanyingPeriodACLAwareRepositoryTest extends KernelTestCase
}
/**
* @param Person $person
* @param array<Scope> $scopes
* @return AccompanyingPeriod
*/
private function buildPeriod(Person $person, array $scopes, User|null $creator, bool $confirm): AccompanyingPeriod
{

View File

@@ -44,11 +44,9 @@ class RelationshipNoDuplicateValidator extends ConstraintValidator
foreach ($relationships as $r) {
if (spl_object_hash($r) !== spl_object_hash($value)
and
(
and (
($r->getFromPerson() === $fromPerson and $r->getToPerson() === $toPerson)
||
($r->getFromPerson() === $toPerson and $r->getToPerson() === $fromPerson)
|| ($r->getFromPerson() === $toPerson and $r->getToPerson() === $fromPerson)
)
) {
$this->context->buildViolation($constraint->message)