mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-30 19:43:49 +00:00
DX: apply rector rules up to php8.0
This commit is contained in:
@@ -44,10 +44,6 @@ class ExportManager
|
||||
*/
|
||||
private array $aggregators = [];
|
||||
|
||||
private AuthorizationCheckerInterface $authorizationChecker;
|
||||
|
||||
private AuthorizationHelperInterface $authorizationHelper;
|
||||
|
||||
/**
|
||||
* Collected Exports, injected by DI.
|
||||
*
|
||||
@@ -69,17 +65,15 @@ class ExportManager
|
||||
*/
|
||||
private array $formatters = [];
|
||||
|
||||
private LoggerInterface $logger;
|
||||
|
||||
/**
|
||||
* @var \Symfony\Component\Security\Core\User\UserInterface
|
||||
*/
|
||||
private $user;
|
||||
|
||||
public function __construct(
|
||||
LoggerInterface $logger,
|
||||
AuthorizationCheckerInterface $authorizationChecker,
|
||||
AuthorizationHelperInterface $authorizationHelper,
|
||||
private LoggerInterface $logger,
|
||||
private AuthorizationCheckerInterface $authorizationChecker,
|
||||
private AuthorizationHelperInterface $authorizationHelper,
|
||||
TokenStorageInterface $tokenStorage,
|
||||
iterable $exports,
|
||||
iterable $aggregators,
|
||||
@@ -87,9 +81,6 @@ class ExportManager
|
||||
//iterable $formatters,
|
||||
//iterable $exportElementProvider
|
||||
) {
|
||||
$this->logger = $logger;
|
||||
$this->authorizationChecker = $authorizationChecker;
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
$this->user = $tokenStorage->getToken()->getUser();
|
||||
$this->exports = iterator_to_array($exports);
|
||||
$this->aggregators = iterator_to_array($aggregators);
|
||||
@@ -163,7 +154,7 @@ class ExportManager
|
||||
} elseif ($element instanceof FormatterInterface) {
|
||||
$this->addFormatter($element, $alias);
|
||||
} else {
|
||||
throw new LogicException('This element ' . get_class($element) . ' '
|
||||
throw new LogicException('This element ' . $element::class . ' '
|
||||
. 'is not an instance of export element');
|
||||
}
|
||||
}
|
||||
@@ -468,12 +459,10 @@ class ExportManager
|
||||
* Return true if the current user has access to the ExportElement for every
|
||||
* center, false if the user hasn't access to element for at least one center.
|
||||
*
|
||||
* @param \Chill\MainBundle\Export\ExportElementInterface $element
|
||||
* @param DirectExportInterface|ExportInterface $export
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isGrantedForElement(ExportElementInterface $element, ?ExportElementInterface $export = null, ?array $centers = null)
|
||||
public function isGrantedForElement(ExportElementInterface $element, \Chill\MainBundle\Export\DirectExportInterface|\Chill\MainBundle\Export\ExportInterface $export = null, ?array $centers = null)
|
||||
{
|
||||
if ($element instanceof ExportInterface || $element instanceof DirectExportInterface) {
|
||||
$role = $element->requiredRole();
|
||||
@@ -506,7 +495,7 @@ class ExportManager
|
||||
//debugging
|
||||
$this->logger->debug('user has no access to element', [
|
||||
'method' => __METHOD__,
|
||||
'type' => get_class($element),
|
||||
'type' => $element::class,
|
||||
'center' => $center->getName(),
|
||||
'role' => $role,
|
||||
]);
|
||||
@@ -577,7 +566,7 @@ class ExportManager
|
||||
private function handleFilters(
|
||||
ExportInterface $export,
|
||||
QueryBuilder $qb,
|
||||
$data,
|
||||
mixed $data,
|
||||
array $centers
|
||||
) {
|
||||
$filters = $this->retrieveUsedFilters($data);
|
||||
@@ -598,11 +587,9 @@ class ExportManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return AggregatorInterface[]
|
||||
*/
|
||||
private function retrieveUsedAggregators($data)
|
||||
private function retrieveUsedAggregators(mixed $data)
|
||||
{
|
||||
if (null === $data) {
|
||||
return [];
|
||||
@@ -616,11 +603,9 @@ class ExportManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
private function retrieveUsedAggregatorsType($data)
|
||||
private function retrieveUsedAggregatorsType(mixed $data)
|
||||
{
|
||||
if (null === $data) {
|
||||
return [];
|
||||
@@ -660,7 +645,7 @@ class ExportManager
|
||||
*
|
||||
* @return array an array with types
|
||||
*/
|
||||
private function retrieveUsedFiltersType($data)
|
||||
private function retrieveUsedFiltersType(mixed $data)
|
||||
{
|
||||
if (null === $data) {
|
||||
return [];
|
||||
@@ -684,11 +669,10 @@ class ExportManager
|
||||
/**
|
||||
* parse the data to retrieve the used filters and aggregators.
|
||||
*
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
private function retrieveUsedModifiers($data)
|
||||
private function retrieveUsedModifiers(mixed $data)
|
||||
{
|
||||
if (null === $data) {
|
||||
return [];
|
||||
|
@@ -56,13 +56,10 @@ class CSVFormatter implements FormatterInterface
|
||||
|
||||
protected $result;
|
||||
|
||||
protected TranslatorInterface $translator;
|
||||
|
||||
public function __construct(
|
||||
TranslatorInterface $translator,
|
||||
protected TranslatorInterface $translator,
|
||||
ExportManager $manager
|
||||
) {
|
||||
$this->translator = $translator;
|
||||
$this->exportManager = $manager;
|
||||
}
|
||||
|
||||
|
@@ -347,27 +347,12 @@ class SpreadSheetFormatter implements FormatterInterface
|
||||
|
||||
$line = $this->addContentTable($worksheet, $sortedResult, $line);
|
||||
|
||||
switch ($this->formatterData['format']) {
|
||||
case 'ods':
|
||||
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Ods');
|
||||
|
||||
break;
|
||||
|
||||
case 'xlsx':
|
||||
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||||
|
||||
break;
|
||||
|
||||
case 'csv':
|
||||
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Csv');
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
// this should not happen
|
||||
// throw an exception to ensure that the error is catched
|
||||
throw new LogicException();
|
||||
}
|
||||
$writer = match ($this->formatterData['format']) {
|
||||
'ods' => \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Ods'),
|
||||
'xlsx' => \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'),
|
||||
'csv' => \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Csv'),
|
||||
default => throw new LogicException(),
|
||||
};
|
||||
|
||||
$writer->save($this->tempfile);
|
||||
}
|
||||
@@ -435,11 +420,10 @@ class SpreadSheetFormatter implements FormatterInterface
|
||||
* Get the displayable result.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDisplayableResult($key, $value)
|
||||
protected function getDisplayableResult($key, mixed $value)
|
||||
{
|
||||
if (false === $this->cacheDisplayableResultIsInitialized) {
|
||||
$this->initializeCache($key);
|
||||
|
@@ -18,11 +18,8 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class DateTimeHelper
|
||||
{
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
public function __construct(private TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function getLabel($header): callable
|
||||
|
@@ -74,14 +74,6 @@ class ExportAddressHelper
|
||||
'geographical_units' => ['_unit_names', '_unit_refs'],
|
||||
];
|
||||
|
||||
private AddressRender $addressRender;
|
||||
|
||||
private AddressRepository $addressRepository;
|
||||
|
||||
private GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository;
|
||||
|
||||
private TranslatableStringHelperInterface $translatableStringHelper;
|
||||
|
||||
/**
|
||||
* @var array<string, string, GeographicalUnitLayer>>|null
|
||||
*/
|
||||
@@ -92,16 +84,8 @@ class ExportAddressHelper
|
||||
*/
|
||||
private ?array $unitRefsKeysCache = [];
|
||||
|
||||
public function __construct(
|
||||
AddressRender $addressRender,
|
||||
AddressRepository $addressRepository,
|
||||
GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository,
|
||||
TranslatableStringHelperInterface $translatableStringHelper
|
||||
) {
|
||||
$this->addressRepository = $addressRepository;
|
||||
$this->geographicalUnitLayerRepository = $geographicalUnitLayerRepository;
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
$this->addressRender = $addressRender;
|
||||
public function __construct(private AddressRender $addressRender, private AddressRepository $addressRepository, private GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository, private TranslatableStringHelperInterface $translatableStringHelper)
|
||||
{
|
||||
}
|
||||
|
||||
public function addSelectClauses(int $params, QueryBuilder $queryBuilder, $entityName = 'address', $prefix = 'add')
|
||||
@@ -369,16 +353,11 @@ class ExportAddressHelper
|
||||
|
||||
$decodedValues = json_decode($value, true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
switch (count($decodedValues)) {
|
||||
case 0:
|
||||
return '';
|
||||
|
||||
case 1:
|
||||
return $decodedValues[0];
|
||||
|
||||
default:
|
||||
return implode('|', $decodedValues);
|
||||
}
|
||||
return match (count($decodedValues)) {
|
||||
0 => '',
|
||||
1 => $decodedValues[0],
|
||||
default => implode('|', $decodedValues),
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -21,11 +21,8 @@ use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
*/
|
||||
class TranslatableStringExportLabelHelper
|
||||
{
|
||||
private TranslatableStringHelperInterface $translatableStringHelper;
|
||||
|
||||
public function __construct(TranslatableStringHelperInterface $translatableStringHelper)
|
||||
public function __construct(private TranslatableStringHelperInterface $translatableStringHelper)
|
||||
{
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
}
|
||||
|
||||
public function getLabel(string $key, array $values, string $header)
|
||||
|
@@ -18,14 +18,8 @@ use const SORT_NUMERIC;
|
||||
|
||||
class UserHelper
|
||||
{
|
||||
private UserRender $userRender;
|
||||
|
||||
private UserRepositoryInterface $userRepository;
|
||||
|
||||
public function __construct(UserRender $userRender, UserRepositoryInterface $userRepository)
|
||||
public function __construct(private UserRender $userRender, private UserRepositoryInterface $userRepository)
|
||||
{
|
||||
$this->userRender = $userRender;
|
||||
$this->userRepository = $userRepository;
|
||||
}
|
||||
|
||||
public function getLabel($key, array $values, string $header): callable
|
||||
|
Reference in New Issue
Block a user