cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,28 +1,47 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Search\Utils;
use LogicException;
use function implode;
use function preg_match;
use function str_split;
use function strtr;
use function trim;
class ExtractPhonenumberFromPattern
{
private const PATTERN = "([\+]{0,1}[0-9\ ]{5,})";
private const PATTERN = '([\\+]{0,1}[0-9\\ ]{5,})';
public function extractPhonenumber(string $subject): SearchExtractionResult
{
$matches = [];
\preg_match(self::PATTERN, $subject,$matches);
preg_match(self::PATTERN, $subject, $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 '0':
$length++;
if ($key === 0) { $phonenumber[] = '+32'; }
else { $phonenumber[] = $char; }
if (0 === $key) {
$phonenumber[] = '+32';
} else {
$phonenumber[] = $char;
}
break;
case '1':
case '2':
case '3':
@@ -34,18 +53,21 @@ class ExtractPhonenumberFromPattern
case '9':
$length++;
$phonenumber[] = $char;
break;
case ' ':
break;
default:
throw new \LogicException("should not match not alnum character");
throw new LogicException('should not match not alnum character');
}
}
if ($length > 5) {
$filtered = \trim(\strtr($subject, [$matches[0] => '']));
if (5 < $length) {
$filtered = trim(strtr($subject, [$matches[0] => '']));
return new SearchExtractionResult($filtered, [\implode('', $phonenumber)] );
return new SearchExtractionResult($filtered, [implode('', $phonenumber)]);
}
}