Skip to content

Commit

Permalink
PHP8.1 update, proper Symfony 5.4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
pkly authored Dec 30, 2022
1 parent d85abd1 commit 0bfa02a
Show file tree
Hide file tree
Showing 111 changed files with 955 additions and 952 deletions.
77 changes: 52 additions & 25 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
name: Validate push
on: [push]
on: [pull_request]

jobs:
install:
strategy:
matrix:
symfony-version: [ 4.4, 5.4 ]
php-version: [ 7.4, 8.1 ]
include:
- symfony-version: 5.4
php-version: 8.1

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -15,29 +17,32 @@ jobs:
uses: actions/cache@v3
with:
path: vendor/
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ matrix.symfony-version }}-${{ matrix.php-version }}
key: ${{ runner.os }}-composer-s-${{ hashFiles('**/composer.json') }}-${{ matrix.symfony-version }}-${{ matrix.php-version }}
restore-keys: |
${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ matrix.symfony-version }}-${{ matrix.php-version }}
${{ runner.os }}-composer-s-${{ hashFiles('**/composer.json') }}-${{ matrix.symfony-version }}-${{ matrix.php-version }}
- name: Setup flex
uses: php-actions/composer@v6
- name: PHP Setup
uses: shivammathur/setup-php@v2
with:
php_version: ${{ matrix.php-version }}
command: global require --no-progress --no-scripts --no-plugins symfony/flex
php-version: ${{ matrix.php-version }}
ini-values: pcov.directory=.
coverage: pcov
tools: composer

- uses: php-actions/composer@v6
- name: Setup flex
run: |
composer global require --no-progress --no-scripts --no-plugins symfony/flex && composer global config --no-plugins allow-plugins.symfony/flex true
- name: Install
env:
SYMFONY_REQUIRE: ${{ matrix.symfony-version }}
with:
php_version: ${{ matrix.php-version }}
command: install --no-interaction --no-scripts --ansi --no-progress --prefer-dist
run: |
composer install --no-interaction --no-scripts --ansi --no-progress --prefer-dist
phpstan:
strategy:
matrix:
include:
- symfony-version: 4.4
php-version: 7.4
- symfony-version: 5.4
php-version: 8.1

Expand All @@ -51,16 +56,17 @@ jobs:
uses: actions/cache@v3
with:
path: vendor/
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ matrix.symfony-version }}-${{ matrix.php-version }}
key: ${{ runner.os }}-composer-s-${{ hashFiles('**/composer.json') }}-${{ matrix.symfony-version }}-${{ matrix.php-version }}
restore-keys: |
${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ matrix.symfony-version }}-${{ matrix.php-version }}
${{ runner.os }}-composer-s-${{ hashFiles('**/composer.json') }}-${{ matrix.symfony-version }}-${{ matrix.php-version }}
- name: PHP Setup
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
ini-values: pcov.directory=.
coverage: pcov
tools: composer

- name: PHPStan
run: |
Expand All @@ -70,8 +76,6 @@ jobs:
strategy:
matrix:
include:
- symfony-version: 4.4
php-version: 7.4
- symfony-version: 5.4
php-version: 8.1

Expand All @@ -85,16 +89,17 @@ jobs:
uses: actions/cache@v3
with:
path: vendor/
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ matrix.symfony-version }}-${{ matrix.php-version }}
key: ${{ runner.os }}-composer-s-${{ hashFiles('**/composer.json') }}-${{ matrix.symfony-version }}-${{ matrix.php-version }}
restore-keys: |
${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ matrix.symfony-version }}-${{ matrix.php-version }}
${{ runner.os }}-composer-s-${{ hashFiles('**/composer.json') }}-${{ matrix.symfony-version }}-${{ matrix.php-version }}
- name: PHP Setup
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
ini-values: pcov.directory=.
coverage: pcov
tools: composer

- name: PHP-CS-Fixer
run: |
Expand All @@ -103,8 +108,9 @@ jobs:
test:
strategy:
matrix:
symfony-version: [ 4.4, 5.4 ]
php-version: [ 7.4, 8.1 ]
include:
- symfony-version: 5.4
php-version: 8.1

runs-on: ubuntu-latest
needs:
Expand All @@ -118,17 +124,38 @@ jobs:
uses: actions/cache@v3
with:
path: vendor/
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ matrix.symfony-version }}-${{ matrix.php-version }}
key: ${{ runner.os }}-composer-s-${{ hashFiles('**/composer.json') }}-${{ matrix.symfony-version }}-${{ matrix.php-version }}
restore-keys: |
${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ matrix.symfony-version }}-${{ matrix.php-version }}
${{ runner.os }}-composer-s-${{ hashFiles('**/composer.json') }}-${{ matrix.symfony-version }}-${{ matrix.php-version }}
- name: PHP Setup
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
ini-values: pcov.directory=.
coverage: pcov
tools: composer

