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,7 +13,6 @@ namespace Chill\MainBundle\Export\Formatter;
use Chill\MainBundle\Export\ExportManager;
use Chill\MainBundle\Export\FormatterInterface;
use LogicException;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
@@ -21,19 +20,6 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\Translation\TranslatorInterface;
use function array_map;
use function array_merge;
use function array_multisort;
use function array_unique;
use function call_user_func;
use function count;
use function fopen;
use function is_array;
use function stream_get_contents;
use function sys_get_temp_dir;
use function tempnam;
use function unlink;
class SpreadSheetFormatter implements FormatterInterface
{
/**
@@ -60,7 +46,7 @@ class SpreadSheetFormatter implements FormatterInterface
*
* @var type
*/
//protected $aggregators;
// protected $aggregators;
/**
* array containing value of export form.
@@ -104,7 +90,7 @@ class SpreadSheetFormatter implements FormatterInterface
*
* @var array
*/
//protected $labels;
// protected $labels;
/**
* temporary file to store spreadsheet.
@@ -157,7 +143,7 @@ class SpreadSheetFormatter implements FormatterInterface
// ordering aggregators
$aggregators = $this->exportManager->getAggregators($aggregatorAliases);
$nb = count($aggregatorAliases);
$nb = \count($aggregatorAliases);
foreach ($aggregators as $alias => $aggregator) {
$builderAggregator = $builder->create($alias, FormType::class, [
@@ -212,15 +198,15 @@ class SpreadSheetFormatter implements FormatterInterface
$this->getContentType($this->formatterData['format'])
);
$this->tempfile = tempnam(sys_get_temp_dir(), '');
$this->tempfile = \tempnam(\sys_get_temp_dir(), '');
$this->generateContent();
$f = fopen($this->tempfile, 'rb');
$response->setContent(stream_get_contents($f));
$f = \fopen($this->tempfile, 'rb');
$response->setContent(\stream_get_contents($f));
fclose($f);
// remove the temp file from disk
unlink($this->tempfile);
\unlink($this->tempfile);
return $response;
}
@@ -238,11 +224,11 @@ class SpreadSheetFormatter implements FormatterInterface
$worksheet->fromArray(
$sortedResults,
null,
'A' . $line,
'A'.$line,
true
);
return $line + count($sortedResults) + 1;
return $line + \count($sortedResults) + 1;
}
/**
@@ -260,7 +246,7 @@ class SpreadSheetFormatter implements FormatterInterface
$filter = $this->exportManager->getFilter($alias);
$description = $filter->describeAction($data, 'string');
if (is_array($description)) {
if (\is_array($description)) {
$description = $this->translator
->trans(
$description[0],
@@ -268,7 +254,7 @@ class SpreadSheetFormatter implements FormatterInterface
);
}
$worksheet->setCellValue('A' . $line, $description);
$worksheet->setCellValue('A'.$line, $description);
++$line;
}
@@ -303,7 +289,7 @@ class SpreadSheetFormatter implements FormatterInterface
$worksheet->fromArray(
$displayables,
null,
'A' . $line
'A'.$line
);
return $line + 1;
@@ -359,7 +345,7 @@ class SpreadSheetFormatter implements FormatterInterface
'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(),
default => throw new \LogicException(),
};
$writer->save($this->tempfile);
@@ -383,7 +369,7 @@ class SpreadSheetFormatter implements FormatterInterface
$aggregator = $this->exportManager->getAggregator($alias);
$aggregatorsKeys = $aggregator->getQueryKeys($data);
// append the keys from aggregator to the $keys existing array
$keys = array_merge($keys, $aggregatorsKeys);
$keys = \array_merge($keys, $aggregatorsKeys);
// append the key with the alias, which will be use later for sorting
foreach ($aggregatorsKeys as $key) {
$aggregatorKeyAssociation[$key] = $alias;
@@ -420,7 +406,7 @@ class SpreadSheetFormatter implements FormatterInterface
case 'xlsx':
return 'application/vnd.openxmlformats-officedocument.'
. 'spreadsheetml.sheet';
.'spreadsheetml.sheet';
}
}
@@ -439,7 +425,7 @@ class SpreadSheetFormatter implements FormatterInterface
$value ??= '';
return call_user_func($this->cacheDisplayableResult[$key], $value);
return \call_user_func($this->cacheDisplayableResult[$key], $value);
}
protected function getTitle()
@@ -447,7 +433,7 @@ class SpreadSheetFormatter implements FormatterInterface
$title = $this->translator->trans($this->export->getTitle());
if (30 < strlen($title)) {
return substr($title, 0, 30) . '…';
return substr($title, 0, 30).'…';
}
return $title;
@@ -499,7 +485,7 @@ class SpreadSheetFormatter implements FormatterInterface
$this->cacheDisplayableResult[$key] = $element->getLabels($key, ['_header'], $data);
} else {
$this->cacheDisplayableResult[$key] =
$element->getLabels($key, array_unique($allValues[$key]), $data);
$element->getLabels($key, \array_unique($allValues[$key]), $data);
}
}
@@ -548,9 +534,9 @@ class SpreadSheetFormatter implements FormatterInterface
$exportKeys = $this->export->getQueryKeys($this->exportData);
$aggregatorKeys = $this->getAggregatorKeysSorted();
$globalKeys = array_merge($aggregatorKeys, $exportKeys);
$globalKeys = \array_merge($aggregatorKeys, $exportKeys);
$sortedResult = array_map(function ($row) use ($globalKeys) {
$sortedResult = \array_map(function ($row) use ($globalKeys) {
$newRow = [];
foreach ($globalKeys as $key) {
@@ -560,7 +546,7 @@ class SpreadSheetFormatter implements FormatterInterface
return $newRow;
}, $this->result);
array_multisort($sortedResult);
\array_multisort($sortedResult);
return [$sortedResult, $exportKeys, $aggregatorKeys, $globalKeys];
}