DX: fix phpstan errors

This commit is contained in:
Julien Fastré 2023-02-07 22:34:37 +01:00
parent e5c183aa44
commit fa481fd795
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
3 changed files with 55 additions and 28 deletions

View File

@ -116,23 +116,23 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
{ {
$string = '@person '; $string = '@person ';
$string .= empty($data['_default']) ? '' : $data['_default'] . ' '; $string .= !isset($data['_default']) ? '' : $data['_default'] . ' ';
foreach (['firstname', 'lastname', 'gender', 'city'] as $key) { foreach (['firstname', 'lastname', 'gender', 'city'] as $key) {
$string .= empty($data[$key]) ? '' : $key . ':' . $string .= !isset($data[$key]) ? '' : $key . ':' .
// add quote if contains spaces // add quote if contains spaces
(strpos($data[$key], ' ') !== false ? '"' . $data[$key] . '"' : $data[$key]) (strpos($data[$key], ' ') !== false ? '"' . $data[$key] . '"' : $data[$key])
. ' '; . ' ';
} }
foreach (['birthdate', 'birthdate-before', 'birthdate-after'] as $key) { foreach (['birthdate', 'birthdate-before', 'birthdate-after'] as $key) {
$string .= empty($data[$key]) ? $string .= !isset($data[$key]) ?
'' ''
: :
$key . ':' . $data[$key]->format('Y-m-d') . ' '; $key . ':' . $data[$key]->format('Y-m-d') . ' ';
} }
$string .= empty($data['phonenumber']) ? '' : 'phonenumber:' . $data['phonenumber']->getNationalNumber(); $string .= !isset($data['phonenumber']) ? '' : 'phonenumber:' . $data['phonenumber']->getNationalNumber();
return $string; return $string;
} }
@ -163,7 +163,7 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
$phonenumber = new PhoneNumber(); $phonenumber = new PhoneNumber();
$phonenumber->setNationalNumber($terms['phonenumber']); $phonenumber->setNationalNumber($terms['phonenumber']);
} catch (Exception $ex) { } catch (Exception $ex) {
throw new ParsingException("The data for {$key} is " throw new ParsingException("The data for phonenumber is "
. 'not parsable', 0, $ex); . 'not parsable', 0, $ex);
} }
@ -267,14 +267,30 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
'city' => $city, 'city' => $city,
] = $terms + array_fill_keys(self::POSSIBLE_KEYS, null); ] = $terms + array_fill_keys(self::POSSIBLE_KEYS, null);
foreach (['birthdateBefore', 'birthdateAfter', 'birthdate'] as $v) { if (null !== $birthdate) {
if (null !== ${$v}) { try {
try { $birthdate = new DateTime($birthdate);
${$v} = new DateTime(${$v}); } catch (Exception $e) {
} catch (Exception $e) { throw new ParsingException('The date is '
throw new ParsingException('The date is ' . 'not parsable', 0, $e);
. 'not parsable', 0, $e); }
} }
if (null !== $birthdateBefore) {
try {
$birthdateBefore = new DateTime($birthdateBefore);
} catch (Exception $e) {
throw new ParsingException('The date is '
. 'not parsable', 0, $e);
}
}
if (null !== $birthdateAfter) {
try {
$birthdateAfter = new DateTime($birthdateAfter);
} catch (Exception $e) {
throw new ParsingException('The date is '
. 'not parsable', 0, $e);
} }
} }
@ -311,14 +327,30 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
'city' => $city, 'city' => $city,
] = $terms + array_fill_keys(self::POSSIBLE_KEYS, null); ] = $terms + array_fill_keys(self::POSSIBLE_KEYS, null);
foreach (['birthdateBefore', 'birthdateAfter', 'birthdate'] as $v) { if (null !== $birthdate) {
if (null !== ${$v}) { try {
try { $birthdate = new DateTime($birthdate);
${$v} = new DateTime(${$v}); } catch (Exception $e) {
} catch (Exception $e) { throw new ParsingException('The date is '
throw new ParsingException('The date is ' . 'not parsable', 0, $e);
. 'not parsable', 0, $e); }
} }
if (null !== $birthdateBefore) {
try {
$birthdateBefore = new DateTime($birthdateBefore);
} catch (Exception $e) {
throw new ParsingException('The date is '
. 'not parsable', 0, $e);
}
}
if (null !== $birthdateAfter) {
try {
$birthdateAfter = new DateTime($birthdateAfter);
} catch (Exception $e) {
throw new ParsingException('The date is '
. 'not parsable', 0, $e);
} }
} }

View File

@ -78,15 +78,14 @@ class ParticipationOverlapValidator extends ConstraintValidator
if ($overlaps->hasIntersections()) { if ($overlaps->hasIntersections()) {
foreach ($overlaps->getIntersections() as [$start, $end, $ids]) { foreach ($overlaps->getIntersections() as [$start, $end, $ids]) {
$msg = null === $end ? $constraint->message : $msg = $constraint->message;
$constraint->message;
$this->context->buildViolation($msg) $this->context->buildViolation($msg)
->setParameters([ ->setParameters([
'{{ start }}' => $start->format('d-m-Y'), '{{ start }}' => $start->format('d-m-Y'),
'{{ end }}' => null === $end ? null : $end->format('d-m-Y'), '{{ end }}' => null === $end ? null : $end->format('d-m-Y'),
'{{ ids }}' => $ids, '{{ ids }}' => $ids,
'{{ name }}' => $this->personRender->renderString($participation->getPerson(), []), '{{ name }}' => $this->personRender->renderString($participations[0]->getPerson(), []),
]) ])
->addViolation(); ->addViolation();
} }

View File

@ -59,10 +59,6 @@ class ThirdPartyChoiceLoader implements ChoiceLoaderInterface
$choices = []; $choices = [];
foreach ($values as $value) { foreach ($values as $value) {
if (null === $value || '' === $value) {
continue;
}
$party = $this->partyRepository->find($value); $party = $this->partyRepository->find($value);
if (false === in_array($this->center, $party->getCenters()->toArray(), true)) { if (false === in_array($this->center, $party->getCenters()->toArray(), true)) {