Skip to content

Commit

Permalink
Update the meritoo/common-library package to ^1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
meritoo committed Nov 15, 2024
1 parent f60b628 commit 4de5b66
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 46 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 14 additions & 8 deletions src/DependencyInjection/Base/BaseExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Exception/Type/Date/UnknownDateLengthException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
27 changes: 15 additions & 12 deletions src/Service/DateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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
Expand All @@ -78,20 +79,21 @@ 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
*/
public function formatDateUsingLocale(
int $dateType,
int $timeType,
string $locale,
DateTimeInterface $dateTime
DateTimeInterface $dateTime,
): string {
$timestamp = $dateTime->getTimestamp();

Expand All @@ -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);
}

Expand Down
5 changes: 3 additions & 2 deletions src/Type/DependencyInjection/ConfigurationFileType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
14 changes: 7 additions & 7 deletions tests/Type/Date/DateLengthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}
Expand Down
21 changes: 11 additions & 10 deletions tests/Type/DependencyInjection/ConfigurationFileTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 4de5b66

Please sign in to comment.