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

@@ -11,9 +11,6 @@ declare(strict_types=1);
namespace Chill\MainBundle\Export\Helper;
use DateTime;
use DateTimeInterface;
use Exception;
use Symfony\Contracts\Translation\TranslatorInterface;
class DateTimeHelper
@@ -31,23 +28,22 @@ class DateTimeHelper
return '';
}
if ($value instanceof DateTimeInterface) {
if ($value instanceof \DateTimeInterface) {
return $value;
}
// warning: won't work with DateTimeImmutable as we reset time a few lines later
$date = DateTime::createFromFormat('Y-m-d', $value);
$date = \DateTime::createFromFormat('Y-m-d', $value);
$hasTime = false;
if (false === $date) {
$date = DateTime::createFromFormat('Y-m-d H:i:s', $value);
$date = \DateTime::createFromFormat('Y-m-d H:i:s', $value);
$hasTime = true;
}
// check that the creation could occurs.
if (false === $date) {
throw new Exception(sprintf('The value %s could '
. 'not be converted to %s', $value, DateTime::class));
throw new \Exception(sprintf('The value %s could not be converted to %s', $value, \DateTime::class));
}
if (!$hasTime) {

View File

@@ -18,11 +18,6 @@ use Chill\MainBundle\Repository\GeographicalUnitLayerRepositoryInterface;
use Chill\MainBundle\Templating\Entity\AddressRender;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Doctrine\ORM\QueryBuilder;
use LogicException;
use function array_key_exists;
use function count;
use function in_array;
use function strlen;
/**
* Helps to load addresses and format them in list.
@@ -116,8 +111,8 @@ class ExportAddressHelper
case 'postcode_code':
$postCodeAlias = sprintf('%spostcode_t', $prefix);
if (!in_array($postCodeAlias, $queryBuilder->getAllAliases(), true)) {
$queryBuilder->leftJoin($entityName . '.postcode', $postCodeAlias);
if (!\in_array($postCodeAlias, $queryBuilder->getAllAliases(), true)) {
$queryBuilder->leftJoin($entityName.'.postcode', $postCodeAlias);
}
if ('postcode_name' === $field) {
@@ -134,7 +129,7 @@ class ExportAddressHelper
$countryAlias = sprintf('%scountry_t', $prefix);
if (!in_array($countryAlias, $queryBuilder->getAllAliases(), true)) {
if (!\in_array($countryAlias, $queryBuilder->getAllAliases(), true)) {
$queryBuilder->leftJoin(sprintf('%s.country', $postCodeAlias), $countryAlias);
}
@@ -211,7 +206,7 @@ class ExportAddressHelper
break;
default:
throw new LogicException(sprintf('This key is not supported: %s, field %s', $key, $field));
throw new \LogicException(sprintf('This key is not supported: %s, field %s', $key, $field));
}
}
}
@@ -239,7 +234,7 @@ class ExportAddressHelper
$prefixes = array_merge(
$prefixes,
array_map(
static fn ($item) => $prefix . $item,
static fn ($item) => $prefix.$item,
self::COLUMN_MAPPING[$key]
)
);
@@ -251,7 +246,7 @@ class ExportAddressHelper
public function getLabel($key, array $values, $data, string $prefix = '', string $translationPrefix = 'export.address_helper.'): callable
{
$sanitizedKey = substr((string) $key, strlen($prefix));
$sanitizedKey = substr((string) $key, \strlen($prefix));
switch ($sanitizedKey) {
case 'id':
@@ -270,7 +265,7 @@ class ExportAddressHelper
case 'postcode_name':
return static function ($value) use ($sanitizedKey, $translationPrefix) {
if ('_header' === $value) {
return $translationPrefix . $sanitizedKey;
return $translationPrefix.$sanitizedKey;
}
if (null === $value) {
@@ -283,7 +278,7 @@ class ExportAddressHelper
case 'country':
return function ($value) use ($sanitizedKey, $translationPrefix) {
if ('_header' === $value) {
return $translationPrefix . $sanitizedKey;
return $translationPrefix.$sanitizedKey;
}
if (null === $value) {
@@ -297,7 +292,7 @@ class ExportAddressHelper
case 'confidential':
return static function ($value) use ($sanitizedKey, $translationPrefix) {
if ('_header' === $value) {
return $translationPrefix . $sanitizedKey;
return $translationPrefix.$sanitizedKey;
}
switch ($value) {
@@ -311,14 +306,14 @@ class ExportAddressHelper
return 0;
default:
throw new LogicException('this value is not supported for ' . $sanitizedKey . ': ' . $value);
throw new \LogicException('this value is not supported for '.$sanitizedKey.': '.$value);
}
};
case '_as_string':
return function ($value) use ($sanitizedKey, $translationPrefix) {
if ('_header' === $value) {
return $translationPrefix . $sanitizedKey;
return $translationPrefix.$sanitizedKey;
}
if (null === $value) {
@@ -333,7 +328,7 @@ class ExportAddressHelper
default:
$layerNamesKeys = [...$this->generateKeysForUnitsNames($prefix), ...$this->generateKeysForUnitsRefs($prefix)];
if (array_key_exists($key, $layerNamesKeys)) {
if (\array_key_exists($key, $layerNamesKeys)) {
return function ($value) use ($key, $layerNamesKeys) {
if ('_header' === $value) {
$header = $this->translatableStringHelper->localize($layerNamesKeys[$key]->getName());
@@ -351,7 +346,7 @@ class ExportAddressHelper
$decodedValues = json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR);
return match (count($decodedValues)) {
return match (\count($decodedValues)) {
0 => '',
1 => $decodedValues[0],
default => implode('|', $decodedValues),
@@ -359,7 +354,7 @@ class ExportAddressHelper
};
}
throw new LogicException('this key is not supported: ' . $sanitizedKey);
throw new \LogicException('this key is not supported: '.$sanitizedKey);
}
}
@@ -368,14 +363,14 @@ class ExportAddressHelper
*/
private function generateKeysForUnitsNames(string $prefix): array
{
if (array_key_exists($prefix, $this->unitNamesKeysCache)) {
if (\array_key_exists($prefix, $this->unitNamesKeysCache)) {
return $this->unitNamesKeysCache[$prefix];
}
$keys = [];
foreach ($this->geographicalUnitLayerRepository->findAllHavingUnits() as $layer) {
$keys[$prefix . 'unit_names_' . $layer->getId()] = $layer;
$keys[$prefix.'unit_names_'.$layer->getId()] = $layer;
}
return $this->unitNamesKeysCache[$prefix] = $keys;
@@ -386,14 +381,14 @@ class ExportAddressHelper
*/
private function generateKeysForUnitsRefs(string $prefix): array
{
if (array_key_exists($prefix, $this->unitRefsKeysCache)) {
if (\array_key_exists($prefix, $this->unitRefsKeysCache)) {
return $this->unitRefsKeysCache[$prefix];
}
$keys = [];
foreach ($this->geographicalUnitLayerRepository->findAllHavingUnits() as $layer) {
$keys[$prefix . 'unit_refs_' . $layer->getId()] = $layer;
$keys[$prefix.'unit_refs_'.$layer->getId()] = $layer;
}
return $this->unitRefsKeysCache[$prefix] = $keys;

View File

@@ -13,23 +13,21 @@ namespace Chill\MainBundle\Export\Helper;
use Chill\MainBundle\Repository\UserRepositoryInterface;
use Chill\MainBundle\Templating\Entity\UserRender;
use function count;
use const SORT_NUMERIC;
class UserHelper
{
public function __construct(private readonly UserRender $userRender, private readonly UserRepositoryInterface $userRepository) {}
/**
* Return a callable that will transform a value into a string representing a user
* Return a callable that will transform a value into a string representing a user.
*
* The callable may receive as argument:
*
* - an int or a string, the id of the user;
* - a string containing a json which will be decoded, and will have this structure: array{uid: int, d: string}. The job and scopes will be shown at this date
*
* @param string $key the key of the content
* @param array $values the list of values
* @param string $key the key of the content
* @param array $values the list of values
* @param string $header the header's content
*/
public function getLabel($key, array $values, string $header): callable
@@ -66,17 +64,15 @@ class UserHelper
}
/**
* Return a callable that will transform a value into a string representing a user
* Return a callable that will transform a value into a string representing a user.
*
* The callable may receive as argument:
*
* - an int or a string, the id of the user;
* - a string containing a json which will be decoded, and will have this structure: array{uid: int, d: string}. The job and scopes will be shown at this date * @param $key
*
* @param string $key the key of the element
* @param array $values a list of values
* @param string $key the key of the element
* @param array $values a list of values
* @param string $header the header's content
* @return callable
*/
public function getLabelMulti($key, array $values, string $header): callable
{
@@ -91,7 +87,7 @@ class UserHelper
$decoded = json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR);
if (0 === count($decoded)) {
if (0 === \count($decoded)) {
return '';
}
$asStrings = [];