mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-15 17:40:58 +00:00
Narrowing return types (#18009)
| Q | A |-----------------|----- | Branch? | 2.1 <!-- see the comment below --> | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | #17963 | License | MIT Removing types that are impossible to reach from the return type or the documentation. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved consistency in return values for locale and payment-related methods, ensuring they always return the expected data type and never null where previously possible. - **Refactor** - Updated method signatures to provide stricter and more predictable return types for locale conversion, payment provision, and data transformation logic. - **Chores** - Adjusted static analysis configuration to report unused return type issues, enhancing code quality checks. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
commit
e1b9c654fe
5 changed files with 4 additions and 7 deletions
|
|
@ -38,7 +38,6 @@ parameters:
|
|||
ignoreErrors:
|
||||
- identifier: missingType.generics # This need to be fixed, too many classes are using generics without PHPDoc type
|
||||
- identifier: varTag.nativeType
|
||||
- identifier: return.unusedType
|
||||
- '/(Interface|Class) [a-zA-Z\\]+ specifies template type (\w+) of interface [a-zA-Z\\]+ as [a-zA-Z\\]+ (of [a-zA-Z\\]+ )?but it''s already specified as/' # turns off a weird generics check behavior, we are basing on Psalm for generics checks - '/Method Sylius\\Component\\(\w+)\\Model\\(\w+)\:\:getId\(\) has no return type specified./'
|
||||
- '/Method Sylius\\Bundle\\(Admin|Shop)Bundle\\Twig\\Component\\[a-zA-Z\\]+\:\:getDataModelValue\(\) is unused./'
|
||||
- '/Method Sylius\\Component\\(\w+)\\Model\\(\w+)\:\:getId\(\) has no return type specified./'
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ final class LocaleExtension extends AbstractExtension
|
|||
];
|
||||
}
|
||||
|
||||
public function convertCodeToName(string $code, ?string $localeCode = null): ?string
|
||||
public function convertCodeToName(string $code, ?string $localeCode = null): string
|
||||
{
|
||||
try {
|
||||
return $this->localeConverter->convertCodeToName($code, $this->getLocaleCode($localeCode));
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use Symfony\Component\Form\Extension\Core\DataTransformer\MoneyToLocalizedString
|
|||
|
||||
final class MoneyIntToLocalizedStringTransformer extends MoneyToLocalizedStringTransformer
|
||||
{
|
||||
public function reverseTransform(mixed $value): float|int|null
|
||||
public function reverseTransform(mixed $value): ?int
|
||||
{
|
||||
if (!is_numeric($value)) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -23,12 +23,10 @@ final class PercentFloatToLocalizedStringTransformer extends PercentToLocalizedS
|
|||
*
|
||||
* @param string $value Percentage value
|
||||
*
|
||||
* @return float Normalized value
|
||||
*
|
||||
* @throws TransformationFailedException if the given value is not a string or
|
||||
* if the value could not be transformed
|
||||
*/
|
||||
public function reverseTransform(mixed $value): float|int|null
|
||||
public function reverseTransform(mixed $value): ?float
|
||||
{
|
||||
if (!is_numeric($value)) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ final class OrderPaymentProvider implements OrderPaymentProviderInterface
|
|||
) {
|
||||
}
|
||||
|
||||
public function provideOrderPayment(OrderInterface $order, string $targetState): ?PaymentInterface
|
||||
public function provideOrderPayment(OrderInterface $order, string $targetState): PaymentInterface
|
||||
{
|
||||
/** @var PaymentInterface $payment */
|
||||
$payment = $this->paymentFactory->createWithAmountAndCurrencyCode(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue