Skip to content

Commit 33f7d39

Browse files
committed
Merge branch '1.x' into 2.x
2 parents e880c6d + 2523a51 commit 33f7d39

26 files changed

+239
-92
lines changed

.github/workflows/static-analysis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ jobs:
1515
- name: Setup PHP
1616
uses: shivammathur/setup-php@v2
1717
with:
18-
php-version: '8.3'
18+
php-version: '8.4'
1919
tools: composer:v2,flex
2020
extensions: curl, iconv, mbstring, mongodb, pdo, pdo_sqlite, sqlite, zip
2121
coverage: none
2222

2323
- name: Install dependencies
2424
run: composer update --prefer-stable --prefer-dist
2525
env:
26-
SYMFONY_REQUIRE: '7.2.*@rc'
26+
SYMFONY_REQUIRE: '7.2.*'
2727

2828
- name: Run PHPStan
2929
run: vendor/bin/phpstan analyze --error-format=github

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
"jms/serializer-bundle": "^5.4",
2121
"matthiasnoback/symfony-dependency-injection-test": "^5.0",
2222
"phpstan/extension-installer": "^1.4",
23-
"phpstan/phpstan": "1.12.10",
24-
"phpstan/phpstan-phpunit": "1.4.1",
25-
"phpstan/phpstan-symfony": "1.4.12",
26-
"phpunit/phpunit": "9.6.21",
23+
"phpstan/phpstan": "2.1.14",
24+
"phpstan/phpstan-phpunit": "2.0.6",
25+
"phpstan/phpstan-symfony": "2.0.4",
26+
"phpunit/phpunit": "9.6.23",
2727
"symfony/form": "^6.4 || ^7.2",
2828
"symfony/intl": "^6.4 || ^7.2",
2929
"symfony/phpunit-bridge": "^6.4 || ^7.2",

phpstan-baseline.neon

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,104 @@
11
parameters:
22
ignoreErrors:
33
-
4-
message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:children\\(\\)\\.$#"
4+
message: '#^Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition\:\:children\(\)\.$#'
5+
identifier: method.notFound
56
count: 1
67
path: src/BabDevMoneyBundle.php
78

89
-
9-
message: "#^Cannot cast mixed to int\\.$#"
10+
message: '#^Cannot call method defaultValue\(\) on mixed\.$#'
11+
identifier: method.nonObject
12+
count: 1
13+
path: src/BabDevMoneyBundle.php
14+
15+
-
16+
message: '#^Cannot call method end\(\) on mixed\.$#'
17+
identifier: method.nonObject
18+
count: 2
19+
path: src/BabDevMoneyBundle.php
20+
21+
-
22+
message: '#^Cannot call method scalarNode\(\) on mixed\.$#'
23+
identifier: method.nonObject
24+
count: 1
25+
path: src/BabDevMoneyBundle.php
26+
27+
-
28+
message: '#^Cannot cast mixed to int\.$#'
29+
identifier: cast.int
1030
count: 3
1131
path: src/Factory/FormatterFactory.php
1232

1333
-
14-
message: "#^Cannot cast mixed to int\\.$#"
34+
message: '#^Cannot cast mixed to int\.$#'
35+
identifier: cast.int
1536
count: 3
1637
path: src/Factory/ParserFactory.php
1738

1839
-
19-
message: "#^Parameter \\#1 \\$currency of static method BabDev\\\\MoneyBundle\\\\Form\\\\Type\\\\MoneyType\\:\\:getPattern\\(\\) expects Money\\\\Currency, mixed given\\.$#"
20-
count: 1
21-
path: src/Form/Type/MoneyType.php
22-
23-
-
24-
message: "#^Parameter \\#1 \\$scale of class Symfony\\\\Component\\\\Form\\\\Extension\\\\Core\\\\DataTransformer\\\\NumberToLocalizedStringTransformer constructor expects int\\|null, mixed given\\.$#"
40+
message: '#^Parameter \#1 \$scale of class Symfony\\Component\\Form\\Extension\\Core\\DataTransformer\\NumberToLocalizedStringTransformer constructor expects int\|null, mixed given\.$#'
41+
identifier: argument.type
2542
count: 1
2643
path: src/Form/Type/MoneyType.php
2744

