mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -23,18 +23,9 @@ use Chill\MainBundle\Search\Utils\ExtractPhonenumberFromPattern;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Form\Type\GenderType;
|
||||
use Chill\PersonBundle\Repository\PersonACLAwareRepositoryInterface;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use libphonenumber\PhoneNumber;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
|
||||
use function array_fill_keys;
|
||||
use function array_filter;
|
||||
use function array_key_exists;
|
||||
use function array_merge;
|
||||
|
||||
class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterface
|
||||
{
|
||||
@@ -94,23 +85,23 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
|
||||
{
|
||||
$string = '@person ';
|
||||
|
||||
$string .= !isset($data['_default']) ? '' : $data['_default'] . ' ';
|
||||
$string .= !isset($data['_default']) ? '' : $data['_default'].' ';
|
||||
|
||||
foreach (['firstname', 'lastname', 'gender', 'city'] as $key) {
|
||||
$string .= !isset($data[$key]) ? '' : $key . ':' .
|
||||
$string .= !isset($data[$key]) ? '' : $key.':'.
|
||||
// add quote if contains spaces
|
||||
(str_contains((string) $data[$key], ' ') ? '"' . $data[$key] . '"' : $data[$key])
|
||||
. ' ';
|
||||
(str_contains((string) $data[$key], ' ') ? '"'.$data[$key].'"' : $data[$key])
|
||||
.' ';
|
||||
}
|
||||
|
||||
foreach (['birthdate', 'birthdate-before', 'birthdate-after'] as $key) {
|
||||
$string .= !isset($data[$key]) ?
|
||||
''
|
||||
:
|
||||
$key . ':' . $data[$key]->format('Y-m-d') . ' ';
|
||||
$key.':'.$data[$key]->format('Y-m-d').' ';
|
||||
}
|
||||
|
||||
$string .= !isset($data['phonenumber']) ? '' : 'phonenumber:' . $data['phonenumber']->getNationalNumber();
|
||||
$string .= !isset($data['phonenumber']) ? '' : 'phonenumber:'.$data['phonenumber']->getNationalNumber();
|
||||
|
||||
return $string;
|
||||
}
|
||||
@@ -125,24 +116,22 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
|
||||
|
||||
// parse dates
|
||||
foreach (['birthdate', 'birthdate-before', 'birthdate-after'] as $key) {
|
||||
if (array_key_exists($key, $terms)) {
|
||||
if (\array_key_exists($key, $terms)) {
|
||||
try {
|
||||
$date = new DateTime($terms[$key]);
|
||||
} catch (Exception $ex) {
|
||||
throw new ParsingException("The date for {$key} is "
|
||||
. 'not parsable', 0, $ex);
|
||||
$date = new \DateTime($terms[$key]);
|
||||
} catch (\Exception $ex) {
|
||||
throw new ParsingException("The date for {$key} is ".'not parsable', 0, $ex);
|
||||
}
|
||||
}
|
||||
$data[$key] = $date ?? null;
|
||||
}
|
||||
|
||||
if (array_key_exists('phonenumber', $terms)) {
|
||||
if (\array_key_exists('phonenumber', $terms)) {
|
||||
try {
|
||||
$phonenumber = new PhoneNumber();
|
||||
$phonenumber->setNationalNumber($terms['phonenumber']);
|
||||
} catch (Exception $ex) {
|
||||
throw new ParsingException("The data for phonenumber is "
|
||||
. 'not parsable', 0, $ex);
|
||||
} catch (\Exception $ex) {
|
||||
throw new ParsingException('The data for phonenumber is not parsable', 0, $ex);
|
||||
}
|
||||
|
||||
$data['phonenumber'] = $phonenumber;
|
||||
@@ -194,7 +183,7 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
|
||||
'persons' => $this->search($terms, $start, $limit, $options),
|
||||
'pattern' => $this->recomposePattern(
|
||||
$terms,
|
||||
array_filter(self::POSSIBLE_KEYS, static fn ($item) => '_default' !== $item),
|
||||
\array_filter(self::POSSIBLE_KEYS, static fn ($item) => '_default' !== $item),
|
||||
$terms['_domain']
|
||||
),
|
||||
'total' => $total,
|
||||
@@ -205,9 +194,10 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// format is "json"
|
||||
return [
|
||||
'results' => $this->search($terms, $start, $limit, array_merge($options, ['simplify' => true])),
|
||||
'results' => $this->search($terms, $start, $limit, \array_merge($options, ['simplify' => true])),
|
||||
'pagination' => [
|
||||
'more' => $paginator->hasNextPage(),
|
||||
],
|
||||
@@ -232,32 +222,29 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
|
||||
'nationality' => $countryCode,
|
||||
'phonenumber' => $phonenumber,
|
||||
'city' => $city,
|
||||
] = $terms + array_fill_keys(self::POSSIBLE_KEYS, null);
|
||||
] = $terms + \array_fill_keys(self::POSSIBLE_KEYS, null);
|
||||
|
||||
if (null !== $birthdate) {
|
||||
try {
|
||||
$birthdate = new DateTime($birthdate);
|
||||
} catch (Exception $e) {
|
||||
throw new ParsingException('The date is '
|
||||
. 'not parsable', 0, $e);
|
||||
$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);
|
||||
$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);
|
||||
$birthdateAfter = new \DateTime($birthdateAfter);
|
||||
} catch (\Exception $e) {
|
||||
throw new ParsingException('The date is not parsable', 0, $e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,32 +279,29 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
|
||||
'nationality' => $countryCode,
|
||||
'phonenumber' => $phonenumber,
|
||||
'city' => $city,
|
||||
] = $terms + array_fill_keys(self::POSSIBLE_KEYS, null);
|
||||
] = $terms + \array_fill_keys(self::POSSIBLE_KEYS, null);
|
||||
|
||||
if (null !== $birthdate) {
|
||||
try {
|
||||
$birthdate = new DateTime($birthdate);
|
||||
} catch (Exception $e) {
|
||||
throw new ParsingException('The date is '
|
||||
. 'not parsable', 0, $e);
|
||||
$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);
|
||||
$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);
|
||||
$birthdateAfter = new \DateTime($birthdateAfter);
|
||||
} catch (\Exception $e) {
|
||||
throw new ParsingException('The date is not parsable', 0, $e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,14 +331,14 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
|
||||
$terms['_default'] = $phoneResults->getFilteredSubject();
|
||||
|
||||
if (
|
||||
$datesResults->hasResult() && (!array_key_exists('birthdate', $terms)
|
||||
$datesResults->hasResult() && (!\array_key_exists('birthdate', $terms)
|
||||
|| null !== $terms['birthdate'])
|
||||
) {
|
||||
$terms['birthdate'] = $datesResults->getFound()[0]->format('Y-m-d');
|
||||
}
|
||||
|
||||
if (
|
||||
$phoneResults->hasResult() && (!array_key_exists('phonenumber', $terms)
|
||||
$phoneResults->hasResult() && (!\array_key_exists('phonenumber', $terms)
|
||||
|| null !== $terms['phonenumber'])
|
||||
) {
|
||||
$terms['phonenumber'] = $phoneResults->getFound()[0];
|
||||
|
Reference in New Issue
Block a user