Skip to content

Commit

Permalink
Bump to PHP 8.1, there are literally no installs on older PHP versions
Browse files Browse the repository at this point in the history
  • Loading branch information
mbabker committed Sep 15, 2023
1 parent 60a5bba commit 12d3bda
Show file tree
Hide file tree
Showing 27 changed files with 124 additions and 238 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ jobs:
strategy:
fail-fast: true
matrix:
php: ['7.4', '8.0', '8.1', '8.2']
php: ['8.1', '8.2']
symfony: ['5.4.*', '6.3.*']
composer-flags: ['--prefer-stable']
can-fail: [false]
has-mongodb: [true]
extensions: ['curl, iconv, mbstring, mongodb, pdo, pdo_sqlite, sqlite, zip']
include:
- php: '7.4'
- php: '8.1'
symfony: '5.4.*'
composer-flags: '--prefer-stable --prefer-lowest'
extensions: 'curl, iconv, mbstring, mongodb, pdo, pdo_sqlite, sqlite, zip'
Expand All @@ -34,11 +34,6 @@ jobs:
extensions: 'curl, iconv, mbstring, mongodb, pdo, pdo_sqlite, sqlite, zip'
can-fail: true
has-mongodb: true
exclude:
- php: '7.4'
symfony: '6.3.*'
- php: '8.0'
symfony: '6.3.*'

name: "PHP ${{ matrix.php }} - Symfony ${{ matrix.symfony }}${{ matrix.composer-flags != '' && format(' - Composer {0}', matrix.composer-flags) || '' }}"

