DX: fix phpstan errors

This commit is contained in:
2023-02-07 22:34:37 +01:00
parent e5c183aa44
commit fa481fd795
3 changed files with 55 additions and 28 deletions

View File

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