diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 953db5b1..d2f6db5f 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -24,16 +24,14 @@ * @author Thomas Rabaix * @author Alexander */ -class Configuration implements ConfigurationInterface +final class Configuration implements ConfigurationInterface { /** * @psalm-suppress PossiblyNullReference, PossiblyUndefinedMethod * * @see https://github.com/psalm/psalm-plugin-symfony/issues/174 - * - * @return TreeBuilder */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('sonata_intl'); $rootNode = $treeBuilder->getRootNode(); diff --git a/src/DependencyInjection/SonataIntlExtension.php b/src/DependencyInjection/SonataIntlExtension.php index e059930e..5b1ee2ba 100644 --- a/src/DependencyInjection/SonataIntlExtension.php +++ b/src/DependencyInjection/SonataIntlExtension.php @@ -21,12 +21,10 @@ use Symfony\Component\HttpKernel\DependencyInjection\Extension; /** - * SonataIntlExtension. - * * @author Thomas Rabaix * @author Alexander */ -class SonataIntlExtension extends Extension +final class SonataIntlExtension extends Extension { /** * @param array $configs @@ -47,7 +45,7 @@ public function load(array $configs, ContainerBuilder $container): void /** * @param mixed[] $config */ - protected function configureTimezone(ContainerBuilder $container, array $config): void + private function configureTimezone(ContainerBuilder $container, array $config): void { if (isset($config['timezone']['service'])) { $container->setAlias('sonata.intl.timezone_detector', $config['timezone']['service']); @@ -88,8 +86,6 @@ protected function configureTimezone(ContainerBuilder $container, array $config) } /** - * Validate timezones. - * * @param array $timezones * * @throws \RuntimeException If one of the locales is invalid diff --git a/src/Helper/BaseHelper.php b/src/Helper/BaseHelper.php index 72ae36fa..e902afe3 100644 --- a/src/Helper/BaseHelper.php +++ b/src/Helper/BaseHelper.php @@ -29,32 +29,20 @@ */ abstract class BaseHelper implements LocaleAwareInterface { - protected string $charset = 'UTF-8'; + private string $charset = 'UTF-8'; - /** - * @var string|null - */ - protected $locale; + private ?string $locale = null; - /** - * @param string $charset The output charset of the helper - */ public function __construct(string $charset) { $this->setCharset($charset); } - /** - * Sets the default charset. - */ public function setCharset(string $charset): void { $this->charset = $charset; } - /** - * Gets the default charset. - */ public function getCharset(): string { return $this->charset; @@ -74,9 +62,6 @@ public function setLocale(string $locale): void $this->locale = $locale; } - /** - * @static - */ public static function getICUDataVersion(): string { if (\defined('INTL_ICU_VERSION')) { @@ -122,10 +107,6 @@ public static function getICUDataVersion(): string * charset of the kernel. * * Precondition: the kernel charset is not UTF-8 - * - * @param string $string The string to fix - * - * @return string A string with the %kernel.charset% encoding */ protected function fixCharset(string $string): string { diff --git a/src/Helper/DateTimeFormatter.php b/src/Helper/DateTimeFormatter.php index 60850035..6b79c460 100644 --- a/src/Helper/DateTimeFormatter.php +++ b/src/Helper/DateTimeFormatter.php @@ -36,8 +36,12 @@ public function __construct( parent::__construct($charset); } - public function formatDate($date, ?string $locale = null, ?string $timezone = null, ?int $dateType = null): string - { + public function formatDate( + \DateTimeInterface|string|int $date, + ?string $locale = null, + ?string $timezone = null, + ?int $dateType = null + ): string { $date = $this->getDatetime($date, $timezone); $formatter = self::createInstance([ @@ -51,8 +55,13 @@ public function formatDate($date, ?string $locale = null, ?string $timezone = nu return $this->process($formatter, $date); } - public function formatDateTime($datetime, ?string $locale = null, ?string $timezone = null, ?int $dateType = null, ?int $timeType = null): string - { + public function formatDateTime( + \DateTimeInterface|string|int $datetime, + ?string $locale = null, + ?string $timezone = null, + ?int $dateType = null, + ?int $timeType = null + ): string { $date = $this->getDatetime($datetime, $timezone); $formatter = self::createInstance([ @@ -66,8 +75,12 @@ public function formatDateTime($datetime, ?string $locale = null, ?string $timez return $this->process($formatter, $date); } - public function formatTime($time, ?string $locale = null, ?string $timezone = null, ?int $timeType = null): string - { + public function formatTime( + \DateTimeInterface|string|int $time, + ?string $locale = null, + ?string $timezone = null, + ?int $timeType = null + ): string { $date = $this->getDatetime($time, $timezone); $formatter = self::createInstance([ @@ -81,8 +94,12 @@ public function formatTime($time, ?string $locale = null, ?string $timezone = nu return $this->process($formatter, $date); } - public function format($datetime, string $pattern, ?string $locale = null, ?string $timezone = null): string - { + public function format( + \DateTimeInterface|string|int $datetime, + string $pattern, + ?string $locale = null, + ?string $timezone = null + ): string { $date = $this->getDatetime($datetime, $timezone); $formatter = self::createInstance([ @@ -97,8 +114,10 @@ public function format($datetime, string $pattern, ?string $locale = null, ?stri return $this->process($formatter, $date); } - public function getDatetime($data, ?string $timezone = null): \DateTimeInterface - { + public function getDatetime( + \DateTimeInterface|string|int $data, + ?string $timezone = null + ): \DateTimeInterface { if ($data instanceof \DateTimeInterface) { return $data; } @@ -124,10 +143,8 @@ public function getDatetime($data, ?string $timezone = null): \DateTimeInterface /** * @param mixed[] $args - * - * @return \IntlDateFormatter */ - protected static function createInstance(array $args = []) + private static function createInstance(array $args = []): \IntlDateFormatter { if (null === self::$reflection) { self::$reflection = new \ReflectionClass(\IntlDateFormatter::class); diff --git a/src/Helper/DateTimeFormatterInterface.php b/src/Helper/DateTimeFormatterInterface.php index 4c03ecd4..84c5fbda 100644 --- a/src/Helper/DateTimeFormatterInterface.php +++ b/src/Helper/DateTimeFormatterInterface.php @@ -23,34 +23,49 @@ interface DateTimeFormatterInterface { /** - * @param \DateTimeInterface|string|int $date - * @param int|null $dateType See \IntlDateFormatter::getDateType + * @param int|null $dateType See \IntlDateFormatter::getDateType */ - public function formatDate($date, ?string $locale = null, ?string $timezone = null, ?int $dateType = null): string; + public function formatDate( + \DateTimeInterface|string|int $date, + ?string $locale = null, + ?string $timezone = null, + ?int $dateType = null + ): string; /** - * @param \DateTimeInterface|string|int $datetime - * @param int|null $dateType See \IntlDateFormatter::getDateType - * @param int|null $timeType See \IntlDateFormatter::getTimeType + * @param int|null $dateType See \IntlDateFormatter::getDateType + * @param int|null $timeType See \IntlDateFormatter::getTimeType */ - public function formatDateTime($datetime, ?string $locale = null, ?string $timezone = null, ?int $dateType = null, ?int $timeType = null): string; + public function formatDateTime( + \DateTimeInterface|string|int $datetime, + ?string $locale = null, + ?string $timezone = null, + ?int $dateType = null, + ?int $timeType = null + ): string; /** - * @param \DateTimeInterface|string|int $time - * @param int|null $timeType See \IntlDateFormatter::getTimeType + * @param int|null $timeType See \IntlDateFormatter::getTimeType */ - public function formatTime($time, ?string $locale = null, ?string $timezone = null, ?int $timeType = null): string; + public function formatTime( + \DateTimeInterface|string|int $time, + ?string $locale = null, + ?string $timezone = null, + ?int $timeType = null + ): string; - /** - * @param \DateTimeInterface|string|int $datetime - */ - public function format($datetime, string $pattern, ?string $locale = null, ?string $timezone = null): string; + public function format( + \DateTimeInterface|string|int $datetime, + string $pattern, + ?string $locale = null, + ?string $timezone = null + ): string; /** * Gets a date time instance by a given data and timezone. - * - * @param \DateTimeInterface|string|int $data Value representing date - * @param string|null $timezone Timezone of the date */ - public function getDatetime($data, ?string $timezone = null): \DateTimeInterface; + public function getDatetime( + \DateTimeInterface|string|int $data, + ?string $timezone = null + ): \DateTimeInterface; } diff --git a/src/Helper/NumberFormatter.php b/src/Helper/NumberFormatter.php index ee5e5e37..054805de 100644 --- a/src/Helper/NumberFormatter.php +++ b/src/Helper/NumberFormatter.php @@ -36,27 +36,27 @@ public function __construct( parent::__construct($charset); } - public function formatPercent($number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string + public function formatPercent(string|float|int $number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string { return $this->format($number, \NumberFormatter::PERCENT, $attributes, $textAttributes, $symbols, $locale); } - public function formatDuration($number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string + public function formatDuration(string|float|int $number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string { return $this->format($number, \NumberFormatter::DURATION, $attributes, $textAttributes, $symbols, $locale); } - public function formatDecimal($number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string + public function formatDecimal(string|float|int $number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string { return $this->format($number, \NumberFormatter::DECIMAL, $attributes, $textAttributes, $symbols, $locale); } - public function formatSpellout($number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string + public function formatSpellout(string|float|int $number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string { return $this->format($number, \NumberFormatter::SPELLOUT, $attributes, $textAttributes, $symbols, $locale); } - public function formatCurrency($number, string $currency, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string + public function formatCurrency(string|float|int $number, string $currency, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string { $formatter = $this->getFormatter($locale ?? $this->getLocale(), \NumberFormatter::CURRENCY, $attributes, $textAttributes, $symbols); $number = $this->parseNumericValue($number); @@ -71,17 +71,17 @@ public function formatCurrency($number, string $currency, array $attributes = [] return $this->fixCharset($result); } - public function formatScientific($number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string + public function formatScientific(string|float|int $number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string { return $this->format($number, \NumberFormatter::SCIENTIFIC, $attributes, $textAttributes, $symbols, $locale); } - public function formatOrdinal($number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string + public function formatOrdinal(string|float|int $number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string { return $this->format($number, \NumberFormatter::ORDINAL, $attributes, $textAttributes, $symbols, $locale); } - public function format($number, int $style, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string + public function format(string|float|int $number, int $style, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string { $number = $this->parseNumericValue($number); $formatter = $this->getFormatter($locale ?? $this->getLocale(), $style, $attributes, $textAttributes, $symbols); @@ -104,7 +104,7 @@ public function format($number, int $style, array $attributes = [], array $textA * @param array $textAttributes The text attributes used by \NumberFormatter * @param array $symbols The symbols used by \NumberFormatter */ - protected function getFormatter(string $culture, int $style, array $attributes = [], array $textAttributes = [], array $symbols = []): \NumberFormatter + private function getFormatter(string $culture, int $style, array $attributes = [], array $textAttributes = [], array $symbols = []): \NumberFormatter { $attributes = $this->parseAttributes(array_merge($this->attributes, $attributes)); $textAttributes = $this->parseAttributes(array_merge($this->textAttributes, $textAttributes)); @@ -144,7 +144,7 @@ protected function getFormatter(string $culture, int $style, array $attributes = * @phpstan-param array $attributes * @phpstan-return array */ - protected function parseAttributes(array $attributes) + private function parseAttributes(array $attributes): array { $result = []; @@ -158,11 +158,9 @@ protected function parseAttributes(array $attributes) /** * Parse the given value trying to get a match with a \NumberFormatter constant. * - * @param string $attribute The constant's name - * * @throws \InvalidArgumentException If the value does not match any constant */ - protected function parseConstantValue(string $attribute): int + private function parseConstantValue(string $attribute): int { $attribute = strtoupper($attribute); $constantName = 'NumberFormatter::'.$attribute; diff --git a/src/Helper/NumberFormatterInterface.php b/src/Helper/NumberFormatterInterface.php index 23e51064..1228100d 100644 --- a/src/Helper/NumberFormatterInterface.php +++ b/src/Helper/NumberFormatterInterface.php @@ -33,7 +33,7 @@ interface NumberFormatterInterface * * @return string The formatted number */ - public function formatPercent($number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string; + public function formatPercent(string|float|int $number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string; /** * Formats a number as duration according to the specified locale and @@ -47,7 +47,7 @@ public function formatPercent($number, array $attributes = [], array $textAttrib * * @return string The formatted number */ - public function formatDuration($number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string; + public function formatDuration(string|float|int $number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string; /** * Formats a number as decimal according to the specified locale and @@ -61,7 +61,7 @@ public function formatDuration($number, array $attributes = [], array $textAttri * * @return string The formatted number */ - public function formatDecimal($number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string; + public function formatDecimal(string|float|int $number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string; /** * Formats a number as spellout according to the specified locale and @@ -75,7 +75,7 @@ public function formatDecimal($number, array $attributes = [], array $textAttrib * * @return string The formatted number */ - public function formatSpellout($number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string; + public function formatSpellout(string|float|int $number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string; /** * Formats a number as currency according to the specified locale and @@ -90,7 +90,7 @@ public function formatSpellout($number, array $attributes = [], array $textAttri * * @return string The formatted number */ - public function formatCurrency($number, string $currency, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string; + public function formatCurrency(string|float|int $number, string $currency, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string; /** * Formats a number in scientific notation according to the specified @@ -104,7 +104,7 @@ public function formatCurrency($number, string $currency, array $attributes = [] * * @return string The formatted number */ - public function formatScientific($number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string; + public function formatScientific(string|float|int $number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string; /** * Formats a number as ordinal according to the specified locale and @@ -118,7 +118,7 @@ public function formatScientific($number, array $attributes = [], array $textAtt * * @return string The formatted number */ - public function formatOrdinal($number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string; + public function formatOrdinal(string|float|int $number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string; /** * Formats a number according to the specified locale and \NumberFormatter @@ -131,5 +131,5 @@ public function formatOrdinal($number, array $attributes = [], array $textAttrib * @param array $symbols The symbols used by \NumberFormatter * @param string|null $locale The locale used to format the number */ - public function format($number, int $style, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string; + public function format(string|float|int $number, int $style, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string; } diff --git a/src/SonataIntlBundle.php b/src/SonataIntlBundle.php index d25e87f7..ac6c8627 100644 --- a/src/SonataIntlBundle.php +++ b/src/SonataIntlBundle.php @@ -16,18 +16,12 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; -class SonataIntlBundle extends Bundle +final class SonataIntlBundle extends Bundle { /** * Returns a cleaned version number. - * - * @static - * - * @param string $version - * - * @return string */ - public static function getSymfonyVersion($version) + public static function getSymfonyVersion(string $version): string { return implode('.', \array_slice(array_map( static fn ($val) => (int) $val, diff --git a/src/Timezone/ChainTimezoneDetector.php b/src/Timezone/ChainTimezoneDetector.php index 68d56d0d..fd372d11 100644 --- a/src/Timezone/ChainTimezoneDetector.php +++ b/src/Timezone/ChainTimezoneDetector.php @@ -18,22 +18,18 @@ * * @author Emmanuel Vella */ -class ChainTimezoneDetector implements TimezoneDetectorInterface +final class ChainTimezoneDetector implements TimezoneDetectorInterface { /** * @var TimezoneDetectorInterface[] */ - protected $timezoneDetectors = []; + private array $timezoneDetectors; - /** - * @var string|null - */ - protected $guessedTimezone = null; + private string $defaultTimezone; - /** - * @param string $defaultTimezone - */ - public function __construct(protected $defaultTimezone) + private ?string $guessedTimezone = null; + + public function __construct(string $defaultTimezone) { } @@ -42,7 +38,7 @@ public function addDetector(TimezoneDetectorInterface $timezoneDetector): void $this->timezoneDetectors[] = $timezoneDetector; } - public function getTimezone() + public function getTimezone(): string { if (null === $this->guessedTimezone) { $availableTimezones = \DateTimeZone::listIdentifiers(); diff --git a/src/Timezone/TimezoneAwareTrait.php b/src/Timezone/TimezoneAwareTrait.php index 41d8ab62..17305d12 100644 --- a/src/Timezone/TimezoneAwareTrait.php +++ b/src/Timezone/TimezoneAwareTrait.php @@ -20,10 +20,7 @@ */ trait TimezoneAwareTrait { - /** - * @var string|null - */ - private $timezone; + private ?string $timezone = null; final public function getTimezone(): ?string { diff --git a/src/Timezone/TimezoneDetectorInterface.php b/src/Timezone/TimezoneDetectorInterface.php index f2a0ee98..53a3f9fd 100644 --- a/src/Timezone/TimezoneDetectorInterface.php +++ b/src/Timezone/TimezoneDetectorInterface.php @@ -22,8 +22,6 @@ interface TimezoneDetectorInterface { /** * Get the appropriate timezone. - * - * @return string|null */ - public function getTimezone(); + public function getTimezone(): ?string; } diff --git a/src/Timezone/UserBasedTimezoneDetector.php b/src/Timezone/UserBasedTimezoneDetector.php index 870b03c8..ede15ba3 100644 --- a/src/Timezone/UserBasedTimezoneDetector.php +++ b/src/Timezone/UserBasedTimezoneDetector.php @@ -20,13 +20,15 @@ * * @author Emmanuel Vella */ -class UserBasedTimezoneDetector implements TimezoneDetectorInterface +final class UserBasedTimezoneDetector implements TimezoneDetectorInterface { - public function __construct(protected TokenStorageInterface $securityContext) + private TokenStorageInterface $securityContext; + + public function __construct(TokenStorageInterface $securityContext) { } - public function getTimezone() + public function getTimezone(): ?string { $token = $this->securityContext->getToken(); if (null === $token) { diff --git a/src/Twig/DateTimeRuntime.php b/src/Twig/DateTimeRuntime.php index fa8375f5..2cd3ee76 100644 --- a/src/Twig/DateTimeRuntime.php +++ b/src/Twig/DateTimeRuntime.php @@ -22,16 +22,13 @@ public function __construct(private DateTimeFormatterInterface $helper) { } - /** - * @param string|null $pattern - * @param string|null $locale - * @param string|null $timezone - * @param int|null $dateType - * - * @return string - */ - public function formatDate(\DateTime|string|int $date, $pattern = null, $locale = null, $timezone = null, $dateType = null) - { + public function formatDate( + \DateTimeInterface|string|int $date, + ?string $pattern = null, + ?string $locale = null, + ?string $timezone = null, + ?int $dateType = null + ): string { if (null !== $pattern) { return $this->helper->format($date, $pattern, $locale, $timezone); } @@ -39,16 +36,13 @@ public function formatDate(\DateTime|string|int $date, $pattern = null, $locale return $this->helper->formatDate($date, $locale, $timezone, $dateType); } - /** - * @param string|null $pattern - * @param string|null $locale - * @param string|null $timezone - * @param int|null $timeType - * - * @return string - */ - public function formatTime(\DateTime|string|int $time, $pattern = null, $locale = null, $timezone = null, $timeType = null) - { + public function formatTime( + \DateTimeInterface|string|int $time, + ?string $pattern = null, + ?string $locale = null, + ?string $timezone = null, + ?int $timeType = null + ): string { if (null !== $pattern) { return $this->helper->format($time, $pattern, $locale, $timezone); } @@ -56,17 +50,14 @@ public function formatTime(\DateTime|string|int $time, $pattern = null, $locale return $this->helper->formatTime($time, $locale, $timezone, $timeType); } - /** - * @param string|null $pattern - * @param string|null $locale - * @param string|null $timezone - * @param int|null $dateType - * @param int|null $timeType - * - * @return string - */ - public function formatDatetime(\DateTime|string|int $time, $pattern = null, $locale = null, $timezone = null, $dateType = null, $timeType = null) - { + public function formatDatetime( + \DateTimeInterface|string|int $time, + ?string $pattern = null, + ?string $locale = null, + ?string $timezone = null, + ?int $dateType = null, + ?int $timeType = null + ): string { if (null !== $pattern) { return $this->helper->format($time, $pattern, $locale, $timezone); } diff --git a/src/Twig/Extension/DateTimeExtension.php b/src/Twig/Extension/DateTimeExtension.php index 7b23a4d6..2644ee7c 100644 --- a/src/Twig/Extension/DateTimeExtension.php +++ b/src/Twig/Extension/DateTimeExtension.php @@ -22,12 +22,12 @@ * * @author Thomas Rabaix */ -class DateTimeExtension extends AbstractExtension +final class DateTimeExtension extends AbstractExtension { /** * @return TwigFilter[] */ - public function getFilters() + public function getFilters(): array { return [ new TwigFilter('sonata_format_date', [DateTimeRuntime::class, 'formatDate'], ['is_safe' => ['html']]), diff --git a/src/Twig/Extension/LocaleExtension.php b/src/Twig/Extension/LocaleExtension.php index 038cd52a..cb295c4a 100644 --- a/src/Twig/Extension/LocaleExtension.php +++ b/src/Twig/Extension/LocaleExtension.php @@ -22,12 +22,12 @@ * * @author Thomas Rabaix */ -class LocaleExtension extends AbstractExtension +final class LocaleExtension extends AbstractExtension { /** * @return TwigFilter[] */ - public function getFilters() + public function getFilters(): array { return [ new TwigFilter('sonata_country', [LocaleRuntime::class, 'country'], ['is_safe' => ['html']]), diff --git a/src/Twig/Extension/NumberExtension.php b/src/Twig/Extension/NumberExtension.php index edb0ceb4..3241d155 100644 --- a/src/Twig/Extension/NumberExtension.php +++ b/src/Twig/Extension/NumberExtension.php @@ -24,12 +24,12 @@ * @author Thomas Rabaix * @author Stefano Arlandini */ -class NumberExtension extends AbstractExtension +final class NumberExtension extends AbstractExtension { /** * @return TwigFilter[] */ - public function getFilters() + public function getFilters(): array { return [ new TwigFilter('sonata_number_format_currency', [NumberRuntime::class, 'formatCurrency'], ['is_safe' => ['html']]), diff --git a/src/Twig/LocaleRuntime.php b/src/Twig/LocaleRuntime.php index 870136df..8b565910 100644 --- a/src/Twig/LocaleRuntime.php +++ b/src/Twig/LocaleRuntime.php @@ -24,39 +24,24 @@ public function __construct(private LocalizerInterface $helper) /** * Returns the localized country name from the provided code. - * - * @param string $code - * @param string|null $locale - * - * @return string */ - public function country($code, $locale = null) + public function country(string $code, ?string $locale = null): string { return $this->helper->country($code, $locale); } /** * Returns the localized locale name from the provided code. - * - * @param string $code - * @param string|null $locale - * - * @return string */ - public function locale($code, $locale = null) + public function locale(string $code, ?string $locale = null): string { return $this->helper->locale($code, $locale); } /** * Returns the localized language name from the provided code. - * - * @param string $code - * @param string|null $locale - * - * @return string */ - public function language($code, $locale = null) + public function language(string $code, ?string $locale = null): string { return $this->helper->language($code, $locale); } diff --git a/src/Twig/NumberRuntime.php b/src/Twig/NumberRuntime.php index 115bf4a8..e3cb5e01 100644 --- a/src/Twig/NumberRuntime.php +++ b/src/Twig/NumberRuntime.php @@ -34,8 +34,14 @@ public function __construct(private NumberFormatterInterface $helper) * * @return string The formatted number */ - public function formatCurrency(string|float|int $number, string $currency, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string - { + public function formatCurrency( + string|float|int $number, + string $currency, + array $attributes = [], + array $textAttributes = [], + array $symbols = [], + ?string $locale = null + ): string { return $this->helper->formatCurrency($number, $currency, $attributes, $textAttributes, $symbols, $locale); } @@ -50,8 +56,13 @@ public function formatCurrency(string|float|int $number, string $currency, array * * @return string The formatted number */ - public function formatDecimal(string|float|int $number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string - { + public function formatDecimal( + string|float|int $number, + array $attributes = [], + array $textAttributes = [], + array $symbols = [], + ?string $locale = null + ): string { return $this->helper->formatDecimal($number, $attributes, $textAttributes, $symbols, $locale); } @@ -66,8 +77,13 @@ public function formatDecimal(string|float|int $number, array $attributes = [], * * @return string The formatted number */ - public function formatScientific(string|float|int $number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string - { + public function formatScientific( + string|float|int $number, + array $attributes = [], + array $textAttributes = [], + array $symbols = [], + ?string $locale = null + ): string { return $this->helper->formatScientific($number, $attributes, $textAttributes, $symbols, $locale); } @@ -82,8 +98,13 @@ public function formatScientific(string|float|int $number, array $attributes = [ * * @return string The formatted number */ - public function formatSpellout(string|float|int $number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string - { + public function formatSpellout( + string|float|int $number, + array $attributes = [], + array $textAttributes = [], + array $symbols = [], + ?string $locale = null + ): string { return $this->helper->formatSpellout($number, $attributes, $textAttributes, $symbols, $locale); } @@ -98,8 +119,13 @@ public function formatSpellout(string|float|int $number, array $attributes = [], * * @return string The formatted number */ - public function formatPercent(string|float|int $number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string - { + public function formatPercent( + string|float|int $number, + array $attributes = [], + array $textAttributes = [], + array $symbols = [], + ?string $locale = null + ): string { return $this->helper->formatPercent($number, $attributes, $textAttributes, $symbols, $locale); } @@ -114,8 +140,13 @@ public function formatPercent(string|float|int $number, array $attributes = [], * * @return string The formatted number */ - public function formatDuration(string|float|int $number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string - { + public function formatDuration( + string|float|int $number, + array $attributes = [], + array $textAttributes = [], + array $symbols = [], + ?string $locale = null + ): string { return $this->helper->formatDuration($number, $attributes, $textAttributes, $symbols, $locale); } @@ -130,8 +161,13 @@ public function formatDuration(string|float|int $number, array $attributes = [], * * @return string The formatted number */ - public function formatOrdinal(string|float|int $number, array $attributes = [], array $textAttributes = [], array $symbols = [], ?string $locale = null): string - { + public function formatOrdinal( + string|float|int $number, + array $attributes = [], + array $textAttributes = [], + array $symbols = [], + ?string $locale = null + ): string { return $this->helper->formatOrdinal($number, $attributes, $textAttributes, $symbols, $locale); } }