Expand Down
5 changes: 2 additions & 3 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP74Migration' => true,
'@PHP74Migration:risky' => true,
'@PHP81Migration' => true,
'@PHP80Migration:risky' => true,
'@PHPUnit84Migration:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_after_opening_tag' => false,
'fopen_flags' => false,
'get_class_to_class_keyword' => false, // Re-enable when dropping PHP 7.4 support
'linebreak_after_opening_tag' => false,
'no_superfluous_phpdoc_tags' => ['remove_inheritdoc' => true],
'nullable_type_declaration_for_default_null_value' => ['use_nullable_type_declaration' => true],
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
"keywords": ["money", "moneyphp", "currency", "symfony"],
"license": "MIT",
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.1",
"moneyphp/money": "^3.3 || ^4.0",
"symfony/config": "^5.4 || ^6.3 || ^7.0",
"symfony/dependency-injection": "^5.4 || ^6.3 || ^7.0",
"symfony/deprecation-contracts": "^2.1 || ^3.0",
"symfony/http-kernel": "^5.4 || ^6.3 || ^7.0",
"symfony/polyfill-php80": "^1.16"
"symfony/http-kernel": "^5.4 || ^6.3 || ^7.0"
},
"require-dev": {
"doctrine/doctrine-bundle": "^2.0",
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ parameters:
path: tests/Form/DataTransformer/MoneyToLocalizedStringTransformerTest.php

-
message: "#^Parameter \\#2 \\$locale of function setlocale expects string\\|null, string\\|false given\\.$#"
message: "#^Parameter \\#2 \\$locale of function setlocale expects string\\|null, bool\\|string given\\.$#"
count: 1
path: tests/Form/DataTransformer/MoneyToLocalizedStringTransformerTest.php

Expand Down
25 changes: 10 additions & 15 deletions src/Factory/Exception/UnsupportedFormatException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,23 @@
final class UnsupportedFormatException extends \InvalidArgumentException
{
/**
* @var string[]
* @param list<string> $formats
*
* @phpstan-var array<Format::*>
* @phpstan-param list<Format::*> $formats
*/
private array $formats;

/**
* @param string[] $formats
*
* @phpstan-param array<Format::*> $formats
*/
public function __construct(array $formats, string $message = '', int $code = 0, ?\Throwable $previous = null)
{
public function __construct(
private readonly array $formats,
string $message = '',
int $code = 0,
?\Throwable $previous = null,
) {
parent::__construct($message, $code, $previous);

$this->formats = $formats;
}

/**
* @return string[]
* @return list<string>
*
* @phpstan-return array<Format::*>
* @phpstan-return list<Format::*>
*/
public function getFormats(): array
{
Expand Down
7 changes: 1 addition & 6 deletions src/Factory/FormatterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ final class FormatterFactory implements FormatterFactoryInterface
Format::INTL_MONEY => IntlMoneyFormatter::class,
];

private string $defaultLocale;

public function __construct(string $defaultLocale)
{
$this->defaultLocale = $defaultLocale;
}
public function __construct(private readonly string $defaultLocale) {}

/**
* @phpstan-param Format::* $format
Expand Down
7 changes: 1 addition & 6 deletions src/Factory/ParserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ final class ParserFactory implements ParserFactoryInterface
Format::INTL_MONEY => IntlMoneyParser::class,
];

private string $defaultLocale;

public function __construct(string $defaultLocale)
{
$this->defaultLocale = $defaultLocale;
}
public function __construct(private readonly string $defaultLocale) {}

/**
* @phpstan-param Format::* $format
Expand Down
22 changes: 10 additions & 12 deletions src/Form/DataTransformer/MoneyToLocalizedStringTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* Transforms between a normalized format and a localized money string.
*
* Class is based on \Symfony\Component\Form\Extension\Core\DataTransformer\MoneyToLocalizedStringTransformer
* Class is based on {@see \Symfony\Component\Form\Extension\Core\DataTransformer\MoneyToLocalizedStringTransformer}
*
* @template T of Money
* @template R of string
Expand All @@ -25,19 +25,22 @@
*/
final class MoneyToLocalizedStringTransformer implements DataTransformerInterface
{
private FormatterFactoryInterface $formatterFactory;
private ParserFactoryInterface $parserFactory;
private Currency $currency;
private ?string $locale;
private NumberToLocalizedStringTransformer $numberTransformer;

/**
* @param NumberToLocalizedStringTransformer|int|null $scaleOrTransformer
*
* @throws InvalidArgumentException if an invalid constructor parameter is provided
*/
public function __construct(FormatterFactoryInterface $formatterFactory, ParserFactoryInterface $parserFactory, Currency $currency, $scaleOrTransformer = 2, ?bool $grouping = true, ?int $roundingMode = \NumberFormatter::ROUND_HALFUP, ?string $locale = null)
{
public function __construct(
private readonly FormatterFactoryInterface $formatterFactory,
private readonly ParserFactoryInterface $parserFactory,
private readonly Currency $currency,
$scaleOrTransformer = 2,
?bool $grouping = true,
?int $roundingMode = \NumberFormatter::ROUND_HALFUP,
private readonly ?string $locale = null,
) {
if ($scaleOrTransformer instanceof NumberToLocalizedStringTransformer) {
$this->numberTransformer = $scaleOrTransformer;
} elseif (\is_int($scaleOrTransformer) || null === $scaleOrTransformer) {
Expand All @@ -47,11 +50,6 @@ public function __construct(FormatterFactoryInterface $formatterFactory, ParserF
} else {
throw new InvalidArgumentException(sprintf('The fourth argument to the %s constructor must be an instance of %s, an integer, or null; %s given', self::class, NumberToLocalizedStringTransformer::class, get_debug_type($scaleOrTransformer)));
}

$this->formatterFactory = $formatterFactory;
$this->parserFactory = $parserFactory;
$this->currency = $currency;
$this->locale = $locale;
}

/**
Expand Down
18 changes: 9 additions & 9 deletions src/Form/Type/MoneyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use BabDev\MoneyBundle\Factory\ParserFactoryInterface;
use BabDev\MoneyBundle\Form\DataTransformer\MoneyToLocalizedStringTransformer;
use Money\Currency;
use Money\Money;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Exception\LogicException;
use Symfony\Component\Form\Extension\Core\DataTransformer\NumberToLocalizedStringTransformer;
Expand All @@ -16,15 +17,13 @@
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* Alternative money form type supporting a `Money\Money` object as a data input.
* Alternative money form type supporting a {@see Money} object as a data input.
*
* Class is based on \Symfony\Component\Form\Extension\Core\Type\MoneyType
* Class is based on {@see \Symfony\Component\Form\Extension\Core\Type\MoneyType}
*/
final class MoneyType extends AbstractType
{
private FormatterFactoryInterface $formatterFactory;
private ParserFactoryInterface $parserFactory;
private Currency $defaultCurrency;
private readonly Currency $defaultCurrency;

/**
* @var array<string, array<string, string>>
Expand All @@ -34,10 +33,11 @@ final class MoneyType extends AbstractType
/**
* @phpstan-param non-empty-string $defaultCurrency
*/
public function __construct(FormatterFactoryInterface $formatterFactory, ParserFactoryInterface $parserFactory, string $defaultCurrency)
{
$this->formatterFactory = $formatterFactory;
$this->parserFactory = $parserFactory;
public function __construct(
private readonly FormatterFactoryInterface $formatterFactory,
private readonly ParserFactoryInterface $parserFactory,
string $defaultCurrency,
) {
$this->defaultCurrency = new Currency($defaultCurrency);
}

Expand Down
9 changes: 2 additions & 7 deletions src/Serializer/Normalizer/LegacyMoneyNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,13 @@
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

/**
* Decorator for {@see MoneyNormalizer} implementing the legacy {@CacheableSupportsMethodInterface} for older Symfony version support.
* Decorator for {@see MoneyNormalizer} implementing the legacy {@see CacheableSupportsMethodInterface} for older Symfony version support.
*
* @internal
*/
final class LegacyMoneyNormalizer implements NormalizerInterface, DenormalizerInterface, CacheableSupportsMethodInterface
{
private MoneyNormalizer $normalizer;

public function __construct(MoneyNormalizer $normalizer)
{
$this->normalizer = $normalizer;
}
public function __construct(private readonly MoneyNormalizer $normalizer) {}

public function normalize($object, ?string $format = null, array $context = []): array
{
Expand Down
28 changes: 9 additions & 19 deletions src/Twig/MoneyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,41 @@

final class MoneyExtension extends AbstractExtension
{
private FormatterFactoryInterface $formatterFactory;

/**
* @phpstan-var non-empty-string
*/
private string $defaultCurrency;

/**
* @phpstan-param non-empty-string $defaultCurrency
*/
public function __construct(FormatterFactoryInterface $formatterFactory, string $defaultCurrency)
{
$this->formatterFactory = $formatterFactory;
$this->defaultCurrency = $defaultCurrency;
}
public function __construct(
private readonly FormatterFactoryInterface $formatterFactory,
private readonly string $defaultCurrency
) {}

/**
* @return TwigFilter[]
* @return list<TwigFilter>
*/
public function getFilters(): array
{
return [
new TwigFilter('money', [$this, 'formatMoney']),
new TwigFilter('money', $this->formatMoney(...)),
];
}

/**
* @return TwigFunction[]
* @return list<TwigFunction>
*/
public function getFunctions(): array
{
return [
new TwigFunction('money', [$this, 'createMoney']),
new TwigFunction('money', $this->createMoney(...)),
];
}

/**
* @param string|int $amount
*
* @phpstan-param numeric-string|int $amount
* @phpstan-param non-empty-string|null $currency
*
* @throws \InvalidArgumentException if the amount cannot be converted to a {@see Money} instance
*/
public function createMoney($amount, ?string $currency = null): Money
public function createMoney(string|int $amount, ?string $currency = null): Money
{
return new Money($amount, new Currency($currency ?: $this->defaultCurrency));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Validator/Constraints/AbstractMoneyComparison.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* Used for the comparison of Money objects.
*
* Class is based on \Symfony\Component\Validator\Constraints\AbstractComparison
* Class is based on {@see \Symfony\Component\Validator\Constraints\AbstractComparison}
*/
abstract class AbstractMoneyComparison extends Constraint
{
Expand Down
Loading

0 comments on commit 12d3bda

Please sign in to comment.