2845
-
29-
message: "#^Parameter \\#2 \\$grouping of class Symfony\\\\Component\\\\Form\\\\Extension\\\\Core\\\\DataTransformer\\\\NumberToLocalizedStringTransformer constructor expects bool\\|null, mixed given\\.$#"
46+
message: '#^Parameter \#2 \$grouping of class Symfony\\Component\\Form\\Extension\\Core\\DataTransformer\\NumberToLocalizedStringTransformer constructor expects bool\|null, mixed given\.$#'
47+
identifier: argument.type
3048
count: 1
3149
path: src/Form/Type/MoneyType.php
3250

3351
-
34-
message: "#^Parameter \\#3 \\$currency of class BabDev\\\\MoneyBundle\\\\Form\\\\DataTransformer\\\\MoneyToLocalizedStringTransformer constructor expects Money\\\\Currency, mixed given\\.$#"
52+
message: '#^Parameter \#3 \$currency of class BabDev\\MoneyBundle\\Form\\DataTransformer\\MoneyToLocalizedStringTransformer constructor expects Money\\Currency, mixed given\.$#'
53+
identifier: argument.type
3554
count: 1
3655
path: src/Form/Type/MoneyType.php
3756

3857
-
39-
message: "#^Parameter \\#3 \\$roundingMode of class Symfony\\\\Component\\\\Form\\\\Extension\\\\Core\\\\DataTransformer\\\\NumberToLocalizedStringTransformer constructor expects int\\|null, mixed given\\.$#"
58+
message: '#^Parameter \#3 \$roundingMode of class Symfony\\Component\\Form\\Extension\\Core\\DataTransformer\\NumberToLocalizedStringTransformer constructor expects int\|null, mixed given\.$#'
59+
identifier: argument.type
4060
count: 1
4161
path: src/Form/Type/MoneyType.php
4262

4363
-
44-
message: "#^Parameter \\#1 \\$message of method Symfony\\\\Component\\\\Validator\\\\Context\\\\ExecutionContextInterface\\:\\:buildViolation\\(\\) expects string, string\\|null given\\.$#"
64+
message: '#^Parameter \#1 \$message of method Symfony\\Component\\Validator\\Context\\ExecutionContextInterface\:\:buildViolation\(\) expects string, string\|null given\.$#'
65+
identifier: argument.type
4566
count: 1
4667
path: src/Validator/Constraints/AbstractMoneyComparisonValidator.php
4768

4869
-
49-
message: "#^Parameter \\#2 \\$value of method BabDev\\\\MoneyBundle\\\\Validator\\\\Constraints\\\\AbstractMoneyComparisonValidator\\:\\:ensureMoneyObject\\(\\) expects float\\|int\\|Money\\\\Money\\|numeric\\-string\\|null, mixed given\\.$#"
70+
message: '#^Parameter \#2 \$value of method BabDev\\MoneyBundle\\Validator\\Constraints\\AbstractMoneyComparisonValidator\:\:ensureMoneyObject\(\) expects float\|int\|Money\\Money\|numeric\-string\|null, mixed given\.$#'
71+
identifier: argument.type
5072
count: 2
5173
path: src/Validator/Constraints/AbstractMoneyComparisonValidator.php
5274

