From a5cdce10a1b5abc894305b05f810d6904018aa94 Mon Sep 17 00:00:00 2001 From: Marcus Olsson Date: Tue, 10 Dec 2024 19:01:49 +0100 Subject: [PATCH 1/4] Add phpstan --- composer.json | 2 ++ phpstan.neon | 6 ++++++ 2 files changed, 8 insertions(+) create mode 100644 phpstan.neon diff --git a/composer.json b/composer.json index 83f288e..7c7091e 100644 --- a/composer.json +++ b/composer.json @@ -26,6 +26,7 @@ "orchestra/testbench": "^7.0 || ^8.0 || ^9.0", "pestphp/pest": "^1.0 || ^2.0", "pestphp/pest-plugin-laravel": "^1.2 || ^2.0", + "phpstan/phpstan": "^2.0", "phpunit/phpunit": "^9.0 || ^10.5" }, "minimum-stability": "dev", @@ -59,6 +60,7 @@ "scripts": { "phpfix": "vendor/bin/phpcbf --standard=\"PSR12\" ./src --ignore=./src/resources/*", "phpsniff": "vendor/bin/phpcs --standard=\"PSR12\" ./src --ignore=./src/resources/*", + "phpstan": "./vendor/bin/phpstan", "test": "vendor/bin/pest" } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..f5821d4 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,6 @@ +parameters: + level: 8 + paths: + - src + ignoreErrors: + - identifier: missingType.generics From 311f6917e6530741822bd8b226f6fd518642a745 Mon Sep 17 00:00:00 2001 From: Marcus Olsson Date: Tue, 10 Dec 2024 19:01:56 +0100 Subject: [PATCH 2/4] Fix return types --- src/Handlers/DefaultResponseHandler.php | 6 ++++-- src/Handlers/ResponseHandler.php | 4 +++- src/Http/Middleware/VeryBasicAuth.php | 7 ++++--- tests/Fixtures/CustomResponseHandler.php | 4 +++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Handlers/DefaultResponseHandler.php b/src/Handlers/DefaultResponseHandler.php index 07afa66..48df8d4 100644 --- a/src/Handlers/DefaultResponseHandler.php +++ b/src/Handlers/DefaultResponseHandler.php @@ -2,11 +2,13 @@ namespace Olssonm\VeryBasicAuth\Handlers; +use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Http\Response; class DefaultResponseHandler implements ResponseHandler { - public function __invoke(Request $request) + public function __invoke(Request $request): Response|JsonResponse { // Build header $header = [ @@ -30,6 +32,6 @@ public function __invoke(Request $request) } // Return default message - return response(config('very_basic_auth.error_message'), 401, $header); + return response()->make(config('very_basic_auth.error_message'), 401, $header); } } diff --git a/src/Handlers/ResponseHandler.php b/src/Handlers/ResponseHandler.php index cdc764d..e18d040 100644 --- a/src/Handlers/ResponseHandler.php +++ b/src/Handlers/ResponseHandler.php @@ -2,9 +2,11 @@ namespace Olssonm\VeryBasicAuth\Handlers; +use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Http\Response; interface ResponseHandler { - public function __invoke(Request $request); + public function __invoke(Request $request): Response|JsonResponse; } diff --git a/src/Http/Middleware/VeryBasicAuth.php b/src/Http/Middleware/VeryBasicAuth.php index b008f09..47932a1 100644 --- a/src/Http/Middleware/VeryBasicAuth.php +++ b/src/Http/Middleware/VeryBasicAuth.php @@ -3,13 +3,14 @@ namespace Olssonm\VeryBasicAuth\Http\Middleware; use Closure; +use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Olssonm\VeryBasicAuth\Handlers\ResponseHandler; use Symfony\Component\HttpFoundation\Response; class VeryBasicAuth { - protected $responseHandler; + protected ResponseHandler $responseHandler; public function __construct(ResponseHandler $responseHandler) { @@ -47,9 +48,9 @@ public function handle(Request $request, Closure $next, $username = null, $passw /** * Return a error response * - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse */ - private function deniedResponse(Request $request): Response + private function deniedResponse(Request $request): Response|JsonResponse { return ($this->responseHandler)($request); } diff --git a/tests/Fixtures/CustomResponseHandler.php b/tests/Fixtures/CustomResponseHandler.php index 7169aef..214345f 100644 --- a/tests/Fixtures/CustomResponseHandler.php +++ b/tests/Fixtures/CustomResponseHandler.php @@ -2,12 +2,14 @@ namespace Olssonm\VeryBasicAuth\Tests\Fixtures; +use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Http\Response; use Olssonm\VeryBasicAuth\Handlers\ResponseHandler; class CustomResponseHandler implements ResponseHandler { - public function __invoke(Request $request) + public function __invoke(Request $request): Response|JsonResponse { return response('Custom response', 401); } From f542d90f39100561640afacdb3cfa2ecd7c04173 Mon Sep 17 00:00:00 2001 From: Marcus Olsson Date: Tue, 10 Dec 2024 19:02:05 +0100 Subject: [PATCH 3/4] Update test-matrix --- .github/workflows/test.yml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 47fafe7..70bd159 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,20 +10,14 @@ jobs: strategy: matrix: - php: [8.3, 8.2, 8.1, 8.0] - laravel: [11.*, 10.*, 9.*] + php: [8.4, 8.3, 8.2, 8.1] + laravel: [11.*, 10.*] dependency-version: [prefer-lowest, prefer-stable] exclude: - laravel: 11.* php: 8.1 - - laravel: 11.* - php: 8.0 - laravel: 10.* - php: 8.0 - - laravel: 9.* - php: 8.3 - - laravel: 9.* - php: 8.2 + php: 8.4 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} From dfc5e2ab37db1a499536253e883485eacb4dffd0 Mon Sep 17 00:00:00 2001 From: Marcus Olsson Date: Tue, 10 Dec 2024 19:07:20 +0100 Subject: [PATCH 4/4] Skip prefer-lowest dependancy version --- .github/workflows/test.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 70bd159..131afc2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,14 +12,13 @@ jobs: matrix: php: [8.4, 8.3, 8.2, 8.1] laravel: [11.*, 10.*] - dependency-version: [prefer-lowest, prefer-stable] exclude: - - laravel: 11.* - php: 8.1 - - laravel: 10.* - php: 8.4 + - php: 8.1 + laravel: 11.* + - php: 8.4 + laravel: 10.* - name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} + name: P${{ matrix.php }} - L${{ matrix.laravel }} steps: - name: Checkout code @@ -36,7 +35,7 @@ jobs: - name: Install dependencies run: | composer require "illuminate/support:${{ matrix.laravel }}" --no-interaction --no-progress --no-suggest - composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-progress + composer update --prefer-dist --no-interaction --no-progress - name: Execute tests run: composer test