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

@@ -25,9 +25,9 @@ class CSVCellTwig extends AbstractExtension
/**
* Replace into a string the char " by "".
*
* @param string $content The input string.
* @param string $content the input string
*
* @return string The safe string.
* @return string the safe string
*/
public function csvCellFilter($content)
{
@@ -55,7 +55,7 @@ class CSVCellTwig extends AbstractExtension
/**
* Returns the name of the extension.
*
* @return The name of the extension.
* @return The name of the extension
*/
public function getName()
{

View File

@@ -11,7 +11,6 @@ declare(strict_types=1);
namespace Chill\MainBundle\Templating;
use Parsedown;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
@@ -21,13 +20,13 @@ use Twig\TwigFilter;
final class ChillMarkdownRenderExtension extends AbstractExtension
{
/**
* @var Parsedown
* @var \Parsedown
*/
protected $parsedown;
public function __construct()
{
$this->parsedown = new Parsedown();
$this->parsedown = new \Parsedown();
$this->parsedown->setSafeMode(true);
}

View File

@@ -16,8 +16,6 @@ use Twig\Environment;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use function array_merge;
class ChillTwigHelper extends AbstractExtension
{
public function getFilters()
@@ -46,7 +44,7 @@ class ChillTwigHelper extends AbstractExtension
* - `date_format` (default to `'medium'`)
* - `time_format` (default to `'none'`)
*
* @param string $value Default to 'No value'. Fallback to default if null
* @param string $value Default to 'No value'. Fallback to default if null
* @param string $message
* @param string $template
*
@@ -59,24 +57,24 @@ class ChillTwigHelper extends AbstractExtension
$template = 'default',
array $options = []
) {
if ($value instanceof DateTimeInterface) {
$options = array_merge([
if ($value instanceof \DateTimeInterface) {
$options = \array_merge([
'date_format' => 'medium',
'time_format' => 'none',
], $options);
$t = match ($template) {
'default', 'blockquote' => '@ChillMain/Extensions/PrintOrMessage/' . $template . '_date.html.twig',
'default', 'blockquote' => '@ChillMain/Extensions/PrintOrMessage/'.$template.'_date.html.twig',
default => $template,
};
} else {
$t = match ($template) {
'default', 'blockquote' => '@ChillMain/Extensions/PrintOrMessage/' . $template . '.html.twig',
'default', 'blockquote' => '@ChillMain/Extensions/PrintOrMessage/'.$template.'.html.twig',
default => $template,
};
}
return $twig->render($t, array_merge([
return $twig->render($t, \array_merge([
'value' => $value,
'message' => $message,
], $options));

View File

@@ -69,9 +69,9 @@ class ChillTwigRoutingHelper extends AbstractExtension
/**
* Build an url with a returnPath parameter to current page.
*
* @param string $name
* @param array $parameters
* @param bool $relative
* @param string $name
* @param array $parameters
* @param bool $relative
* @param mixed|null $label
*
* @return string
@@ -93,8 +93,8 @@ class ChillTwigRoutingHelper extends AbstractExtension
* Build an url with a returnPath parameter to current page.
*
* @param string $name
* @param array $parameters
* @param bool $relative
* @param array $parameters
* @param bool $relative
*
* @return string
*/
@@ -118,8 +118,8 @@ class ChillTwigRoutingHelper extends AbstractExtension
* Return the return path if it exists, or generate the path if not.
*
* @param string $name
* @param array $parameters
* @param bool $relative
* @param array $parameters
* @param bool $relative
*
* @return string
*/

View File

@@ -12,7 +12,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\Templating\Entity;
/**
* @deprecated load @link{BoxUtilsChillEntityRenderTrait} in the render
* @deprecated load @see{BoxUtilsChillEntityRenderTrait} in the render
*/
abstract class AbstractChillEntityRender implements ChillEntityRenderInterface
{

View File

@@ -13,12 +13,6 @@ namespace Chill\MainBundle\Templating\Entity;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Templating\EngineInterface;
use function array_merge;
use function strtr;
/**
* @implements ChillEntityRenderInterface<Address>
@@ -40,7 +34,7 @@ class AddressRender implements ChillEntityRenderInterface
public function renderBox($addr, array $options): string
{
$options = array_merge(self::DEFAULT_OPTIONS, $options);
$options = \array_merge(self::DEFAULT_OPTIONS, $options);
return $this->templating
->render('@ChillMain/Entity/address.html.twig', [
@@ -60,7 +54,7 @@ class AddressRender implements ChillEntityRenderInterface
$lines = [];
if (null !== $addr->getPostcode()) {
if ($addr->getPostcode()->getCountry()->getCountryCode() === 'FR') {
if ('FR' === $addr->getPostcode()->getCountry()->getCountryCode()) {
$lines[] = $this->renderIntraBuildingLine($addr);
$lines[] = $this->renderBuildingLine($addr);
$lines[] = $this->renderStreetLine($addr);
@@ -105,10 +99,10 @@ class AddressRender implements ChillEntityRenderInterface
$streetNumber = '';
}
$res = trim($street . ', ' . $streetNumber, ', ');
$res = trim($street.', '.$streetNumber, ', ');
if ($addr->getPostcode()->getCountry()->getCountryCode() === 'FR') {
$res = trim($streetNumber . ', ' . $street, ', ');
if ('FR' === $addr->getPostcode()->getCountry()->getCountryCode()) {
$res = trim($streetNumber.', '.$street, ', ');
}
if ((',' === $res) || ('' === $res)) {
@@ -130,7 +124,7 @@ class AddressRender implements ChillEntityRenderInterface
private function renderBuildingLine(Address $addr): ?string
{
if ($addr->getBuildingName() !== '') {
if ('' !== $addr->getBuildingName()) {
$building = $addr->getBuildingName();
} else {
$building = '';
@@ -141,13 +135,13 @@ class AddressRender implements ChillEntityRenderInterface
$intraBuilding = '';
}
$res = trim($building . ' - ' . $intraBuilding, ' - ');
$res = trim($building.' - '.$intraBuilding, ' - ');
if ('' === $res) {
$res = null;
}
if ($addr->getPostcode()->getCountry()->getCountryCode() === 'FR') {
if ('FR' === $addr->getPostcode()->getCountry()->getCountryCode()) {
$res = $addr->getBuildingName();
}
@@ -157,14 +151,14 @@ class AddressRender implements ChillEntityRenderInterface
private function renderCityLine(Address $addr): string
{
if (null !== $addr->getPostcode()) {
$res = strtr('{postcode} {label}', [
$res = \strtr('{postcode} {label}', [
'{postcode}' => $addr->getPostcode()->getCode(),
'{label}' => $addr->getPostcode()->getName(),
]);
if ($addr->getPostcode()->getCountry()->getCountryCode() === 'FR') {
if ('FR' === $addr->getPostcode()->getCountry()->getCountryCode()) {
if ('' !== $addr->getDistribution()) {
$res = $res . ' ' . $addr->getDistribution();
$res = $res.' '.$addr->getDistribution();
}
}
}
@@ -189,19 +183,19 @@ class AddressRender implements ChillEntityRenderInterface
$arr = [];
if ('' !== $addr->getFlat()) {
$arr[] = 'appart ' . $addr->getFlat();
$arr[] = 'appart '.$addr->getFlat();
}
if ('' !== $addr->getFloor()) {
$arr[] = 'ét ' . $addr->getFloor();
$arr[] = 'ét '.$addr->getFloor();
}
if ('' !== $addr->getCorridor()) {
$arr[] = 'coul ' . $addr->getCorridor();
$arr[] = 'coul '.$addr->getCorridor();
}
if ('' !== $addr->getSteps()) {
$arr[] = 'esc ' . $addr->getSteps();
$arr[] = 'esc '.$addr->getSteps();
}
$res = implode(' - ', $arr);

View File

@@ -20,6 +20,6 @@ trait BoxUtilsChillEntityRenderTrait
protected function getDefaultOpeningBox($classSuffix): string
{
return '<section class="chill-entity entity-' . $classSuffix . '">';
return '<section class="chill-entity entity-'.$classSuffix.'">';
}
}

View File

@@ -20,8 +20,8 @@ class ChillEntityRender implements ChillEntityRenderInterface
public function renderBox($entity, array $options): string
{
return $this->getDefaultOpeningBox('default') . $entity
. $this->getDefaultClosingBox();
return $this->getDefaultOpeningBox('default').$entity
.$this->getDefaultClosingBox();
}
public function renderString($entity, array $options): string

View File

@@ -53,9 +53,6 @@ class ChillEntityRenderExtension extends AbstractExtension
];
}
/**
* @param $entity
*/
public function renderBox($entity, array $options = []): string
{
if (null === $entity) {
@@ -66,9 +63,6 @@ class ChillEntityRenderExtension extends AbstractExtension
->renderBox($entity, $options);
}
/**
* @param $entity
*/
public function renderString($entity, array $options = []): string
{
if (null === $entity) {
@@ -79,10 +73,6 @@ class ChillEntityRenderExtension extends AbstractExtension
->renderString($entity, $options);
}
/**
* @param $entity
* @param $options
*/
protected function getRender($entity, $options): ?ChillEntityRenderInterface
{
foreach ($this->renders as $render) {

View File

@@ -32,6 +32,7 @@ interface ChillEntityRenderInterface
* ```
*
* @param T $entity
*
* @phpstan-pure
*/
public function renderBox($entity, array $options): string;
@@ -42,6 +43,7 @@ interface ChillEntityRenderInterface
* Example: returning the name of a person.
*
* @param T $entity
*
* @phpstan-pure
*/
public function renderString($entity, array $options): string;

View File

@@ -12,11 +12,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\Templating\Entity;
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
use Chill\MainBundle\Repository\UserRepository;
use Chill\MainBundle\Repository\UserRepositoryInterface;
use Symfony\Component\Templating\EngineInterface;
use function array_merge;
/**
* @implements ChillEntityRenderInterface<CommentEmbeddable>
@@ -30,7 +26,7 @@ class CommentRender implements ChillEntityRenderInterface
public function renderBox($entity, array $options): string
{
// default options
$options = array_merge([
$options = \array_merge([
'user' => [],
'disable_markdown' => false,
'limit_lines' => null,

View File

@@ -13,11 +13,7 @@ namespace Chill\MainBundle\Templating\Entity;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use DateTimeImmutable;
use Symfony\Component\Templating\EngineInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use function array_merge;
/**
* @implements ChillEntityRenderInterface<User>
@@ -33,12 +29,9 @@ class UserRender implements ChillEntityRenderInterface
public function __construct(private readonly TranslatableStringHelper $translatableStringHelper, private readonly \Twig\Environment $engine, private readonly TranslatorInterface $translator) {}
/**
* @param mixed $entity
*/
public function renderBox($entity, array $options): string
{
$opts = array_merge(self::DEFAULT_OPTIONS, $options);
$opts = \array_merge(self::DEFAULT_OPTIONS, $options);
return $this->engine->render('@ChillMain/Entity/user.html.twig', [
'user' => $entity,
@@ -46,27 +39,24 @@ class UserRender implements ChillEntityRenderInterface
]);
}
/**
* @param mixed $entity
*/
public function renderString($entity, array $options): string
{
$opts = array_merge(self::DEFAULT_OPTIONS, $options);
$opts = \array_merge(self::DEFAULT_OPTIONS, $options);
$str = $entity->getLabel();
if (null !== $entity->getUserJob($opts['at']) && $opts['user_job']) {
$str .= ' (' . $this->translatableStringHelper
->localize($entity->getUserJob($opts['at'])->getLabel()) . ')';
$str .= ' ('.$this->translatableStringHelper
->localize($entity->getUserJob($opts['at'])->getLabel()).')';
}
if (null !== $entity->getMainScope($opts['at']) && $opts['main_scope']) {
$str .= ' (' . $this->translatableStringHelper
->localize($entity->getMainScope($opts['at'])->getName()) . ')';
$str .= ' ('.$this->translatableStringHelper
->localize($entity->getMainScope($opts['at'])->getName()).')';
}
if ($entity->isAbsent() && $opts['absence']) {
$str .= ' (' . $this->translator->trans('absence.Absent') . ')';
$str .= ' ('.$this->translator->trans('absence.Absent').')';
}
return $str;

View File

@@ -11,8 +11,6 @@ declare(strict_types=1);
namespace Chill\MainBundle\Templating\Events;
use ArrayAccess;
use RuntimeException;
use Symfony\Component\EventDispatcher\Event;
/**
@@ -30,7 +28,7 @@ use Symfony\Component\EventDispatcher\Event;
* The keys are read-only: if you try to update the context using array access
* (example, using `$event['context_key'] = $bar;`, an error will be thrown.
*/
class DelegatedBlockRenderingEvent extends \Symfony\Contracts\EventDispatcher\Event implements ArrayAccess
class DelegatedBlockRenderingEvent extends \Symfony\Contracts\EventDispatcher\Event implements \ArrayAccess
{
/**
* The returned content of the event.
@@ -82,13 +80,11 @@ class DelegatedBlockRenderingEvent extends \Symfony\Contracts\EventDispatcher\Ev
public function offsetSet($offset, $value): never
{
throw new RuntimeException('The event context is read-only, you are not '
. 'allowed to update it.');
throw new \RuntimeException('The event context is read-only, you are not allowed to update it.');
}
public function offsetUnset($offset): never
{
throw new RuntimeException('The event context is read-only, you are not '
. 'allowed to update it.');
throw new \RuntimeException('The event context is read-only, you are not allowed to update it.');
}
}

View File

@@ -25,7 +25,7 @@ final readonly class FilterOrderGetActiveFilterHelper
) {}
/**
* Return all the data required to display the active filters
* Return all the data required to display the active filters.
*
* @return array<array{label: string, value: string, position: string, name: string}>
*/
@@ -38,7 +38,7 @@ final readonly class FilterOrderGetActiveFilterHelper
}
foreach ($filterOrderHelper->getDateRanges() as $name => ['label' => $label]) {
$base = ['position' => FilterOrderPositionEnum::DateRange->value, 'name' => $name, 'label' => (string)$label];
$base = ['position' => FilterOrderPositionEnum::DateRange->value, 'name' => $name, 'label' => (string) $label];
if (null !== ($from = $filterOrderHelper->getDateRangeData($name)['from'] ?? null)) {
$result[] = ['value' => $this->translator->trans('filter_order.by_date.From', ['from_date' => $from]), ...$base];
@@ -66,7 +66,7 @@ final readonly class FilterOrderGetActiveFilterHelper
throw new \UnexpectedValueException(sprintf("we are not able to transform the value of %s to a string. Implements \\Stringable or add a 'choice_label' option to the filterFormBuilder", $selected::class));
}
$value = (string)$selected;
$value = (string) $selected;
}
$result[] = ['value' => $this->translator->trans($value), 'label' => $label, 'position' => FilterOrderPositionEnum::EntityChoice->value, 'name' => $name];

View File

@@ -13,13 +13,10 @@ namespace Chill\MainBundle\Templating\Listing;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Form\Type\Listing\FilterOrderType;
use DateTimeImmutable;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use function array_merge;
final class FilterOrderHelper
{
private array $checkboxes = [];
@@ -78,14 +75,13 @@ final class FilterOrderHelper
return $this->entityChoices;
}
public function addUserPicker(string $name, ?string $label = null, array $options = []): self
public function addUserPicker(string $name, string $label = null, array $options = []): self
{
$this->userPickers[$name] = ['label' => $label, 'options' => $options];
return $this;
}
public function addCheckbox(string $name, array $choices, ?array $default = [], ?array $trans = [], array $options = []): self
{
if ([] === $trans) {
@@ -102,7 +98,7 @@ final class FilterOrderHelper
return $this;
}
public function addDateRange(string $name, ?string $label = null, ?DateTimeImmutable $from = null, ?DateTimeImmutable $to = null): self
public function addDateRange(string $name, string $label = null, \DateTimeImmutable $from = null, \DateTimeImmutable $to = null): self
{
$this->dateRanges[$name] = ['from' => $from, 'to' => $to, 'label' => $label];
@@ -112,7 +108,7 @@ final class FilterOrderHelper
public function buildForm(): FormInterface
{
return $this->formFactory
->createNamed(self::FORM_NAME, $this->formType, $this->getDefaultData(), array_merge([
->createNamed(self::FORM_NAME, $this->formType, $this->getDefaultData(), \array_merge([
'helper' => $this,
'method' => 'GET',
'csrf_protection' => false,
@@ -187,7 +183,7 @@ final class FilterOrderHelper
}
/**
* @return array{to: ?DateTimeImmutable, from: ?DateTimeImmutable}
* @return array{to: ?\DateTimeImmutable, from: ?\DateTimeImmutable}
*/
public function getDateRangeData(string $name): array
{
@@ -223,7 +219,7 @@ final class FilterOrderHelper
'dateRanges' => [],
'single_checkboxes' => [],
'entity_choices' => [],
'user_pickers' => []
'user_pickers' => [],
];
if ($this->hasSearchBox()) {

View File

@@ -11,11 +11,8 @@ declare(strict_types=1);
namespace Chill\MainBundle\Templating\Listing;
use DateTimeImmutable;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class FilterOrderHelperBuilder
{
@@ -66,7 +63,7 @@ class FilterOrderHelperBuilder
return $this;
}
public function addDateRange(string $name, ?string $label = null, ?DateTimeImmutable $from = null, ?DateTimeImmutable $to = null): self
public function addDateRange(string $name, string $label = null, \DateTimeImmutable $from = null, \DateTimeImmutable $to = null): self
{
$this->dateRanges[$name] = ['from' => $from, 'to' => $to, 'label' => $label];
@@ -80,7 +77,7 @@ class FilterOrderHelperBuilder
return $this;
}
public function addUserPicker(string $name, ?string $label = null, ?array $options = []): self
public function addUserPicker(string $name, string $label = null, ?array $options = []): self
{
$this->userPickers[$name] = ['label' => $label, 'options' => $options];
@@ -128,7 +125,6 @@ class FilterOrderHelperBuilder
$helper->addDateRange($name, $label, $from, $to);
}
foreach (
$this->userPickers as $name => [
'label' => $label,
@@ -138,7 +134,6 @@ class FilterOrderHelperBuilder
$helper->addUserPicker($name, $label, $options);
}
return $helper;
}
}

View File

@@ -13,8 +13,6 @@ namespace Chill\MainBundle\Templating\Listing;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class FilterOrderHelperFactory implements FilterOrderHelperFactoryInterface
{

View File

@@ -15,8 +15,6 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\Translation\TranslatorInterface;
use function array_key_exists;
final class TranslatableStringHelper implements TranslatableStringHelperInterface
{
private readonly string $defaultLocale;
@@ -36,12 +34,12 @@ final class TranslatableStringHelper implements TranslatableStringHelperInterfac
$language = null === $request ? $this->defaultLocale : $request->getLocale();
if (array_key_exists($language, $translatableStrings)) {
if (\array_key_exists($language, $translatableStrings)) {
return $translatableStrings[$language];
}
foreach ($this->translator->getFallbackLocales() as $locale) {
if (array_key_exists($locale, $translatableStrings)) {
if (\array_key_exists($locale, $translatableStrings)) {
return $translatableStrings[$locale];
}
}

View File

@@ -43,7 +43,7 @@ class TranslatableStringTwig extends AbstractExtension
/**
* Returns the name of the extension.
*
* @return The name of the extension.
* @return The name of the extension
*/
public function getName()
{

View File

@@ -17,9 +17,6 @@ use Twig\Environment;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
use function array_key_exists;
use function ksort;
/**
* Add the function `chill_delegated_block`.
*
@@ -78,7 +75,7 @@ class WidgetRenderingTwig extends AbstractExtension
* which add the widget to this class when it is created by from DI, according
* to the given config under `chill_main`.
*
* @param string $place
* @param string $place
* @param WidgetInterface $widget
*/
public function addWidget($place, mixed $ordering, $widget, array $config = [])
@@ -127,9 +124,9 @@ class WidgetRenderingTwig extends AbstractExtension
// for old rendering events (deprecated)
$event = new DelegatedBlockRenderingEvent($context);
$this->eventDispatcher->dispatch($event, 'chill_block.' . $block);
$this->eventDispatcher->dispatch($event, 'chill_block.'.$block);
return $content . ' ' . $event->getContent();
return $content.' '.$event->getContent();
}
/**
@@ -139,11 +136,11 @@ class WidgetRenderingTwig extends AbstractExtension
*/
protected function getWidgetsArraysOrdered($place)
{
if (!array_key_exists($place, $this->widget)) {
if (!\array_key_exists($place, $this->widget)) {
$this->widget[$place] = [];
}
ksort($this->widget[$place]);
\ksort($this->widget[$place]);
return $this->widget[$place];
}