5375
-
54-
message: "#^Parameter \\#1 \\$format of method BabDev\\\\MoneyBundle\\\\Factory\\\\FormatterFactory\\:\\:createFormatter\\(\\) expects 'aggregate'\\|'bitcoin'\\|'decimal'\\|'intl_localized…'\\|'intl_money', 'unsupported' given\\.$#"
76+
message: '#^Parameter \#1 \$format of method BabDev\\MoneyBundle\\Factory\\FormatterFactory\:\:createFormatter\(\) expects ''aggregate''\|''bitcoin''\|''decimal''\|''intl_localized…''\|''intl_money'', ''unsupported'' given\.$#'
77+
identifier: argument.type
5578
count: 1
5679
path: tests/Factory/FormatterFactoryTest.php
5780

5881
-
59-
message: "#^Parameter \\#1 \\$format of method BabDev\\\\MoneyBundle\\\\Factory\\\\ParserFactory\\:\\:createParser\\(\\) expects 'aggregate'\\|'bitcoin'\\|'decimal'\\|'intl_localized…'\\|'intl_money', 'unsupported' given\\.$#"
82+
message: '#^Parameter \#1 \$format of method BabDev\\MoneyBundle\\Factory\\ParserFactory\:\:createParser\(\) expects ''aggregate''\|''bitcoin''\|''decimal''\|''intl_localized…''\|''intl_money'', ''unsupported'' given\.$#'
83+
identifier: argument.type
6084
count: 1
6185
path: tests/Factory/ParserFactoryTest.php
6286

6387
-
64-
message: "#^Parameter \\#1 \\$value of method BabDev\\\\MoneyBundle\\\\Form\\\\DataTransformer\\\\MoneyToLocalizedStringTransformer\\<Money\\\\Money,string\\>\\:\\:reverseTransform\\(\\) expects string, int given\\.$#"
88+
message: '#^Parameter \#1 \$value of method BabDev\\MoneyBundle\\Form\\DataTransformer\\MoneyToLocalizedStringTransformer\<Money\\Money,string\>\:\:reverseTransform\(\) expects string, int given\.$#'
89+
identifier: argument.type
6590
count: 1
6691
path: tests/Form/DataTransformer/MoneyToLocalizedStringTransformerTest.php
6792

6893
-
69-
message: "#^Parameter \\#1 \\$value of method BabDev\\\\MoneyBundle\\\\Form\\\\DataTransformer\\\\MoneyToLocalizedStringTransformer\\<Money\\\\Money,string\\>\\:\\:transform\\(\\) expects Money\\\\Money\\|null, string given\\.$#"
94+
message: '#^Parameter \#1 \$value of method BabDev\\MoneyBundle\\Form\\DataTransformer\\MoneyToLocalizedStringTransformer\<Money\\Money,string\>\:\:transform\(\) expects Money\\Money\|null, string given\.$#'
95+
identifier: argument.type
7096
count: 1
7197
path: tests/Form/DataTransformer/MoneyToLocalizedStringTransformerTest.php
7298

7399
-
74-
message: "#^Parameter \\#2 \\$locale of function setlocale expects string\\|null, bool\\|string given\\.$#"
100+
message: '#^Parameter \#2 \$locale of function setlocale expects string\|null, bool\|string given\.$#'
101+
identifier: argument.type
75102
count: 1
76103
path: tests/Form/DataTransformer/MoneyToLocalizedStringTransformerTest.php
77104

phpstan.neon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ includes:
44
parameters:
55
level: max
66
paths:
7-
- %currentWorkingDirectory%/src
8-
- %currentWorkingDirectory%/tests
7+
- src
8+
- tests
99
treatPhpDocTypesAsCertain: false
1010
ignoreErrors:
1111
-

src/BabDevMoneyBundle.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public function configure(DefinitionConfigurator $definition): void
4444
;
4545
}
4646

