Skip to content

Commit

Permalink
Bump PHP to 8.1 and support 8.4 (#6)
Browse files Browse the repository at this point in the history
* Bump minimum PHP to 8.1 and Symfony to 5.4
* Add static analysis scripts entry
* Fix PHP 8.4 deprecations
  • Loading branch information
benr77 authored Dec 16, 2024
1 parent ef128bf commit 8b251a5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 31 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@ jobs:
fail-fast: false
matrix:
operating-system: [ ubuntu-latest, windows-latest ]
php: [ '7.4', '8.0', '8.1', '8.2', '8.3' ]
symfony: [ '4.4.*', '5.4.*', '6.4.*', '7.1.*' ]
php: [ '8.1', '8.2', '8.3', '8.4' ]
symfony: [ '5.4.*', '6.4.*', '7.2.*' ]
exclude:
- { php: '7.4', symfony: '6.4.*' }
- { php: '8.0', symfony: '6.4.*' }
- { php: '7.4', symfony: '7.1.*' }
- { php: '8.0', symfony: '7.1.*' }
- { php: '8.1', symfony: '7.1.*' }

- { php: '8.1', symfony: '7.2.*' }
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -49,6 +44,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: latest
- uses: ramsey/composer-install@v3
- run: vendor/bin/ecs

Expand All @@ -57,5 +55,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: latest
- uses: ramsey/composer-install@v3
- run: vendor/bin/phpstan
19 changes: 10 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
"issues": "https://github.com/headsnet/money-bundle/issues"
},
"require": {
"php": ">=7.4",
"moneyphp/money": "^3.3 || ^4.0",
"symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0 || ^7.0"
"php": ">=8.1",
"moneyphp/money": "^4.6",
"symfony/framework-bundle": "^5.4 || ^6.4 || ^7.0"
},
"require-dev": {
"doctrine/doctrine-bundle": "^1.0 || ^2.0",
"doctrine/doctrine-bundle": "^2.7",
"phpstan/phpstan": "^1.8",
"phpunit/phpunit": "^8.0 || ^9.0",
"symfony/form": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"symfony/serializer": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"symfony/twig-bundle": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"symfony/validator": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"symfony/form": "^5.4 || ^6.4 || ^7.0",
"symfony/serializer": "^5.4 || ^6.4 || ^7.0",
"symfony/twig-bundle": "^5.4 || ^6.4 || ^7.0",
"symfony/validator": "^5.4 || ^6.4 || ^7.0",
"symplify/easy-coding-standard": "^11"
},
"suggest": {
Expand All @@ -41,6 +41,7 @@
},
"scripts": {
"cs": "vendor/bin/ecs check --ansi --config=ecs.php",
"cs-fix": "vendor/bin/ecs check --ansi --config=ecs.php --fix"
"cs-fix": "vendor/bin/ecs check --ansi --config=ecs.php --fix",
"static": "vendor/bin/phpstan analyze --ansi"
}
}
10 changes: 5 additions & 5 deletions src/Serializer/Normalizer/MoneyAsDecimalNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@ public function __construct()
}

/**
* @param Money $object
* @param Money $data
* @param array<string, string> $context
*/
public function normalize($object, string $format = null, array $context = []): string
public function normalize($data, string|null $format = null, array $context = []): string
{
return $this->moneyFormatter->format($object);
return $this->moneyFormatter->format($data);
}

/**
* @param array<string, string> $context
*/
public function supportsNormalization($data, string $format = null, array $context = []): bool
public function supportsNormalization($data, string|null $format = null, array $context = []): bool
{
return $data instanceof Money;
}

/**
* @return array<string, bool>
*/
public function getSupportedTypes(?string $format): array
public function getSupportedTypes(string|null $format): array
{
return [
Money::class => true,
Expand Down
16 changes: 8 additions & 8 deletions src/Serializer/Normalizer/MoneyNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@
class MoneyNormalizer implements NormalizerInterface, DenormalizerInterface
{
/**
* @param Money $object
* @param Money $data
* @param array<string, string> $context
*
* @return array{amount: string, currency: Currency}
*/
public function normalize($object, string $format = null, array $context = []): array
public function normalize($data, string|null $format = null, array $context = []): array
{
return [
'amount' => $object->getAmount(),
'currency' => $object->getCurrency(),
'amount' => $data->getAmount(),
'currency' => $data->getCurrency(),
];
}

/**
* @param array<string, string> $context
*/
public function supportsNormalization($data, string $format = null, array $context = []): bool
public function supportsNormalization($data, string|null $format = null, array $context = []): bool
{
return $data instanceof Money;
}
Expand All @@ -43,15 +43,15 @@ public function supportsNormalization($data, string $format = null, array $conte
* @param array{amount: numeric-string, currency: non-empty-string} $data
* @param array<string, string> $context
*/
public function denormalize($data, string $type, string $format = null, array $context = []): Money
public function denormalize($data, string $type, string|null $format = null, array $context = []): Money
{
return new Money($data['amount'], new Currency($data['currency']));
}

/**
* @param array<string, string> $context
*/
public function supportsDenormalization($data, string $type, string $format = null, array $context = []): bool
public function supportsDenormalization($data, string $type, string|null $format = null, array $context = []): bool
{
if ($type !== Money::class) {
return false;
Expand All @@ -63,7 +63,7 @@ public function supportsDenormalization($data, string $type, string $format = nu
/**
* @return array<string, bool>
*/
public function getSupportedTypes(?string $format): array
public function getSupportedTypes(string|null $format): array
{
return [
Money::class => true,
Expand Down
2 changes: 1 addition & 1 deletion src/Twig/Extension/FormatMoneyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getFilters(): array
return [new TwigFilter('money', [$this, 'moneyFilter'])];
}

public function moneyFilter(Money $money, string $locale = null): string
public function moneyFilter(Money $money, string|null $locale = null): string
{
$defaultLocale = $this->translator->getLocale();

Expand Down

0 comments on commit 8b251a5

Please sign in to comment.