apply more cs rules for php-cs

This commit is contained in:
2023-10-17 13:27:03 +02:00
parent 0b0cbed9db
commit bc2041cbdd
1485 changed files with 8169 additions and 9620 deletions

View File

@@ -13,9 +13,6 @@ namespace Chill\MainBundle\Search;
use DateTime;
use function array_key_exists;
use function strpos;
/**
* This class implements abstract search with most common responses.
*
@@ -29,17 +26,17 @@ abstract class AbstractSearch implements SearchInterface
*
* @param type $string
*
* @throws ParsingException if the date is not parseable
* @return \DateTime
*
* @return DateTime
* @throws ParsingException if the date is not parseable
*/
public function parseDate($string)
{
try {
return new DateTime($string);
return new \DateTime($string);
} catch (ParsingException $ex) {
$exception = new ParsingException('The date is '
. 'not parsable', 0, $ex);
.'not parsable', 0, $ex);
throw $exception;
}
@@ -59,18 +56,18 @@ abstract class AbstractSearch implements SearchInterface
$recomposed = '';
if (null !== $domain) {
$recomposed .= '@' . $domain . ' ';
$recomposed .= '@'.$domain.' ';
}
foreach ($supportedTerms as $term) {
if (array_key_exists($term, $terms) && '_default' !== $term) {
$recomposed .= ' ' . $term . ':';
if (\array_key_exists($term, $terms) && '_default' !== $term) {
$recomposed .= ' '.$term.':';
$containsSpace = str_contains((string) $terms[$term], ' ');
if ($containsSpace) {
$recomposed .= '"';
}
$recomposed .= (mb_stristr(' ', (string) $terms[$term]) === false) ? $terms[$term] : '(' . $terms[$term] . ')';
$recomposed .= (false === mb_stristr(' ', (string) $terms[$term])) ? $terms[$term] : '('.$terms[$term].')';
if ($containsSpace) {
$recomposed .= '"';
@@ -79,11 +76,11 @@ abstract class AbstractSearch implements SearchInterface
}
if ('' !== $terms['_default']) {
$recomposed .= ' ' . $terms['_default'];
$recomposed .= ' '.$terms['_default'];
}
//strip first character if empty
if (mb_strcut($recomposed, 0, 1) === ' ') {
// strip first character if empty
if (' ' === mb_strcut($recomposed, 0, 1)) {
$recomposed = mb_strcut($recomposed, 1);
}

View File

@@ -15,9 +15,6 @@ use Chill\MainBundle\Repository\UserRepository;
use Chill\MainBundle\Search\SearchApiInterface;
use Chill\MainBundle\Search\SearchApiQuery;
use function array_map;
use function in_array;
class SearchUserApiProvider implements SearchApiInterface
{
public function __construct(private readonly UserRepository $userRepository) {}
@@ -29,7 +26,7 @@ class SearchUserApiProvider 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->userRepository->findBy(['id' => $ids]);
}
@@ -61,6 +58,6 @@ class SearchUserApiProvider implements SearchApiInterface
public function supportsTypes(string $pattern, array $types, array $parameters): bool
{
return in_array('user', $types, true);
return \in_array('user', $types, true);
}
}

View File

@@ -13,9 +13,6 @@ namespace Chill\MainBundle\Search\Model;
class Result
{
/**
* @param $result
*/
public function __construct(
private readonly float $relevance,
/**

View File

@@ -11,6 +11,4 @@ declare(strict_types=1);
namespace Chill\MainBundle\Search;
use Exception;
class ParsingException extends Exception {}
class ParsingException extends \Exception {}

View File

@@ -18,12 +18,6 @@ use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query\ResultSetMappingBuilder;
use function array_map;
use function array_merge;
use function count;
use function implode;
use function strtr;
class SearchApi
{
public function __construct(private readonly EntityManagerInterface $em, private readonly iterable $providers, private readonly PaginatorFactory $paginator) {}
@@ -32,7 +26,7 @@ class SearchApi
{
$queries = $this->findQueries($pattern, $types, $parameters);
if (0 === count($queries)) {
if (0 === \count($queries)) {
throw new SearchApiNoQueryException($pattern, $types, $parameters);
}
@@ -55,13 +49,13 @@ class SearchApi
foreach ($queries as $q) {
$unions[] = $q->buildQuery(true);
$parameters = array_merge($parameters, $q->buildParameters(true));
$parameters = \array_merge($parameters, $q->buildParameters(true));
}
$unionUnordered = implode(' UNION ', $unions);
$unionUnordered = \implode(' UNION ', $unions);
return [
strtr($query, ['{union_unordered}' => $unionUnordered]),
\strtr($query, ['{union_unordered}' => $unionUnordered]),
$parameters,
];
}
@@ -94,17 +88,17 @@ class SearchApi
foreach ($queries as $q) {
$unions[] = $q->buildQuery();
$parameters = array_merge($parameters, $q->buildParameters());
$parameters = \array_merge($parameters, $q->buildParameters());
}
// add pagination limit
$parameters[] = $paginator->getItemsPerPage();
$parameters[] = $paginator->getCurrentPageFirstItemNumber();
$union = implode(' UNION ', $unions);
$union = \implode(' UNION ', $unions);
return [
strtr($query, ['{unions}' => $union]),
\strtr($query, ['{unions}' => $union]),
$parameters,
];
}
@@ -149,7 +143,7 @@ class SearchApi
private function findQueries($pattern, array $types, array $parameters): array
{
return array_map(
return \array_map(
static fn ($p) => $p->provideQuery($pattern, $parameters),
$this->findProviders($pattern, $types, $parameters),
);

View File

@@ -11,20 +11,15 @@ declare(strict_types=1);
namespace Chill\MainBundle\Search;
use RuntimeException;
use Throwable;
use function implode;
class SearchApiNoQueryException extends RuntimeException
class SearchApiNoQueryException extends \RuntimeException
{
private readonly string $pattern;
private readonly array $types;
public function __construct(string $pattern = '', array $types = [], private readonly array $parameters = [], $code = 0, ?Throwable $previous = null)
public function __construct(string $pattern = '', array $types = [], private readonly array $parameters = [], $code = 0, \Throwable $previous = null)
{
$typesStr = implode(', ', $types);
$typesStr = \implode(', ', $types);
$message = "No query for this search: pattern : {$pattern}, types: {$typesStr}";
$this->pattern = $pattern;
$this->types = $types;

View File

@@ -11,11 +11,6 @@ declare(strict_types=1);
namespace Chill\MainBundle\Search;
use function array_push;
use function count;
use function implode;
use function strtr;
/**
* This create a query optimized for searching for the api response.
*
@@ -24,9 +19,9 @@ use function strtr;
*
* `SELECT '<key>' as key, <metadata> as metadata, <pertinence> as pertinence FROM <from clause> WHERE <where clause>`.
*
* The clause between `<>` are provided through the dedicated method in this class (@link{self::setSelectKey},
* @link{self::setFromClause}), etc.).
* The clause between `<>` are provided through the dedicated method in this class (@see{self::setSelectKey},
*
* @see{self::setFromClause}), etc.).
*/
class SearchApiQuery
{
@@ -76,7 +71,7 @@ class SearchApiQuery
public function andWhereClause(string $whereClause, array $params = []): self
{
$this->whereClauses[] = $whereClause;
array_push($this->whereClausesParams, ...$params);
\array_push($this->whereClausesParams, ...$params);
return $this;
}
@@ -99,18 +94,18 @@ class SearchApiQuery
public function buildQuery(bool $countOnly = false): string
{
$isMultiple = count($this->whereClauses);
$isMultiple = \count($this->whereClauses);
$where =
($isMultiple ? '(' : '') .
implode(
($isMultiple ? ')' : '') . ' AND ' . ($isMultiple ? '(' : ''),
($isMultiple ? '(' : '').
\implode(
($isMultiple ? ')' : '').' AND '.($isMultiple ? '(' : ''),
$this->whereClauses
) .
).
($isMultiple ? ')' : '');
$select = $this->buildSelectClause($countOnly);
return strtr('SELECT
return \strtr('SELECT
{select}
FROM {from}
WHERE {where}
@@ -218,24 +213,24 @@ class SearchApiQuery
return 'count(*) AS c';
}
return 'count(distinct ' . $this->isDistinctKey . ') AS c';
return 'count(distinct '.$this->isDistinctKey.') AS c';
}
$selects = $this->getSelectClauses();
if (null !== $this->selectKey) {
$selects[] = strtr("'{key}' AS key", ['{key}' => $this->selectKey]);
$selects[] = \strtr("'{key}' AS key", ['{key}' => $this->selectKey]);
}
if (null !== $this->jsonbMetadata) {
$selects[] = strtr('{metadata} AS metadata', ['{metadata}' => $this->jsonbMetadata]);
$selects[] = \strtr('{metadata} AS metadata', ['{metadata}' => $this->jsonbMetadata]);
}
if (null !== $this->pertinence) {
$selects[] = strtr('{pertinence} AS pertinence', ['{pertinence}' => $this->pertinence]);
$selects[] = \strtr('{pertinence} AS pertinence', ['{pertinence}' => $this->pertinence]);
}
return ($this->isDistinct ? 'DISTINCT ' : '') . implode(', ', $selects);
return ($this->isDistinct ? 'DISTINCT ' : '').\implode(', ', $selects);
}
private function buildSelectParams(bool $count = false): array

View File

@@ -68,10 +68,10 @@ interface SearchInterface
* take only the given parameters into account; the results from pagination
* should be ignored. (Most of the time, it should be the same).
*
* @param array $terms the string to search
* @param int $start the first result (for pagination)
* @param int $limit the number of result (for pagination)
* @param "html"|"json" $format The format for result
* @param array $terms the string to search
* @param int $start the first result (for pagination)
* @param int $limit the number of result (for pagination)
* @param "html"|"json" $format The format for result
*
* @return string|array a string if format is html, an array if format is json
*/
@@ -80,9 +80,6 @@ interface SearchInterface
/**
* indicate if the implementation supports the given domain.
*
* @param mixed $domain
* @param mixed $format
*
* @return bool
*/
public function supports($domain, $format);

View File

@@ -11,9 +11,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\Search;
use function array_key_exists;
use function chr;
use function count;
/**
* a service which gather all search services defined into the bundles
@@ -62,9 +60,9 @@ class SearchProvider
* return search services with a specific name, defined in service
* definition.
*
* @return SearchInterface
*
* @throws UnknowSearchNameException if not exists
* @return SearchInterface
*/
public function getByName(mixed $name)
{
@@ -87,7 +85,7 @@ class SearchProvider
*/
public function getByOrder()
{
//sort the array
// sort the array
uasort($this->searchServices, static fn (SearchInterface $a, SearchInterface $b) => $a->getOrder() <=> $b->getOrder());
return $this->searchServices;
@@ -101,7 +99,7 @@ class SearchProvider
*/
public function getHasAdvancedFormByName(string $name): HasAdvancedSearchFormInterface
{
if (array_key_exists($name, $this->hasAdvancedFormSearchServices)) {
if (\array_key_exists($name, $this->hasAdvancedFormSearchServices)) {
return $this->hasAdvancedFormSearchServices[$name];
}
@@ -110,7 +108,7 @@ class SearchProvider
public function getHasAdvancedFormSearchServices()
{
//sort the array
// sort the array
uasort($this->hasAdvancedFormSearchServices, static fn (HasAdvancedSearchFormInterface $a, HasAdvancedSearchFormInterface $b): int => $a->getOrder() <=> $b->getOrder());
return $this->hasAdvancedFormSearchServices;
@@ -143,9 +141,9 @@ class SearchProvider
* @param number $limit
* @param string $format
*
* @throws UnknowSearchDomainException if the domain is unknow
*
* @return array of results from different SearchInterface
*
* @throws UnknowSearchDomainException if the domain is unknow
*/
public function getSearchResults(
$pattern,
@@ -157,7 +155,7 @@ class SearchProvider
$terms = $this->parse($pattern);
$results = [];
//sort searchServices by order
// sort searchServices by order
$sortedSearchServices = [];
foreach ($this->searchServices as $service) {
@@ -171,7 +169,7 @@ class SearchProvider
}
}
if (count($results) === 0) {
if (0 === \count($results)) {
throw new UnknowSearchDomainException($terms['_domain']);
}
} else { // no domain provided, we use default search
@@ -182,7 +180,7 @@ class SearchProvider
}
}
//sort array
// sort array
ksort($results);
return $results;
@@ -197,9 +195,9 @@ class SearchProvider
*/
public function parse($pattern)
{
//reset must be extracted
// reset must be extracted
$this->mustBeExtracted = [];
//filter to lower and remove accentued
// filter to lower and remove accentued
$filteredPattern = mb_strtolower($this->remove_accents($pattern));
$terms = $this->extractTerms($filteredPattern);
@@ -228,19 +226,19 @@ class SearchProvider
*
* @param type $subject
*
* @throws ParsingException
*
* @return string
*
* @throws ParsingException
*/
private function extractDomain(&$subject)
{
preg_match_all('/@([a-z]+)/', $subject, $terms);
if (count($terms[0]) > 1) {
if (\count($terms[0]) > 1) {
throw new ParsingException('You should not have more than one domain.');
}
//add pattern to be extracted
// add pattern to be extracted
if (isset($terms[0][0])) {
$this->mustBeExtracted[] = $terms[0][0];
}
@@ -255,12 +253,12 @@ class SearchProvider
preg_match_all('/([a-z\-]+):(([^"][\S\-]+)|"[^"]*")/', (string) $subject, $matches);
foreach ($matches[2] as $key => $match) {
//remove from search pattern
// remove from search pattern
$this->mustBeExtracted[] = $matches[0][$key];
//strip parenthesis
// strip parenthesis
if (
mb_substr((string) $match, 0, 1) === '"'
&& mb_substr((string) $match, mb_strlen((string) $match) - 1) === '"'
'"' === mb_substr((string) $match, 0, 1)
&& '"' === mb_substr((string) $match, mb_strlen((string) $match) - 1)
) {
$match = trim(mb_substr((string) $match, 1, mb_strlen((string) $match) - 2));
}
@@ -279,7 +277,7 @@ class SearchProvider
*
* @param string $string Text that might have accent characters
*
* @return string Filtered string with replaced "nice" characters.
* @return string filtered string with replaced "nice" characters
*
* @license GNU GPLv2 : https://core.trac.wordpress.org/browser/tags/4.1/src/license.txt
*/
@@ -289,182 +287,182 @@ class SearchProvider
return $string;
}
//if ($this->seems_utf8($string)) { // remove from wordpress: we use only UTF-8
// if ($this->seems_utf8($string)) { // remove from wordpress: we use only UTF-8
if (true) {
$chars = [
// Decompositions for Latin-1 Supplement
chr(194) . chr(170) => 'a', chr(194) . chr(186) => 'o',
chr(195) . chr(128) => 'A', chr(195) . chr(129) => 'A',
chr(195) . chr(130) => 'A', chr(195) . chr(131) => 'A',
chr(195) . chr(132) => 'A', chr(195) . chr(133) => 'A',
chr(195) . chr(134) => 'AE', chr(195) . chr(135) => 'C',
chr(195) . chr(136) => 'E', chr(195) . chr(137) => 'E',
chr(195) . chr(138) => 'E', chr(195) . chr(139) => 'E',
chr(195) . chr(140) => 'I', chr(195) . chr(141) => 'I',
chr(195) . chr(142) => 'I', chr(195) . chr(143) => 'I',
chr(195) . chr(144) => 'D', chr(195) . chr(145) => 'N',
chr(195) . chr(146) => 'O', chr(195) . chr(147) => 'O',
chr(195) . chr(148) => 'O', chr(195) . chr(149) => 'O',
chr(195) . chr(150) => 'O', chr(195) . chr(153) => 'U',
chr(195) . chr(154) => 'U', chr(195) . chr(155) => 'U',
chr(195) . chr(156) => 'U', chr(195) . chr(157) => 'Y',
chr(195) . chr(158) => 'TH', chr(195) . chr(159) => 's',
chr(195) . chr(160) => 'a', chr(195) . chr(161) => 'a',
chr(195) . chr(162) => 'a', chr(195) . chr(163) => 'a',
chr(195) . chr(164) => 'a', chr(195) . chr(165) => 'a',
chr(195) . chr(166) => 'ae', chr(195) . chr(167) => 'c',
chr(195) . chr(168) => 'e', chr(195) . chr(169) => 'e',
chr(195) . chr(170) => 'e', chr(195) . chr(171) => 'e',
chr(195) . chr(172) => 'i', chr(195) . chr(173) => 'i',
chr(195) . chr(174) => 'i', chr(195) . chr(175) => 'i',
chr(195) . chr(176) => 'd', chr(195) . chr(177) => 'n',
chr(195) . chr(178) => 'o', chr(195) . chr(179) => 'o',
chr(195) . chr(180) => 'o', chr(195) . chr(181) => 'o',
chr(195) . chr(182) => 'o', chr(195) . chr(184) => 'o',
chr(195) . chr(185) => 'u', chr(195) . chr(186) => 'u',
chr(195) . chr(187) => 'u', chr(195) . chr(188) => 'u',
chr(195) . chr(189) => 'y', chr(195) . chr(190) => 'th',
chr(195) . chr(191) => 'y', chr(195) . chr(152) => 'O',
\chr(194).\chr(170) => 'a', \chr(194).\chr(186) => 'o',
\chr(195).\chr(128) => 'A', \chr(195).\chr(129) => 'A',
\chr(195).\chr(130) => 'A', \chr(195).\chr(131) => 'A',
\chr(195).\chr(132) => 'A', \chr(195).\chr(133) => 'A',
\chr(195).\chr(134) => 'AE', \chr(195).\chr(135) => 'C',
\chr(195).\chr(136) => 'E', \chr(195).\chr(137) => 'E',
\chr(195).\chr(138) => 'E', \chr(195).\chr(139) => 'E',
\chr(195).\chr(140) => 'I', \chr(195).\chr(141) => 'I',
\chr(195).\chr(142) => 'I', \chr(195).\chr(143) => 'I',
\chr(195).\chr(144) => 'D', \chr(195).\chr(145) => 'N',
\chr(195).\chr(146) => 'O', \chr(195).\chr(147) => 'O',
\chr(195).\chr(148) => 'O', \chr(195).\chr(149) => 'O',
\chr(195).\chr(150) => 'O', \chr(195).\chr(153) => 'U',
\chr(195).\chr(154) => 'U', \chr(195).\chr(155) => 'U',
\chr(195).\chr(156) => 'U', \chr(195).\chr(157) => 'Y',
\chr(195).\chr(158) => 'TH', \chr(195).\chr(159) => 's',
\chr(195).\chr(160) => 'a', \chr(195).\chr(161) => 'a',
\chr(195).\chr(162) => 'a', \chr(195).\chr(163) => 'a',
\chr(195).\chr(164) => 'a', \chr(195).\chr(165) => 'a',
\chr(195).\chr(166) => 'ae', \chr(195).\chr(167) => 'c',
\chr(195).\chr(168) => 'e', \chr(195).\chr(169) => 'e',
\chr(195).\chr(170) => 'e', \chr(195).\chr(171) => 'e',
\chr(195).\chr(172) => 'i', \chr(195).\chr(173) => 'i',
\chr(195).\chr(174) => 'i', \chr(195).\chr(175) => 'i',
\chr(195).\chr(176) => 'd', \chr(195).\chr(177) => 'n',
\chr(195).\chr(178) => 'o', \chr(195).\chr(179) => 'o',
\chr(195).\chr(180) => 'o', \chr(195).\chr(181) => 'o',
\chr(195).\chr(182) => 'o', \chr(195).\chr(184) => 'o',
\chr(195).\chr(185) => 'u', \chr(195).\chr(186) => 'u',
\chr(195).\chr(187) => 'u', \chr(195).\chr(188) => 'u',
\chr(195).\chr(189) => 'y', \chr(195).\chr(190) => 'th',
\chr(195).\chr(191) => 'y', \chr(195).\chr(152) => 'O',
// Decompositions for Latin Extended-A
chr(196) . chr(128) => 'A', chr(196) . chr(129) => 'a',
chr(196) . chr(130) => 'A', chr(196) . chr(131) => 'a',
chr(196) . chr(132) => 'A', chr(196) . chr(133) => 'a',
chr(196) . chr(134) => 'C', chr(196) . chr(135) => 'c',
chr(196) . chr(136) => 'C', chr(196) . chr(137) => 'c',
chr(196) . chr(138) => 'C', chr(196) . chr(139) => 'c',
chr(196) . chr(140) => 'C', chr(196) . chr(141) => 'c',
chr(196) . chr(142) => 'D', chr(196) . chr(143) => 'd',
chr(196) . chr(144) => 'D', chr(196) . chr(145) => 'd',
chr(196) . chr(146) => 'E', chr(196) . chr(147) => 'e',
chr(196) . chr(148) => 'E', chr(196) . chr(149) => 'e',
chr(196) . chr(150) => 'E', chr(196) . chr(151) => 'e',
chr(196) . chr(152) => 'E', chr(196) . chr(153) => 'e',
chr(196) . chr(154) => 'E', chr(196) . chr(155) => 'e',
chr(196) . chr(156) => 'G', chr(196) . chr(157) => 'g',
chr(196) . chr(158) => 'G', chr(196) . chr(159) => 'g',
chr(196) . chr(160) => 'G', chr(196) . chr(161) => 'g',
chr(196) . chr(162) => 'G', chr(196) . chr(163) => 'g',
chr(196) . chr(164) => 'H', chr(196) . chr(165) => 'h',
chr(196) . chr(166) => 'H', chr(196) . chr(167) => 'h',
chr(196) . chr(168) => 'I', chr(196) . chr(169) => 'i',
chr(196) . chr(170) => 'I', chr(196) . chr(171) => 'i',
chr(196) . chr(172) => 'I', chr(196) . chr(173) => 'i',
chr(196) . chr(174) => 'I', chr(196) . chr(175) => 'i',
chr(196) . chr(176) => 'I', chr(196) . chr(177) => 'i',
chr(196) . chr(178) => 'IJ', chr(196) . chr(179) => 'ij',
chr(196) . chr(180) => 'J', chr(196) . chr(181) => 'j',
chr(196) . chr(182) => 'K', chr(196) . chr(183) => 'k',
chr(196) . chr(184) => 'k', chr(196) . chr(185) => 'L',
chr(196) . chr(186) => 'l', chr(196) . chr(187) => 'L',
chr(196) . chr(188) => 'l', chr(196) . chr(189) => 'L',
chr(196) . chr(190) => 'l', chr(196) . chr(191) => 'L',
chr(197) . chr(128) => 'l', chr(197) . chr(129) => 'L',
chr(197) . chr(130) => 'l', chr(197) . chr(131) => 'N',
chr(197) . chr(132) => 'n', chr(197) . chr(133) => 'N',
chr(197) . chr(134) => 'n', chr(197) . chr(135) => 'N',
chr(197) . chr(136) => 'n', chr(197) . chr(137) => 'N',
chr(197) . chr(138) => 'n', chr(197) . chr(139) => 'N',
chr(197) . chr(140) => 'O', chr(197) . chr(141) => 'o',
chr(197) . chr(142) => 'O', chr(197) . chr(143) => 'o',
chr(197) . chr(144) => 'O', chr(197) . chr(145) => 'o',
chr(197) . chr(146) => 'OE', chr(197) . chr(147) => 'oe',
chr(197) . chr(148) => 'R', chr(197) . chr(149) => 'r',
chr(197) . chr(150) => 'R', chr(197) . chr(151) => 'r',
chr(197) . chr(152) => 'R', chr(197) . chr(153) => 'r',
chr(197) . chr(154) => 'S', chr(197) . chr(155) => 's',
chr(197) . chr(156) => 'S', chr(197) . chr(157) => 's',
chr(197) . chr(158) => 'S', chr(197) . chr(159) => 's',
chr(197) . chr(160) => 'S', chr(197) . chr(161) => 's',
chr(197) . chr(162) => 'T', chr(197) . chr(163) => 't',
chr(197) . chr(164) => 'T', chr(197) . chr(165) => 't',
chr(197) . chr(166) => 'T', chr(197) . chr(167) => 't',
chr(197) . chr(168) => 'U', chr(197) . chr(169) => 'u',
chr(197) . chr(170) => 'U', chr(197) . chr(171) => 'u',
chr(197) . chr(172) => 'U', chr(197) . chr(173) => 'u',
chr(197) . chr(174) => 'U', chr(197) . chr(175) => 'u',
chr(197) . chr(176) => 'U', chr(197) . chr(177) => 'u',
chr(197) . chr(178) => 'U', chr(197) . chr(179) => 'u',
chr(197) . chr(180) => 'W', chr(197) . chr(181) => 'w',
chr(197) . chr(182) => 'Y', chr(197) . chr(183) => 'y',
chr(197) . chr(184) => 'Y', chr(197) . chr(185) => 'Z',
chr(197) . chr(186) => 'z', chr(197) . chr(187) => 'Z',
chr(197) . chr(188) => 'z', chr(197) . chr(189) => 'Z',
chr(197) . chr(190) => 'z', chr(197) . chr(191) => 's',
\chr(196).\chr(128) => 'A', \chr(196).\chr(129) => 'a',
\chr(196).\chr(130) => 'A', \chr(196).\chr(131) => 'a',
\chr(196).\chr(132) => 'A', \chr(196).\chr(133) => 'a',
\chr(196).\chr(134) => 'C', \chr(196).\chr(135) => 'c',
\chr(196).\chr(136) => 'C', \chr(196).\chr(137) => 'c',
\chr(196).\chr(138) => 'C', \chr(196).\chr(139) => 'c',
\chr(196).\chr(140) => 'C', \chr(196).\chr(141) => 'c',
\chr(196).\chr(142) => 'D', \chr(196).\chr(143) => 'd',
\chr(196).\chr(144) => 'D', \chr(196).\chr(145) => 'd',
\chr(196).\chr(146) => 'E', \chr(196).\chr(147) => 'e',
\chr(196).\chr(148) => 'E', \chr(196).\chr(149) => 'e',
\chr(196).\chr(150) => 'E', \chr(196).\chr(151) => 'e',
\chr(196).\chr(152) => 'E', \chr(196).\chr(153) => 'e',
\chr(196).\chr(154) => 'E', \chr(196).\chr(155) => 'e',
\chr(196).\chr(156) => 'G', \chr(196).\chr(157) => 'g',
\chr(196).\chr(158) => 'G', \chr(196).\chr(159) => 'g',
\chr(196).\chr(160) => 'G', \chr(196).\chr(161) => 'g',
\chr(196).\chr(162) => 'G', \chr(196).\chr(163) => 'g',
\chr(196).\chr(164) => 'H', \chr(196).\chr(165) => 'h',
\chr(196).\chr(166) => 'H', \chr(196).\chr(167) => 'h',
\chr(196).\chr(168) => 'I', \chr(196).\chr(169) => 'i',
\chr(196).\chr(170) => 'I', \chr(196).\chr(171) => 'i',
\chr(196).\chr(172) => 'I', \chr(196).\chr(173) => 'i',
\chr(196).\chr(174) => 'I', \chr(196).\chr(175) => 'i',
\chr(196).\chr(176) => 'I', \chr(196).\chr(177) => 'i',
\chr(196).\chr(178) => 'IJ', \chr(196).\chr(179) => 'ij',
\chr(196).\chr(180) => 'J', \chr(196).\chr(181) => 'j',
\chr(196).\chr(182) => 'K', \chr(196).\chr(183) => 'k',
\chr(196).\chr(184) => 'k', \chr(196).\chr(185) => 'L',
\chr(196).\chr(186) => 'l', \chr(196).\chr(187) => 'L',
\chr(196).\chr(188) => 'l', \chr(196).\chr(189) => 'L',
\chr(196).\chr(190) => 'l', \chr(196).\chr(191) => 'L',
\chr(197).\chr(128) => 'l', \chr(197).\chr(129) => 'L',
\chr(197).\chr(130) => 'l', \chr(197).\chr(131) => 'N',
\chr(197).\chr(132) => 'n', \chr(197).\chr(133) => 'N',
\chr(197).\chr(134) => 'n', \chr(197).\chr(135) => 'N',
\chr(197).\chr(136) => 'n', \chr(197).\chr(137) => 'N',
\chr(197).\chr(138) => 'n', \chr(197).\chr(139) => 'N',
\chr(197).\chr(140) => 'O', \chr(197).\chr(141) => 'o',
\chr(197).\chr(142) => 'O', \chr(197).\chr(143) => 'o',
\chr(197).\chr(144) => 'O', \chr(197).\chr(145) => 'o',
\chr(197).\chr(146) => 'OE', \chr(197).\chr(147) => 'oe',
\chr(197).\chr(148) => 'R', \chr(197).\chr(149) => 'r',
\chr(197).\chr(150) => 'R', \chr(197).\chr(151) => 'r',
\chr(197).\chr(152) => 'R', \chr(197).\chr(153) => 'r',
\chr(197).\chr(154) => 'S', \chr(197).\chr(155) => 's',
\chr(197).\chr(156) => 'S', \chr(197).\chr(157) => 's',
\chr(197).\chr(158) => 'S', \chr(197).\chr(159) => 's',
\chr(197).\chr(160) => 'S', \chr(197).\chr(161) => 's',
\chr(197).\chr(162) => 'T', \chr(197).\chr(163) => 't',
\chr(197).\chr(164) => 'T', \chr(197).\chr(165) => 't',
\chr(197).\chr(166) => 'T', \chr(197).\chr(167) => 't',
\chr(197).\chr(168) => 'U', \chr(197).\chr(169) => 'u',
\chr(197).\chr(170) => 'U', \chr(197).\chr(171) => 'u',
\chr(197).\chr(172) => 'U', \chr(197).\chr(173) => 'u',
\chr(197).\chr(174) => 'U', \chr(197).\chr(175) => 'u',
\chr(197).\chr(176) => 'U', \chr(197).\chr(177) => 'u',
\chr(197).\chr(178) => 'U', \chr(197).\chr(179) => 'u',
\chr(197).\chr(180) => 'W', \chr(197).\chr(181) => 'w',
\chr(197).\chr(182) => 'Y', \chr(197).\chr(183) => 'y',
\chr(197).\chr(184) => 'Y', \chr(197).\chr(185) => 'Z',
\chr(197).\chr(186) => 'z', \chr(197).\chr(187) => 'Z',
\chr(197).\chr(188) => 'z', \chr(197).\chr(189) => 'Z',
\chr(197).\chr(190) => 'z', \chr(197).\chr(191) => 's',
// Decompositions for Latin Extended-B
chr(200) . chr(152) => 'S', chr(200) . chr(153) => 's',
chr(200) . chr(154) => 'T', chr(200) . chr(155) => 't',
\chr(200).\chr(152) => 'S', \chr(200).\chr(153) => 's',
\chr(200).\chr(154) => 'T', \chr(200).\chr(155) => 't',
// Euro Sign
chr(226) . chr(130) . chr(172) => 'E',
\chr(226).\chr(130).\chr(172) => 'E',
// GBP (Pound) Sign
chr(194) . chr(163) => '',
\chr(194).\chr(163) => '',
// Vowels with diacritic (Vietnamese)
// unmarked
chr(198) . chr(160) => 'O', chr(198) . chr(161) => 'o',
chr(198) . chr(175) => 'U', chr(198) . chr(176) => 'u',
\chr(198).\chr(160) => 'O', \chr(198).\chr(161) => 'o',
\chr(198).\chr(175) => 'U', \chr(198).\chr(176) => 'u',
// grave accent
chr(225) . chr(186) . chr(166) => 'A', chr(225) . chr(186) . chr(167) => 'a',
chr(225) . chr(186) . chr(176) => 'A', chr(225) . chr(186) . chr(177) => 'a',
chr(225) . chr(187) . chr(128) => 'E', chr(225) . chr(187) . chr(129) => 'e',
chr(225) . chr(187) . chr(146) => 'O', chr(225) . chr(187) . chr(147) => 'o',
chr(225) . chr(187) . chr(156) => 'O', chr(225) . chr(187) . chr(157) => 'o',
chr(225) . chr(187) . chr(170) => 'U', chr(225) . chr(187) . chr(171) => 'u',
chr(225) . chr(187) . chr(178) => 'Y', chr(225) . chr(187) . chr(179) => 'y',
\chr(225).\chr(186).\chr(166) => 'A', \chr(225).\chr(186).\chr(167) => 'a',
\chr(225).\chr(186).\chr(176) => 'A', \chr(225).\chr(186).\chr(177) => 'a',
\chr(225).\chr(187).\chr(128) => 'E', \chr(225).\chr(187).\chr(129) => 'e',
\chr(225).\chr(187).\chr(146) => 'O', \chr(225).\chr(187).\chr(147) => 'o',
\chr(225).\chr(187).\chr(156) => 'O', \chr(225).\chr(187).\chr(157) => 'o',
\chr(225).\chr(187).\chr(170) => 'U', \chr(225).\chr(187).\chr(171) => 'u',
\chr(225).\chr(187).\chr(178) => 'Y', \chr(225).\chr(187).\chr(179) => 'y',
// hook
chr(225) . chr(186) . chr(162) => 'A', chr(225) . chr(186) . chr(163) => 'a',
chr(225) . chr(186) . chr(168) => 'A', chr(225) . chr(186) . chr(169) => 'a',
chr(225) . chr(186) . chr(178) => 'A', chr(225) . chr(186) . chr(179) => 'a',
chr(225) . chr(186) . chr(186) => 'E', chr(225) . chr(186) . chr(187) => 'e',
chr(225) . chr(187) . chr(130) => 'E', chr(225) . chr(187) . chr(131) => 'e',
chr(225) . chr(187) . chr(136) => 'I', chr(225) . chr(187) . chr(137) => 'i',
chr(225) . chr(187) . chr(142) => 'O', chr(225) . chr(187) . chr(143) => 'o',
chr(225) . chr(187) . chr(148) => 'O', chr(225) . chr(187) . chr(149) => 'o',
chr(225) . chr(187) . chr(158) => 'O', chr(225) . chr(187) . chr(159) => 'o',
chr(225) . chr(187) . chr(166) => 'U', chr(225) . chr(187) . chr(167) => 'u',
chr(225) . chr(187) . chr(172) => 'U', chr(225) . chr(187) . chr(173) => 'u',
chr(225) . chr(187) . chr(182) => 'Y', chr(225) . chr(187) . chr(183) => 'y',
\chr(225).\chr(186).\chr(162) => 'A', \chr(225).\chr(186).\chr(163) => 'a',
\chr(225).\chr(186).\chr(168) => 'A', \chr(225).\chr(186).\chr(169) => 'a',
\chr(225).\chr(186).\chr(178) => 'A', \chr(225).\chr(186).\chr(179) => 'a',
\chr(225).\chr(186).\chr(186) => 'E', \chr(225).\chr(186).\chr(187) => 'e',
\chr(225).\chr(187).\chr(130) => 'E', \chr(225).\chr(187).\chr(131) => 'e',
\chr(225).\chr(187).\chr(136) => 'I', \chr(225).\chr(187).\chr(137) => 'i',
\chr(225).\chr(187).\chr(142) => 'O', \chr(225).\chr(187).\chr(143) => 'o',
\chr(225).\chr(187).\chr(148) => 'O', \chr(225).\chr(187).\chr(149) => 'o',
\chr(225).\chr(187).\chr(158) => 'O', \chr(225).\chr(187).\chr(159) => 'o',
\chr(225).\chr(187).\chr(166) => 'U', \chr(225).\chr(187).\chr(167) => 'u',
\chr(225).\chr(187).\chr(172) => 'U', \chr(225).\chr(187).\chr(173) => 'u',
\chr(225).\chr(187).\chr(182) => 'Y', \chr(225).\chr(187).\chr(183) => 'y',
// tilde
chr(225) . chr(186) . chr(170) => 'A', chr(225) . chr(186) . chr(171) => 'a',
chr(225) . chr(186) . chr(180) => 'A', chr(225) . chr(186) . chr(181) => 'a',
chr(225) . chr(186) . chr(188) => 'E', chr(225) . chr(186) . chr(189) => 'e',
chr(225) . chr(187) . chr(132) => 'E', chr(225) . chr(187) . chr(133) => 'e',
chr(225) . chr(187) . chr(150) => 'O', chr(225) . chr(187) . chr(151) => 'o',
chr(225) . chr(187) . chr(160) => 'O', chr(225) . chr(187) . chr(161) => 'o',
chr(225) . chr(187) . chr(174) => 'U', chr(225) . chr(187) . chr(175) => 'u',
chr(225) . chr(187) . chr(184) => 'Y', chr(225) . chr(187) . chr(185) => 'y',
\chr(225).\chr(186).\chr(170) => 'A', \chr(225).\chr(186).\chr(171) => 'a',
\chr(225).\chr(186).\chr(180) => 'A', \chr(225).\chr(186).\chr(181) => 'a',
\chr(225).\chr(186).\chr(188) => 'E', \chr(225).\chr(186).\chr(189) => 'e',
\chr(225).\chr(187).\chr(132) => 'E', \chr(225).\chr(187).\chr(133) => 'e',
\chr(225).\chr(187).\chr(150) => 'O', \chr(225).\chr(187).\chr(151) => 'o',
\chr(225).\chr(187).\chr(160) => 'O', \chr(225).\chr(187).\chr(161) => 'o',
\chr(225).\chr(187).\chr(174) => 'U', \chr(225).\chr(187).\chr(175) => 'u',
\chr(225).\chr(187).\chr(184) => 'Y', \chr(225).\chr(187).\chr(185) => 'y',
// acute accent
chr(225) . chr(186) . chr(164) => 'A', chr(225) . chr(186) . chr(165) => 'a',
chr(225) . chr(186) . chr(174) => 'A', chr(225) . chr(186) . chr(175) => 'a',
chr(225) . chr(186) . chr(190) => 'E', chr(225) . chr(186) . chr(191) => 'e',
chr(225) . chr(187) . chr(144) => 'O', chr(225) . chr(187) . chr(145) => 'o',
chr(225) . chr(187) . chr(154) => 'O', chr(225) . chr(187) . chr(155) => 'o',
chr(225) . chr(187) . chr(168) => 'U', chr(225) . chr(187) . chr(169) => 'u',
\chr(225).\chr(186).\chr(164) => 'A', \chr(225).\chr(186).\chr(165) => 'a',
\chr(225).\chr(186).\chr(174) => 'A', \chr(225).\chr(186).\chr(175) => 'a',
\chr(225).\chr(186).\chr(190) => 'E', \chr(225).\chr(186).\chr(191) => 'e',
\chr(225).\chr(187).\chr(144) => 'O', \chr(225).\chr(187).\chr(145) => 'o',
\chr(225).\chr(187).\chr(154) => 'O', \chr(225).\chr(187).\chr(155) => 'o',
\chr(225).\chr(187).\chr(168) => 'U', \chr(225).\chr(187).\chr(169) => 'u',
// dot below
chr(225) . chr(186) . chr(160) => 'A', chr(225) . chr(186) . chr(161) => 'a',
chr(225) . chr(186) . chr(172) => 'A', chr(225) . chr(186) . chr(173) => 'a',
chr(225) . chr(186) . chr(182) => 'A', chr(225) . chr(186) . chr(183) => 'a',
chr(225) . chr(186) . chr(184) => 'E', chr(225) . chr(186) . chr(185) => 'e',
chr(225) . chr(187) . chr(134) => 'E', chr(225) . chr(187) . chr(135) => 'e',
chr(225) . chr(187) . chr(138) => 'I', chr(225) . chr(187) . chr(139) => 'i',
chr(225) . chr(187) . chr(140) => 'O', chr(225) . chr(187) . chr(141) => 'o',
chr(225) . chr(187) . chr(152) => 'O', chr(225) . chr(187) . chr(153) => 'o',
chr(225) . chr(187) . chr(162) => 'O', chr(225) . chr(187) . chr(163) => 'o',
chr(225) . chr(187) . chr(164) => 'U', chr(225) . chr(187) . chr(165) => 'u',
chr(225) . chr(187) . chr(176) => 'U', chr(225) . chr(187) . chr(177) => 'u',
chr(225) . chr(187) . chr(180) => 'Y', chr(225) . chr(187) . chr(181) => 'y',
\chr(225).\chr(186).\chr(160) => 'A', \chr(225).\chr(186).\chr(161) => 'a',
\chr(225).\chr(186).\chr(172) => 'A', \chr(225).\chr(186).\chr(173) => 'a',
\chr(225).\chr(186).\chr(182) => 'A', \chr(225).\chr(186).\chr(183) => 'a',
\chr(225).\chr(186).\chr(184) => 'E', \chr(225).\chr(186).\chr(185) => 'e',
\chr(225).\chr(187).\chr(134) => 'E', \chr(225).\chr(187).\chr(135) => 'e',
\chr(225).\chr(187).\chr(138) => 'I', \chr(225).\chr(187).\chr(139) => 'i',
\chr(225).\chr(187).\chr(140) => 'O', \chr(225).\chr(187).\chr(141) => 'o',
\chr(225).\chr(187).\chr(152) => 'O', \chr(225).\chr(187).\chr(153) => 'o',
\chr(225).\chr(187).\chr(162) => 'O', \chr(225).\chr(187).\chr(163) => 'o',
\chr(225).\chr(187).\chr(164) => 'U', \chr(225).\chr(187).\chr(165) => 'u',
\chr(225).\chr(187).\chr(176) => 'U', \chr(225).\chr(187).\chr(177) => 'u',
\chr(225).\chr(187).\chr(180) => 'Y', \chr(225).\chr(187).\chr(181) => 'y',
// Vowels with diacritic (Chinese, Hanyu Pinyin)
chr(201) . chr(145) => 'a',
\chr(201).\chr(145) => 'a',
// macron
chr(199) . chr(149) => 'U', chr(199) . chr(150) => 'u',
\chr(199).\chr(149) => 'U', \chr(199).\chr(150) => 'u',
// acute accent
chr(199) . chr(151) => 'U', chr(199) . chr(152) => 'u',
\chr(199).\chr(151) => 'U', \chr(199).\chr(152) => 'u',
// caron
chr(199) . chr(141) => 'A', chr(199) . chr(142) => 'a',
chr(199) . chr(143) => 'I', chr(199) . chr(144) => 'i',
chr(199) . chr(145) => 'O', chr(199) . chr(146) => 'o',
chr(199) . chr(147) => 'U', chr(199) . chr(148) => 'u',
chr(199) . chr(153) => 'U', chr(199) . chr(154) => 'u',
\chr(199).\chr(141) => 'A', \chr(199).\chr(142) => 'a',
\chr(199).\chr(143) => 'I', \chr(199).\chr(144) => 'i',
\chr(199).\chr(145) => 'O', \chr(199).\chr(146) => 'o',
\chr(199).\chr(147) => 'U', \chr(199).\chr(148) => 'u',
\chr(199).\chr(153) => 'U', \chr(199).\chr(154) => 'u',
// grave accent
chr(199) . chr(155) => 'U', chr(199) . chr(156) => 'u',
\chr(199).\chr(155) => 'U', \chr(199).\chr(156) => 'u',
];
// Used for locale-specific rules

View File

@@ -11,12 +11,10 @@ declare(strict_types=1);
namespace Chill\MainBundle\Search;
use Exception;
/**
* Throw by search provider when the search name is not found.
*/
class UnknowSearchDomainException extends Exception
class UnknowSearchDomainException extends \Exception
{
private $domain;

View File

@@ -11,12 +11,10 @@ declare(strict_types=1);
namespace Chill\MainBundle\Search;
use Exception;
/**
* Throw by search provider when the search name is not found.
*/
class UnknowSearchNameException extends Exception
class UnknowSearchNameException extends \Exception
{
private $name;

View File

@@ -11,12 +11,6 @@ declare(strict_types=1);
namespace Chill\MainBundle\Search\Utils;
use DateTimeImmutable;
use function preg_match_all;
use function strtr;
use function trim;
class ExtractDateFromPattern
{
private const DATE_PATTERN = [
@@ -32,15 +26,15 @@ class ExtractDateFromPattern
foreach (self::DATE_PATTERN as [$pattern, $format]) {
$matches = [];
preg_match_all($pattern, $filteredSubject, $matches);
\preg_match_all($pattern, $filteredSubject, $matches);
foreach ($matches[0] as $match) {
$date = DateTimeImmutable::createFromFormat($format, $match);
$date = \DateTimeImmutable::createFromFormat($format, $match);
if (false !== $date) {
$dates[] = $date;
// filter string: remove what is found
$filteredSubject = trim(strtr($filteredSubject, [$match => '']));
$filteredSubject = \trim(\strtr($filteredSubject, [$match => '']));
}
}
}

View File

@@ -12,15 +12,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\Search\Utils;
use libphonenumber\PhoneNumberUtil;
use LogicException;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use function count;
use function implode;
use function preg_match;
use function str_split;
use function strtr;
use function trim;
class ExtractPhonenumberFromPattern
{
@@ -36,19 +28,19 @@ class ExtractPhonenumberFromPattern
public function extractPhonenumber(string $subject): SearchExtractionResult
{
$matches = [];
preg_match(self::PATTERN, $subject, $matches);
\preg_match(self::PATTERN, $subject, $matches);
if (0 < count($matches)) {
if (0 < \count($matches)) {
$phonenumber = [];
$length = 0;
foreach (str_split(trim($matches[0])) as $key => $char) {
foreach (\str_split(\trim($matches[0])) as $key => $char) {
switch ($char) {
case '+':
if (0 === $key) {
$phonenumber[] = $char;
} else {
throw new LogicException('should not match not alnum character');
throw new \LogicException('should not match not alnum character');
}
break;
@@ -58,7 +50,7 @@ class ExtractPhonenumberFromPattern
if (0 === $key) {
$util = PhoneNumberUtil::getInstance();
$phonenumber[] = '+' . $util->getCountryCodeForRegion($this->defaultCarrierCode);
$phonenumber[] = '+'.$util->getCountryCodeForRegion($this->defaultCarrierCode);
} else {
$phonenumber[] = $char;
}
@@ -83,14 +75,14 @@ class ExtractPhonenumberFromPattern
break;
default:
throw new LogicException('should not match not alnum character');
throw new \LogicException('should not match not alnum character');
}
}
if (5 < $length) {
$filtered = trim(strtr($subject, [$matches[0] => '']));
$filtered = \trim(\strtr($subject, [$matches[0] => '']));
return new SearchExtractionResult($filtered, [implode('', $phonenumber)]);
return new SearchExtractionResult($filtered, [\implode('', $phonenumber)]);
}
}