47+
/**
48+
* @param array{default_currency: non-empty-string} $config
49+
*/
4750
public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
4851
{
4952
$container->parameters()

src/Factory/FormatterFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ final class FormatterFactory implements FormatterFactoryInterface
3131
public function __construct(private readonly string $defaultLocale) {}
3232

3333
/**
34+
* @param array{fraction_digits?: int<0, max>, grouping_used?: bool, style?: string} $options
35+
*
3436
* @phpstan-param Format::* $format
3537
* @phpstan-param array<string, mixed> $options
3638
*

src/Factory/ParserFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ final class ParserFactory implements ParserFactoryInterface
3030
public function __construct(private readonly string $defaultLocale) {}
3131

3232
/**
33+
* @param array{fraction_digits?: int<0, max>, grouping_used?: bool, style?: string} $options
34+
*
3335
* @phpstan-param Format::* $format
3436
* @phpstan-param array<string, mixed> $options
3537
*

src/Form/Type/MoneyType.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
* Alternative money form type supporting a {@see Money} object as a data input.
2121
*
2222
* Class is based on {@see \Symfony\Component\Form\Extension\Core\Type\MoneyType}
23+
*
24+
* @template TData of Money
25+
*
26+
* @template-extends AbstractType<Money>
2327
*/
2428
final class MoneyType extends AbstractType
2529
{
@@ -62,6 +66,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
6266

6367
public function buildView(FormView $view, FormInterface $form, array $options): void
6468
{
69+
/** @phpstan-ignore-next-line argument.type */
6570
$view->vars['money_pattern'] = self::getPattern($options['currency']);
6671

6772
if ($options['html5']) {
@@ -71,17 +76,15 @@ public function buildView(FormView $view, FormInterface $form, array $options):
7176

7277
public function configureOptions(OptionsResolver $resolver): void
7378
{
74-
$resolver->setDefaults(
75-
[
76-
'scale' => 2,
77-
'grouping' => false,
78-
'rounding_mode' => \NumberFormatter::ROUND_HALFUP,
79-
'currency' => $this->defaultCurrency,
80-
'compound' => false,
81-
'html5' => false,
82-
'invalid_message' => 'Please enter a valid money amount.',
83-
]
84-
);
79+
$resolver->setDefaults([
80+
'scale' => 2,
81+
'grouping' => false,
82+
'rounding_mode' => \NumberFormatter::ROUND_HALFUP,
83+
'currency' => $this->defaultCurrency,
84+
'compound' => false,
85+
'html5' => false,
86+
'invalid_message' => 'Please enter a valid money amount.',
87+
]);
8588

8689
$resolver->setAllowedValues(
8790
'rounding_mode',

src/Serializer/Handler/MoneyHandler.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public static function getSubscribingMethods(): array
4747
}
4848

4949
/**
50+
* @param array{amount: int|numeric-string, currency: non-empty-string} $moneyAsArray
51+
*
5052
* @throws InvalidArgumentException if a {@see Money} instance could not be created from the serialized data
5153
*/
5254
public function deserializeMoneyFromJson(DeserializationVisitorInterface $visitor, array $moneyAsArray, array $type, DeserializationContext $context): Money
@@ -81,6 +83,7 @@ public function deserializeMoneyFromXml(XmlDeserializationVisitor $visitor, \Sim
8183
*/
8284
public function serializeMoneyToJson(JsonSerializationVisitor $visitor, Money $money, array $type, SerializationContext $context)
8385
{
86+
/** @phpstan-ignore-next-line return.type */
8487
return $visitor->visitArray(
8588
[
8689
'amount' => $money->getAmount(),

src/Serializer/Normalizer/MoneyNormalizer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ public function denormalize($data, string $type, ?string $format = null, array $
5050
throw new UnexpectedValueException('Missing required keys from data array, must provide "amount" and "currency".');
5151
}
5252

53+
\assert((\is_int($data['amount']) || is_numeric($data['amount'])) && (\is_string($data['currency']) && '' !== $data['currency']));
54+
5355
try {
56+
/** @phpstan-ignore-next-line argument.type */
5457
return new Money($data['amount'], new Currency($data['currency']));
5558
} catch (\Exception $e) {
5659
throw new NotNormalizableValueException($e->getMessage(), $e->getCode(), $e);

0 commit comments

Comments
 (0)