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];
|
||||
|
@@ -20,10 +20,6 @@ use Chill\PersonBundle\Repository\Household\HouseholdRepository;
|
||||
use Chill\PersonBundle\Repository\PersonACLAwareRepositoryInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
use function array_map;
|
||||
use function count;
|
||||
use function in_array;
|
||||
|
||||
class SearchHouseholdApiProvider implements SearchApiInterface
|
||||
{
|
||||
public function __construct(private readonly HouseholdRepository $householdRepository, private readonly PersonACLAwareRepositoryInterface $personACLAwareRepository, private readonly Security $security, private readonly AuthorizationHelperInterface $authorizationHelper, private readonly ExtractDateFromPattern $extractDateFromPattern, private readonly ExtractPhonenumberFromPattern $extractPhonenumberFromPattern) {}
|
||||
@@ -35,7 +31,7 @@ class SearchHouseholdApiProvider implements SearchApiInterface
|
||||
|
||||
public function prepare(array $metadatas): void
|
||||
{
|
||||
$ids = array_map(static fn ($m) => $m['id'], $metadatas);
|
||||
$ids = \array_map(static fn ($m) => $m['id'], $metadatas);
|
||||
|
||||
$this->householdRepository->findBy(['id' => $ids]);
|
||||
}
|
||||
@@ -50,12 +46,12 @@ class SearchHouseholdApiProvider implements SearchApiInterface
|
||||
$filtered,
|
||||
null,
|
||||
null,
|
||||
count($datesResult->getFound()) > 0 ? $datesResult->getFound()[0] : null,
|
||||
\count($datesResult->getFound()) > 0 ? $datesResult->getFound()[0] : null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
count($phoneResult->getFound()) > 0 ? $phoneResult->getFound()[0] : null
|
||||
\count($phoneResult->getFound()) > 0 ? $phoneResult->getFound()[0] : null
|
||||
);
|
||||
|
||||
$previousFrom = $query->getFromClause();
|
||||
@@ -64,7 +60,7 @@ class SearchHouseholdApiProvider implements SearchApiInterface
|
||||
$query
|
||||
->setDistinct(true, 'cpphm.household_id')
|
||||
->setFromClause(
|
||||
$previousFrom . ' '.
|
||||
$previousFrom.' '.
|
||||
'JOIN chill_person_household_members AS cpphm ON cpphm.person_id = person.id',
|
||||
$previousParams
|
||||
)
|
||||
@@ -82,6 +78,6 @@ class SearchHouseholdApiProvider implements SearchApiInterface
|
||||
|
||||
public function supportsTypes(string $pattern, array $types, array $parameters): bool
|
||||
{
|
||||
return in_array('household', $types, true);
|
||||
return \in_array('household', $types, true);
|
||||
}
|
||||
}
|
||||
|
@@ -20,10 +20,6 @@ use Chill\PersonBundle\Repository\PersonACLAwareRepositoryInterface;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
use function array_map;
|
||||
use function count;
|
||||
use function in_array;
|
||||
|
||||
class SearchPersonApiProvider implements SearchApiInterface
|
||||
{
|
||||
public function __construct(private readonly PersonRepository $personRepository, private readonly PersonACLAwareRepositoryInterface $personACLAwareRepository, private readonly Security $security, private readonly AuthorizationHelperInterface $authorizationHelper, private readonly ExtractDateFromPattern $extractDateFromPattern, private readonly ExtractPhonenumberFromPattern $extractPhonenumberFromPattern) {}
|
||||
@@ -35,7 +31,7 @@ class SearchPersonApiProvider implements SearchApiInterface
|
||||
|
||||
public function prepare(array $metadatas): void
|
||||
{
|
||||
$ids = array_map(static fn ($m) => $m['id'], $metadatas);
|
||||
$ids = \array_map(static fn ($m) => $m['id'], $metadatas);
|
||||
|
||||
$this->personRepository->findByIds($ids);
|
||||
}
|
||||
@@ -50,12 +46,12 @@ class SearchPersonApiProvider implements SearchApiInterface
|
||||
$filtered,
|
||||
null,
|
||||
null,
|
||||
count($datesResult->getFound()) > 0 ? $datesResult->getFound()[0] : null,
|
||||
\count($datesResult->getFound()) > 0 ? $datesResult->getFound()[0] : null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
count($phoneResult->getFound()) > 0 ? $phoneResult->getFound()[0] : null
|
||||
\count($phoneResult->getFound()) > 0 ? $phoneResult->getFound()[0] : null
|
||||
)
|
||||
->setSelectKey('person')
|
||||
->setSelectJsonbMetadata("jsonb_build_object('id', person.id)");
|
||||
@@ -68,6 +64,6 @@ class SearchPersonApiProvider implements SearchApiInterface
|
||||
|
||||
public function supportsTypes(string $pattern, array $types, array $parameters): bool
|
||||
{
|
||||
return in_array('person', $types, true);
|
||||
return \in_array('person', $types, true);
|
||||
}
|
||||
}
|
||||
|
@@ -19,8 +19,6 @@ use Chill\PersonBundle\Templating\Entity\PersonRenderInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
|
||||
use function count;
|
||||
|
||||
class SimilarPersonMatcher
|
||||
{
|
||||
final public const SIMILAR_SEARCH_ORDER_BY_ALPHABETICAL = 'alphabetical';
|
||||
@@ -96,13 +94,13 @@ class SimilarPersonMatcher
|
||||
$qb->setParameter('personBirthdate', $person->getBirthdate());
|
||||
}
|
||||
|
||||
if ($person->getId() !== null) {
|
||||
if (null !== $person->getId()) {
|
||||
$qb->andWhere($qb->expr()->neq('p.id', ':personId'));
|
||||
$qb->setParameter('personId', $person->getId());
|
||||
|
||||
$notDuplicatePersons = $this->personNotDuplicateRepository->findNotDuplicatePerson($person);
|
||||
|
||||
if (count($notDuplicatePersons)) {
|
||||
if (\count($notDuplicatePersons)) {
|
||||
$qb->andWhere($qb->expr()->notIn('p.id', ':notDuplicatePersons'));
|
||||
$qb->setParameter('notDuplicatePersons', $notDuplicatePersons);
|
||||
}
|
||||
|
Reference in New Issue
Block a user