- name: PHPUnit
run: |
vendor/bin/phpunit --coverage-cobertura artifacts/code-coverage-cobertura.xml
- name: Code Coverage Report
uses: irongut/[email protected]
with:
filename: artifacts/code-coverage-cobertura.xml
badge: true
fail_below_min: true
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: '70 80'

- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
recreate: true
path: code-coverage-results.md
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,47 @@
# Symfony DTO Bundle

![Code Coverage](https://camo.githubusercontent.com/ffe54b3b9a48d4d6bd374e2630b48e088c99858500db95ebed37184e8c1a6a3b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f6465253230436f7665726167652d38342532352d737563636573733f7374796c653d666c6174)

This bundle aims to lower the burden of typechecking, casting, loading entities
and related annoyances of using requests in your api.

## Usage

1. Create a DTO class for your request

```php

use \DM\DtoRequestBundle\Attributes\Dto\Path;
use \DM\DtoRequestBundle\Model\AbstractDto;

class MyDto extends AbstractDto
{
public ?int $myVar = null;

#[Path("custom_path")]
public ?string $myString = null;
}

```

2. Add your dto as a controller argument

```php

class MyController extends \Symfony\Bundle\FrameworkBundle\Controller\AbstractController
{
public function myAction(MyDto $dto): \Symfony\Component\HttpFoundation\Response
{
// your dto here is already validated!
}
}
```

## Docs

Currently no documentation is available, but will be added in the future. For the time being see [the DTO models for tests](tests/Fixtures/Model/Dto)

## Missing features

Currently, some setup is required. Doctrine will not automatically supply entities at this point
and a custom CompilerPass is needed. This will be resolved with an update for the bundle in the future.
25 changes: 11 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,26 @@
}
],
"require": {
"php": "^7.4|^8.1",
"doctrine/annotations": "^1.11",
"symfony/framework-bundle": "^4.4|^5.4",
"symfony/event-dispatcher": "^4.4|^5.4",
"symfony/property-info": "^4.4|^5.4",
"symfony/validator": "^4.4|^5.4",
"symfony/property-access": "^4.4|^5.4",
"myclabs/php-enum": "^1.7",
"symfony/polyfill-php80": "^1"
"php": "^8.1",
"symfony/framework-bundle": "^5.4",
"symfony/event-dispatcher": "^5.4",
"symfony/property-info": "^5.4",
"symfony/validator": "^5.4",
"symfony/property-access": "^5.4"
},
"require-dev": {
"ext-simplexml": "*",
"phpunit/phpunit": "^9.5",
"psalm/plugin-symfony": "^2.4",
"friendsofphp/php-cs-fixer": "^3",
"pedrotroller/php-cs-custom-fixer": "^2",
"vimeo/psalm": "^4.10",
"vimeo/psalm": "^5",
"phpstan/phpstan": "^1",
"symfony/phpunit-bridge": "^4.4|^5.3",
"symfony/phpunit-bridge": "^5.4",
"matthiasnoback/symfony-dependency-injection-test": "^4.3",
"nelmio/api-doc-bundle": "^4",
"symfony/stopwatch": "^4.4|^5.4",
"symfony/web-profiler-bundle": "^4.4|^5.4"
"symfony/stopwatch": "^5.4",
"symfony/web-profiler-bundle": "^5.4",
"doctrine/doctrine-bundle": "^2"
},
"conflict": {
"nelmio/api-doc-bundle": "<4"
Expand Down
3 changes: 1 addition & 2 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@

$services->alias(DtoTypeExtractorInterface::class, DtoTypeExtractorHelper::class);
$services->set(DtoTypeExtractorHelper::class)
->arg(0, new Reference('property_info'))
->arg(1, new Reference('annotation_reader'));
->arg(0, new Reference('property_info'));

$services->alias(DtoResolverInterface::class, DtoResolverService::class);
$services->set(DtoResolverService::class)
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
parameters:
reportUnmatchedIgnoredErrors: false
checkGenericClassInNonGenericObjectType: false
level: 7
level: 9
paths:
- src
31 changes: 0 additions & 31 deletions scripts/coverage-check.php

This file was deleted.

32 changes: 0 additions & 32 deletions src/Annotations/Dto/AllowEnum.php

This file was deleted.

50 changes: 0 additions & 50 deletions src/Annotations/Dto/Bag.php

This file was deleted.

Loading

0 comments on commit 0bfa02a

Please sign in to comment.