From 4de5b66f0c07fa609e8f45156417f09d206afa11 Mon Sep 17 00:00:00 2001 From: Meritoo Date: Fri, 15 Nov 2024 22:29:04 +0100 Subject: [PATCH] Update the meritoo/common-library package to ^1.3 --- CHANGELOG.md | 1 + composer.json | 2 +- .../Base/BaseExtension.php | 22 +++++++++------ .../Type/Date/UnknownDateLengthException.php | 6 ++--- .../UnknownConfigurationFileTypeException.php | 10 ++++--- src/Service/DateService.php | 27 ++++++++++--------- .../ConfigurationFileType.php | 5 ++-- tests/Type/Date/DateLengthTest.php | 14 +++++----- .../ConfigurationFileTypeTest.php | 21 ++++++++------- 9 files changed, 62 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a94410..2e4aa27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Common & useful classes, resources, extensions. Based on Symfony framework. 1. Support Symfony `5.4` 2. Pluralization in translations [using the ICU MessageFormat](https://symfony.com/doc/current/reference/formats/message_format.html#pluralization) +3. Update the `meritoo/common-library` package to `^1.3` # 0.3.1 diff --git a/composer.json b/composer.json index 29121f1..57900c9 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "php": "^8.0", "ext-intl": "*", "doctrine/annotations": "^2.0", - "meritoo/common-library": "dev-develop", + "meritoo/common-library": "^1.3", "symfony/form": "^5.4", "symfony/framework-bundle": "^5.4", "symfony/twig-bundle": "^5.4", diff --git a/src/DependencyInjection/Base/BaseExtension.php b/src/DependencyInjection/Base/BaseExtension.php index 237ba98..f6f4bd0 100644 --- a/src/DependencyInjection/Base/BaseExtension.php +++ b/src/DependencyInjection/Base/BaseExtension.php @@ -142,6 +142,7 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container * If the file name does not contain extension, default extension will be used (the ".yaml" extension). * * @param string $fileName Name of configuration file (with or without extension) + * * @return string */ private function getConfigurationFileWithExtension(string $fileName): string @@ -160,8 +161,9 @@ private function getConfigurationFileWithExtension(string $fileName): string * Returns loader of configuration file * * @param ContainerBuilder $container Container for the Dependency Injection (DI) - * @param FileLocator $locator Locator used to find files - * @param string $fileType Type of configuration file + * @param FileLocator $locator Locator used to find files + * @param string $fileType Type of configuration file + * * @return null|FileLoader */ private function getFileLoader(ContainerBuilder $container, FileLocator $locator, string $fileType): ?FileLoader @@ -220,8 +222,9 @@ private function getGlobalKeysToStopLoadingParametersOn(): array * Loads the configuration file * * @param ContainerBuilder $container Container for the Dependency Injection (DI) - * @param string $fileName Name of configuration file. If provided without extension, the default - * extension of configuration files will be used. + * @param string $fileName Name of configuration file. If provided without extension, the default extension of + * configuration files will be used. + * * @return void */ private function loadConfigurationFile(ContainerBuilder $container, string $fileName): void @@ -248,7 +251,7 @@ private function loadConfigurationFile(ContainerBuilder $container, string $file return; } - $fileType = ConfigurationFileType::getTypeFromFileName($fileName); + $fileType = (new ConfigurationFileType())->getTypeFromFileName($fileName); $locator = new FileLocator($resourcesPath); // Let's load the configuration file @@ -262,8 +265,9 @@ private function loadConfigurationFile(ContainerBuilder $container, string $file /** * Loads parameters into container * - * @param array $mergedConfig Custom configuration merged with defaults - * @param ContainerBuilder $container Container for the Dependency Injection (DI) + * @param array $mergedConfig Custom configuration merged with defaults + * @param ContainerBuilder $container Container for the Dependency Injection (DI) + * * @return BaseExtension */ private function loadParameters(array $mergedConfig, ContainerBuilder $container): BaseExtension @@ -306,6 +310,7 @@ private function loadParameters(array $mergedConfig, ContainerBuilder $container * Loads services from configuration file (located in bundle's resources) * * @param ContainerBuilder $container Container for the Dependency Injection (DI) + * * @return void */ private function loadServices(ContainerBuilder $container): void @@ -321,6 +326,7 @@ private function loadServices(ContainerBuilder $container): void * Returns an array with key-value pairs, where key - name of parameter, value - value of parameter. * * @param array $mergedConfig Custom configuration merged with defaults + * * @return null|array */ private function makeFlatConfig(array $mergedConfig): ?array @@ -332,7 +338,7 @@ private function makeFlatConfig(array $mergedConfig): ?array // Merging standard with global keys and paths $stopIfMatchedBy = array_merge( Arrays::makeArray($keysToStop), - Arrays::makeArray($globalKeysToStop) + Arrays::makeArray($globalKeysToStop), ); // Let's get the last elements' paths and load values into container diff --git a/src/Exception/Type/Date/UnknownDateLengthException.php b/src/Exception/Type/Date/UnknownDateLengthException.php index 0638ae9..dfa2765 100644 --- a/src/Exception/Type/Date/UnknownDateLengthException.php +++ b/src/Exception/Type/Date/UnknownDateLengthException.php @@ -25,13 +25,13 @@ class UnknownDateLengthException extends UnknownTypeException * Creates exception * * @param string $unknownType Unknown type of date length for date format + * * @return UnknownDateLengthException */ public static function createException(string $unknownType): UnknownDateLengthException { - /** @var UnknownDateLengthException $exception */ - $exception = static::create($unknownType, new DateLength(), 'date length for date format'); + $message = static::createMessage($unknownType, new DateLength(), 'date length for date format'); - return $exception; + return new self($message); } } diff --git a/src/Exception/Type/DependencyInjection/UnknownConfigurationFileTypeException.php b/src/Exception/Type/DependencyInjection/UnknownConfigurationFileTypeException.php index 1499b20..f01a2da 100644 --- a/src/Exception/Type/DependencyInjection/UnknownConfigurationFileTypeException.php +++ b/src/Exception/Type/DependencyInjection/UnknownConfigurationFileTypeException.php @@ -25,13 +25,17 @@ class UnknownConfigurationFileTypeException extends UnknownTypeException * Creates exception * * @param string $unknownType Unknown type of Dependency Injection (DI) configuration file + * * @return UnknownConfigurationFileTypeException */ public static function createException(string $unknownType): UnknownConfigurationFileTypeException { - /** @var UnknownConfigurationFileTypeException $exception */ - $exception = static::create($unknownType, new ConfigurationFileType(), 'Dependency Injection (DI) configuration file'); + $message = static::createMessage( + $unknownType, + new ConfigurationFileType(), + 'Dependency Injection (DI) configuration file', + ); - return $exception; + return new self($message); } } diff --git a/src/Service/DateService.php b/src/Service/DateService.php index d0ae8be..633a475 100644 --- a/src/Service/DateService.php +++ b/src/Service/DateService.php @@ -49,9 +49,9 @@ class DateService extends BaseService /** * Class constructor * - * @param string $dateFormat Format of date without time + * @param string $dateFormat Format of date without time * @param string $dateTimeFormat Format of date with time - * @param string $timeFormat Format of time without date + * @param string $timeFormat Format of time without date */ public function __construct(string $dateFormat, string $dateTimeFormat, string $timeFormat) { @@ -63,8 +63,9 @@ public function __construct(string $dateFormat, string $dateTimeFormat, string $ /** * Returns date formatted according to given length of date * - * @param DateTimeInterface $dateTime The date to format - * @param string $dateLength Type of date length. One of the DateLength's class constants. + * @param DateTimeInterface $dateTime The date to format + * @param string $dateLength Type of date length. One of the DateLength's class constants. + * * @return string */ public function formatDate(DateTimeInterface $dateTime, string $dateLength): string @@ -78,12 +79,13 @@ public function formatDate(DateTimeInterface $dateTime, string $dateLength): str * Returns given date formatted with format based on locale. * Uses the \IntlDateFormatter class to set proper type / length of date and time part in the returned string. * - * @param int $dateType Type/length of date part in the returned string. One of constants of the - * \IntlDateFormatter class, e.g. \IntlDateFormatter::SHORT. - * @param int $timeType Type/length of time part in the returned string. One of constants of the - * \IntlDateFormatter class, e.g. \IntlDateFormatter::MEDIUM. - * @param string $locale Locale used to format given date - * @param DateTimeInterface $dateTime The date to format + * @param int $dateType Type/length of date part in the returned string. One of constants of the + * \IntlDateFormatter class, e.g. \IntlDateFormatter::SHORT. + * @param int $timeType Type/length of time part in the returned string. One of constants of the + * \IntlDateFormatter class, e.g. \IntlDateFormatter::MEDIUM. + * @param string $locale Locale used to format given date + * @param DateTimeInterface $dateTime The date to format + * * @return string * @throws Exception */ @@ -91,7 +93,7 @@ public function formatDateUsingLocale( int $dateType, int $timeType, string $locale, - DateTimeInterface $dateTime + DateTimeInterface $dateTime, ): string { $timestamp = $dateTime->getTimestamp(); @@ -102,13 +104,14 @@ public function formatDateUsingLocale( * Returns format of date according to given length of date * * @param string $dateLength Type of date length. One of the DateLength's class constants. + * * @throws UnknownDateLengthException * @return string */ public function getFormat(string $dateLength): string { // Oops, unknown length of date - if (false === DateLength::isCorrectType($dateLength)) { + if (false === (new DateLength())->isCorrectType($dateLength)) { throw UnknownDateLengthException::createException($dateLength); } diff --git a/src/Type/DependencyInjection/ConfigurationFileType.php b/src/Type/DependencyInjection/ConfigurationFileType.php index 9d50d40..10e6eae 100644 --- a/src/Type/DependencyInjection/ConfigurationFileType.php +++ b/src/Type/DependencyInjection/ConfigurationFileType.php @@ -47,15 +47,16 @@ class ConfigurationFileType extends BaseType * Returns type of configuration file based on name of the file * * @param string $fileName Name of configuration file + * * @return string * @throws UnknownConfigurationFileTypeException */ - public static function getTypeFromFileName(string $fileName): string + public function getTypeFromFileName(string $fileName): string { $fileExtension = strtolower(Miscellaneous::getFileExtension($fileName)); // Oops, incorrect type/extension of configuration file - if (false === static::isCorrectType($fileExtension)) { + if (false === $this->isCorrectType($fileExtension)) { throw UnknownConfigurationFileTypeException::createException($fileExtension); } diff --git a/tests/Type/Date/DateLengthTest.php b/tests/Type/Date/DateLengthTest.php index 57c2d58..c1d4de4 100644 --- a/tests/Type/Date/DateLengthTest.php +++ b/tests/Type/Date/DateLengthTest.php @@ -32,37 +32,37 @@ class DateLengthTest extends BaseTypeTestCase public function provideTypeToVerify(): Generator { yield [ - DateLength::isCorrectType(''), + (new DateLength())->isCorrectType(''), false, ]; yield [ - DateLength::isCorrectType(null), + (new DateLength())->isCorrectType(null), false, ]; yield [ - DateLength::isCorrectType('0'), + (new DateLength())->isCorrectType('0'), false, ]; yield [ - DateLength::isCorrectType('1'), + (new DateLength())->isCorrectType('1'), false, ]; yield [ - DateLength::isCorrectType('date'), + (new DateLength())->isCorrectType('date'), true, ]; yield [ - DateLength::isCorrectType('datetime'), + (new DateLength())->isCorrectType('datetime'), true, ]; yield [ - DateLength::isCorrectType('time'), + (new DateLength())->isCorrectType('time'), true, ]; } diff --git a/tests/Type/DependencyInjection/ConfigurationFileTypeTest.php b/tests/Type/DependencyInjection/ConfigurationFileTypeTest.php index c1cd6e4..c800408 100644 --- a/tests/Type/DependencyInjection/ConfigurationFileTypeTest.php +++ b/tests/Type/DependencyInjection/ConfigurationFileTypeTest.php @@ -84,42 +84,42 @@ public function provideFileNameWithUnknownExtension(): Generator public function provideTypeToVerify(): Generator { yield [ - ConfigurationFileType::isCorrectType(''), + (new ConfigurationFileType())->isCorrectType(''), false, ]; yield [ - ConfigurationFileType::isCorrectType(null), + (new ConfigurationFileType())->isCorrectType(null), false, ]; yield [ - ConfigurationFileType::isCorrectType('0'), + (new ConfigurationFileType())->isCorrectType('0'), false, ]; yield [ - ConfigurationFileType::isCorrectType('1'), + (new ConfigurationFileType())->isCorrectType('1'), false, ]; yield [ - ConfigurationFileType::isCorrectType('jpg'), + (new ConfigurationFileType())->isCorrectType('jpg'), false, ]; yield [ - ConfigurationFileType::isCorrectType('php'), + (new ConfigurationFileType())->isCorrectType('php'), true, ]; yield [ - ConfigurationFileType::isCorrectType('xml'), + (new ConfigurationFileType())->isCorrectType('xml'), true, ]; yield [ - ConfigurationFileType::isCorrectType('yaml'), + (new ConfigurationFileType())->isCorrectType('yaml'), true, ]; } @@ -132,17 +132,18 @@ public function provideTypeToVerify(): Generator */ public function testGetTypeFromFileName(string $fileName, string $expected): void { - static::assertSame($expected, ConfigurationFileType::getTypeFromFileName($fileName)); + static::assertSame($expected, (new ConfigurationFileType())->getTypeFromFileName($fileName)); } /** * @param string $fileName Name of configuration file + * * @dataProvider provideFileNameWithUnknownExtension */ public function testGetTypeFromFileNameWithUnknownExtension(string $fileName): void { $this->expectException(UnknownConfigurationFileTypeException::class); - ConfigurationFileType::getTypeFromFileName($fileName); + (new ConfigurationFileType())->getTypeFromFileName($fileName); } /**