Skip to content

Commit

Permalink
Merge pull request overblog#801 from Vincz/master
Browse files Browse the repository at this point in the history
Annotations refactoring & PHP 8 Attributes
  • Loading branch information
murtukov authored Jan 19, 2021
2 parents f9ed247 + a93a003 commit 070b804
Show file tree
Hide file tree
Showing 90 changed files with 3,412 additions and 1,879 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ jobs:
- php-version: 7.4
symfony-version: "5.2.*"

- php-version: 8.0
symfony-version: "5.2.*"

name: "PHP ${{ matrix.php-version }} / Symfony ${{ matrix.symfony-version }} Test"

steps:
Expand Down Expand Up @@ -187,7 +190,7 @@ jobs:
- name: "Install PHP with coverage"
uses: "shivammathur/setup-php@v2"
with:
php-version: "7.4"
php-version: "8.0"
ini-values: pcov.directory=.
coverage: "pcov"

Expand All @@ -198,16 +201,17 @@ jobs:
key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
restore-keys: "php-${{ matrix.php-version }}-composer-locked-"

- name: "Install Ocular as depencies"
run: composer req "scrutinizer/ocular" --dev --no-update

- name: "Install dependencies"
run: composer update --no-interaction --no-progress

- name: "Run tests with coverage"
run: bin/phpunit --color=always -v --debug --coverage-clover=build/logs/clover.xml

- name: "Upload coverage results to Scrutinizer"
run: |
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml
run: vendor/scrutinizer/ocular/bin/ocular code-coverage:upload --format=php-clover build/logs/clover.xml

- name: "Upload coverage results to Coveralls"
env:
Expand Down
2 changes: 2 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ return PhpCsFixer\Config::create()
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
'global_namespace_import' => ['import_functions' => true, 'import_classes' => true, 'import_constants' => true],
'phpdoc_summary' => false,
'hash_to_slash_comment' => false,
'single_line_comment_style' => false
]
)
->setFinder($finder)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Documentation
- [Data fetching](docs/data-fetching/index.md)
- [Query batching](docs/data-fetching/batching.md)
- [Promise](docs/data-fetching/promise.md)
- [Annotations](docs/annotations/index.md)
- [Annotations & PHP 8 Attributes](docs/annotations/index.md)
- [Validation](docs/validation/index.md)
- [Security](docs/security/index.md)
- [Handle CORS](docs/security/handle-cors.md)
Expand Down
74 changes: 71 additions & 3 deletions UPGRADE-1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ UPGRADE FROM 0.13 to 1.0

# Table of Contents

- [Customize the cursor encoder of the edges of a connection](#customize-the-cursor-encoder-of-the-edges-of-a-connection)
- [Change arguments of `TypeGenerator`](#change-arguments-of-typegenerator)
- [Add magic `__get` method to `ArgumentInterface` implementors](#add-magic-__get-method-to-argumentinterface-implementors)
- [UPGRADE FROM 0.13 to 1.0](#upgrade-from-013-to-10)
- [Table of Contents](#table-of-contents)
- [Customize the cursor encoder of the edges of a connection](#customize-the-cursor-encoder-of-the-edges-of-a-connection)
- [Change arguments of `TypeGenerator` class](#change-arguments-of-typegenerator-class)
- [Add magic `__get` method to `ArgumentInterface` implementors](#add-magic-__get-method-to-argumentinterface-implementors)
- [Annotations - Flattened annotations](#annotations---flattened-annotations)
- [Annotations - Attributes changed](#annotations---attributes-changed)

### Customize the cursor encoder of the edges of a connection

Expand Down Expand Up @@ -86,3 +90,67 @@ class Argument implements ArgumentInterface
}
```
If you use your own class for resolver arguments, then it should have a `__get` method as well.


### Annotations - Flattened annotations

In order to prepare to PHP 8 attributes (they don't support nested attributes at the moment. @see https://github.com/symfony/symfony/issues/38503), the following annotations have been flattened: `@FieldsBuilder`, `@FieldBuilder`, `@ArgsBuilder`, `@Arg` and `@EnumValue`.

Before:
```php
/**
* @GQL\Type
*/
class MyType {
/**
* @GQL\Field(args={
* @GQL\Arg(name="arg1", type="String"),
* @GQL\Arg(name="arg2", type="Int")
* })
*/
public function myFields(?string $arg1, ?int $arg2) {..}
}

```

After:
```php
/**
* @GQL\Type
*/
class MyType {
/**
* @GQL\Field
* @GQL\Arg(name="arg1", type="String"),
* @GQL\Arg(name="arg2", type="Int")
*/
public function myFields(?string $arg1, ?int $arg2) {..}
}

```

### Annotations - Attributes changed

Change the attributes name of `@FieldsBuilder` annotation from `builder` and `builderConfig` to `value` and `config`.

Before:
```php
/**
* @GQL\Type(name="MyType", builders={@GQL\FieldsBuilder(builder="Timestamped", builderConfig={opt1: "val1"})})
*/
class MyType {

}
```

After:
```php
/**
* @GQL\Type("MyType")
* @GQL\FieldsBuilder(value="Timestamped", config={opt1: "val1"})
*/
class MyType {

}
```

3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"require": {
"php": ">=7.4",
"ext-json": "*",
"murtukov/php-code-generator": "^0.1.4",
"murtukov/php-code-generator": "^0.1.5",
"phpdocumentor/reflection-docblock": "^5.2",
"psr/log": "^1.0",
"symfony/config": "^4.4 || ^5.0",
"symfony/dependency-injection": "^4.4 || ^5.0",
Expand Down
Loading

0 comments on commit 070b804

Please sign in to comment.