Skip to content

Commit

Permalink
Allow symfony 7 (#5)
Browse files Browse the repository at this point in the history
* Permit Symfony 7.0
* Update CI with new Symfony and PHP versions
* For the moment do not permit doctrine/dbal version >=4.0
  • Loading branch information
benr77 authored May 31, 2024
1 parent 01312af commit 7fbaac9
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 23 deletions.
28 changes: 15 additions & 13 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [master]
branches: [main]
pull_request:
branches: [master]
branches: [main]

jobs:

Expand All @@ -16,16 +16,18 @@ jobs:
fail-fast: false
matrix:
operating-system: [ ubuntu-latest, windows-latest ]
php: [ '7.4', '8.0', '8.1' ]
symfony: [ '4.4.*', '5.4.*', '6.0.*', '6.1.*' ]
php: [ '7.4', '8.0', '8.1', '8.2' ]
symfony: [ '4.4.*', '5.4.*', '6.4.*', '7.0.*' ]
exclude:
- { php: '7.4', symfony: '6.0.*' }
- { php: '7.4', symfony: '6.1.*' }
- { php: '8.0', symfony: '6.1.*' }
- { php: '7.4', symfony: '6.4.*' }
- { php: '8.0', symfony: '6.4.*' }
- { php: '7.4', symfony: '7.0.*' }
- { php: '8.0', symfony: '7.0.*' }
- { php: '8.1', symfony: '7.0.*' }

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
Expand All @@ -35,7 +37,7 @@ jobs:
coverage: none

- name: Install composer dependencies
uses: ramsey/composer-install@v2
uses: ramsey/composer-install@v3
env:
SYMFONY_REQUIRE: ${{ matrix.symfony }}

Expand All @@ -46,14 +48,14 @@ jobs:
name: Easy Coding Standard
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ramsey/composer-install@v2
- uses: actions/checkout@v4
- uses: ramsey/composer-install@v3
- run: vendor/bin/ecs

phpstan:
name: PHPStan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ramsey/composer-install@v2
- uses: actions/checkout@v4
- uses: ramsey/composer-install@v3
- run: vendor/bin/phpstan
13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
"require": {
"php": ">=7.4",
"moneyphp/money": "^3.3 || ^4.0",
"symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0"
"symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0 || ^7.0"
},
"require-dev": {
"doctrine/doctrine-bundle": "^1.0 || ^2.0",
"phpstan/phpstan": "^1.8",
"phpunit/phpunit": "^8.0 || ^9.0",
"symfony/form": "^4.4 || ^5.0 || ^6.0",
"symfony/serializer": "^4.4 || ^5.0 || ^6.0",
"symfony/twig-bundle": "^4.4 || ^5.0 || ^6.0",
"symfony/validator": "^4.4 || ^5.0 || ^6.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",
"symplify/easy-coding-standard": "^11"
},
"suggest": {
Expand All @@ -30,6 +30,9 @@
"symfony/twig-bundle": "Format and manipulate Money in Twig templates",
"symfony/validator": "Use custom validation constraints on Money objects"
},
"conflict": {
"doctrine/dbal": ">=4.0.0"
},
"autoload": {
"psr-4": {
"Headsnet\\MoneyBundle\\": "src/",
Expand Down
4 changes: 3 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ parameters:
bootstrapFiles:
- vendor/autoload.php

checkGenericClassInNonGenericObjectType: false
ignoreErrors:
-
identifier: missingType.generics
8 changes: 7 additions & 1 deletion src/HeadsnetMoneyBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Doctrine\Persistence\ManagerRegistry;
use Headsnet\MoneyBundle\Doctrine\DBAL\Types\CurrencyType;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class HeadsnetMoneyBundle extends Bundle
Expand All @@ -28,6 +29,9 @@ public function build(ContainerBuilder $container): void
$this->addDoctrineMapping($container);
}

/**
* @throws Exception
*/
public function boot(): void
{
$this->addCurrencyColumnType();
Expand Down Expand Up @@ -60,8 +64,10 @@ private function addCurrencyColumnType(): void
Type::addType('currency', CurrencyType::class);
}

/** @var ContainerInterface $container Keep PHPStan happy */
$container = $this->container;
/** @var ManagerRegistry $registry */
$registry = $this->container->get('doctrine');
$registry = $container->get('doctrine');

/** @var Connection $connection */
foreach ($registry->getConnections() as $connection) {
Expand Down
5 changes: 4 additions & 1 deletion src/Serializer/Normalizer/MoneyAsDecimalNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ public function __construct()

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

/**
* @param array<string, string> $context
*/
public function supportsNormalization($data, string $format = null, array $context = []): bool
{
return $data instanceof Money;
Expand Down
10 changes: 8 additions & 2 deletions src/Serializer/Normalizer/MoneyNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MoneyNormalizer implements NormalizerInterface, DenormalizerInterface
{
/**
* @param Money $object
* @param string[] $context
* @param array<string, string> $context
*
* @return array{amount: string, currency: Currency}
*/
Expand All @@ -31,20 +31,26 @@ public function normalize($object, string $format = null, array $context = []):
];
}

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

/**
* @param array{amount: numeric-string, currency: non-empty-string} $data
* @param string[] $context
* @param array<string, string> $context
*/
public function denormalize($data, string $type, string $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
{
if ($type !== Money::class) {
Expand Down

0 comments on commit 7fbaac9

Please sign in to comment.