From 35e9fb4adf515ed779c5357de211406d619f8c3c Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Fri, 10 Dec 2021 09:07:00 +1100 Subject: [PATCH 1/2] introduce composer bin plugin --- .github/workflows/main.yml | 10 +++++++--- README.md | 4 ++-- composer.json | 15 ++++++++------- phpstan.neon | 5 ++--- phpunit.xml | 2 +- src/Concerns/Attributes.php | 4 ++-- src/JsonApiResource.php | 2 +- tests/Models/BasicModel.php | 10 ++++++++++ tests/Resources/BasicJsonApiResource.php | 3 +++ tests/Resources/CommentResource.php | 3 +++ tests/Resources/ImageResource.php | 3 +++ tests/Resources/LicenseResource.php | 5 ++++- tests/Resources/PostResource.php | 3 +++ tests/Resources/UserResource.php | 3 +++ vendor-bin/linting/composer.json | 7 +++++++ vendor-bin/testing/composer.json | 8 ++++++++ 16 files changed, 67 insertions(+), 20 deletions(-) create mode 100644 vendor-bin/linting/composer.json create mode 100644 vendor-bin/testing/composer.json diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 216094a..933c0a9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,7 +27,8 @@ jobs: key: dependencies-composer-${{ hashFiles('composer.json') }}-v3 - name: Install dependencies - run: composer install --no-suggest --no-interaction --verbose + run: | + composer update --no-suggest --no-interaction --verbose - name: Check platform requirements run: composer check-platform-reqs --verbose @@ -61,7 +62,7 @@ jobs: name: 'Test suite on PHP: ${{ matrix.php }}; Dependecies: ${{ matrix.dependency-version }}' strategy: matrix: - php: ['7.4', '8.0'] + php: ['7.4', '8.0', '8.1'] dependency-version: ['prefer-lowest', 'prefer-stable'] steps: @@ -82,9 +83,12 @@ jobs: - name: Install dependencies run: | - composer remove 'friendsofphp/php-cs-fixer' 'infection/infection' 'nunomaduro/larastan' 'phpstan/phpstan' 'phpunit/phpunit' 'ergebnis/composer-normalize' --dev --no-update --no-interaction --verbose composer update --${{ matrix.dependency-version }} --no-suggest --no-interaction --verbose + - name: Support prefer-lowest in PHP 8.1 + if: ${{ matrix.php == 8.1 && matrix.dependency-version == 'prefer-lowest' }} + run: composer require symfony/console:">=5.3.7" symfony/http-foundation:">=5.3.7" laravel/framework:">=8.62.0" nesbot/carbon:">=2.51.0" ramsey/collection:">=1.2.0" --prefer-lowest --with-all-dependencies + - name: Check platform requirements run: composer check-platform-reqs --verbose diff --git a/README.md b/README.md index 749fa4e..a2b9528 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,8 @@ These docs are not designed to introduce you to the JSON:API spec and the associ You can install using [composer](https://getcomposer.org/) from [Packagist](https://packagist.org/packages/timacdonald/json-api). -``` -$ composer require timacdonald/json-api +```sh +composer require timacdonald/json-api ``` # Basic usage diff --git a/composer.json b/composer.json index ec77a68..88c9827 100644 --- a/composer.json +++ b/composer.json @@ -20,13 +20,7 @@ "laravel/framework": "^8.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.0", - "infection/infection": "^0.25.4", - "nunomaduro/larastan": "^0.7.12", - "orchestra/testbench": "^6.0", - "phpstan/phpstan": "^0.12.94", - "phpunit/phpunit": "^9.0", - "mockery/mockery": "^1.3.3" + "bamarni/composer-bin-plugin": "^1.4" }, "config": { "preferred-install": "dist", @@ -45,6 +39,13 @@ "minimum-stability": "stable", "prefer-stable": true, "scripts": { + "bin": "echo 'bin not installed'", + "post-install-cmd": [ + "@composer bin all install --ansi" + ], + "post-update-cmd": [ + "@composer bin all update --ansi" + ], "fix": [ "clear", "@composer normalize", diff --git a/phpstan.neon b/phpstan.neon index b7df2a4..9a23cb9 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,11 +1,10 @@ parameters: - level: max + level: 8 paths: - src - - tests checkInternalClassCaseSensitivity: true checkTooWideReturnTypesInProtectedAndPublicMethods: true checkUninitializedProperties: true checkMissingIterableValueType: false includes: - - vendor/nunomaduro/larastan/extension.neon + - vendor-bin/linting/vendor/nunomaduro/larastan/extension.neon diff --git a/phpunit.xml b/phpunit.xml index 1e9100a..0b0d021 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,6 +1,6 @@ diff --git a/src/Concerns/Attributes.php b/src/Concerns/Attributes.php index 3a8e998..1406225 100644 --- a/src/Concerns/Attributes.php +++ b/src/Concerns/Attributes.php @@ -25,7 +25,7 @@ trait Attributes */ public static function maximalAttributes(): void { - static::$minimalAttributes = false; + self::$minimalAttributes = false; } /** @@ -61,7 +61,7 @@ private function fields(Request $request): ?array return $fields; } - return static::$minimalAttributes + return self::$minimalAttributes ? [] : null; } diff --git a/src/JsonApiResource.php b/src/JsonApiResource.php index 129600f..0755f60 100644 --- a/src/JsonApiResource.php +++ b/src/JsonApiResource.php @@ -32,7 +32,7 @@ public static function resolveTypeUsing(Closure $resolver): void public static function minimalAttributes(): void { - static::$minimalAttributes = true; + self::$minimalAttributes = true; } protected function toAttributes(Request $request): array diff --git a/tests/Models/BasicModel.php b/tests/Models/BasicModel.php index fae3c3b..e495a00 100644 --- a/tests/Models/BasicModel.php +++ b/tests/Models/BasicModel.php @@ -5,14 +5,24 @@ namespace Tests\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Collection; /** + * @property string $content + * @property string $key + * @property string $name + * @property string $title + * @property string $url * @property array $posts * @property self $author * @property self $license * @property self $feature_image * @property self $avatar * @property self|array $child + * @property self $post + * @property self $user + * @property Collection $likes + * @property Collection $comments */ class BasicModel extends Model { diff --git a/tests/Resources/BasicJsonApiResource.php b/tests/Resources/BasicJsonApiResource.php index cb9e62f..03a2af1 100644 --- a/tests/Resources/BasicJsonApiResource.php +++ b/tests/Resources/BasicJsonApiResource.php @@ -6,6 +6,9 @@ use TiMacDonald\JsonApi\JsonApiResource; +/** + * @mixin \Tests\Models\BasicModel + */ class BasicJsonApiResource extends JsonApiResource { // diff --git a/tests/Resources/CommentResource.php b/tests/Resources/CommentResource.php index 2b875bd..2f0e8ca 100644 --- a/tests/Resources/CommentResource.php +++ b/tests/Resources/CommentResource.php @@ -7,6 +7,9 @@ use Illuminate\Http\Request; use TiMacDonald\JsonApi\JsonApiResource; +/** + * @mixin \Tests\Models\BasicModel + */ class CommentResource extends JsonApiResource { protected function toAttributes(Request $request): array diff --git a/tests/Resources/ImageResource.php b/tests/Resources/ImageResource.php index 7b0b3aa..ecdbbdd 100644 --- a/tests/Resources/ImageResource.php +++ b/tests/Resources/ImageResource.php @@ -7,6 +7,9 @@ use Illuminate\Http\Request; use TiMacDonald\JsonApi\JsonApiResource; +/** + * @mixin \Tests\Models\BasicModel + */ class ImageResource extends JsonApiResource { protected function toAttributes(Request $request): array diff --git a/tests/Resources/LicenseResource.php b/tests/Resources/LicenseResource.php index d4f1488..20015f9 100644 --- a/tests/Resources/LicenseResource.php +++ b/tests/Resources/LicenseResource.php @@ -7,6 +7,9 @@ use Illuminate\Http\Request; use TiMacDonald\JsonApi\JsonApiResource; +/** + * @mixin \Tests\Models\BasicModel + */ class LicenseResource extends JsonApiResource { protected function toAttributes(Request $request): array @@ -19,7 +22,7 @@ protected function toAttributes(Request $request): array protected function toRelationships(Request $request): array { return [ - 'user' => UserResource::make($this->user), + 'user' => fn () => UserResource::make($this->user), ]; } } diff --git a/tests/Resources/PostResource.php b/tests/Resources/PostResource.php index 38049c5..4cac1ea 100644 --- a/tests/Resources/PostResource.php +++ b/tests/Resources/PostResource.php @@ -7,6 +7,9 @@ use Illuminate\Http\Request; use TiMacDonald\JsonApi\JsonApiResource; +/** + * @mixin \Tests\Models\BasicModel + */ class PostResource extends JsonApiResource { protected function toAttributes(Request $request): array diff --git a/tests/Resources/UserResource.php b/tests/Resources/UserResource.php index b902371..0665ab0 100644 --- a/tests/Resources/UserResource.php +++ b/tests/Resources/UserResource.php @@ -9,6 +9,9 @@ use TiMacDonald\JsonApi\JsonApiResource; use TiMacDonald\JsonApi\JsonApiResourceCollection; +/** + * @mixin \Tests\Models\BasicModel + */ class UserResource extends JsonApiResource { protected function toAttributes(Request $request): array diff --git a/vendor-bin/linting/composer.json b/vendor-bin/linting/composer.json new file mode 100644 index 0000000..9aa47bd --- /dev/null +++ b/vendor-bin/linting/composer.json @@ -0,0 +1,7 @@ +{ + "require": { + "nunomaduro/larastan": "^1.0", + "friendsofphp/php-cs-fixer": "^3.3", + "orchestra/testbench": "^6.0" + } +} diff --git a/vendor-bin/testing/composer.json b/vendor-bin/testing/composer.json new file mode 100644 index 0000000..805e96a --- /dev/null +++ b/vendor-bin/testing/composer.json @@ -0,0 +1,8 @@ +{ + "require": { + "phpunit/phpunit": "^9.5", + "mockery/mockery": "^1.3.3", + "orchestra/testbench": "^6.0", + "infection/infection": "^0.25.4" + } +} From 254cdb91d1b181205aa3d1b4af586a01d164a5b4 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Fri, 10 Dec 2021 18:52:01 +1100 Subject: [PATCH 2/2] add version support --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index a2b9528..8b6cecd 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,11 @@ A lightweight JSON Resource for Laravel that helps you adhere to the JSON:API st These docs are not designed to introduce you to the JSON:API spec and the associated concepts, instead you should [head over and read the spec](https:/jsonapi.org) if you are not familiar with it. +# Version support + +- **PHP**: 7.4, 8.0, 8.1 +- **Laravel**: 8.0 + # Installation You can install using [composer](https://getcomposer.org/) from [Packagist](https://packagist.org/packages/timacdonald/json-api).