Skip to content

Commit

Permalink
PHP 8.4 compat-check (#66)
Browse files Browse the repository at this point in the history
* Add phpstan

* Fix return types

* Update test-matrix

* Skip prefer-lowest dependancy version
  • Loading branch information
olssonm authored Dec 10, 2024
1 parent e20be0d commit ae2213c
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 23 deletions.
25 changes: 9 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,15 @@ jobs:

strategy:
matrix:
php: [8.3, 8.2, 8.1, 8.0]
laravel: [11.*, 10.*, 9.*]
dependency-version: [prefer-lowest, prefer-stable]
php: [8.4, 8.3, 8.2, 8.1]
laravel: [11.*, 10.*]
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

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}
- php: 8.1
laravel: 11.*
- php: 8.4
laravel: 10.*

name: P${{ matrix.php }} - L${{ matrix.laravel }}

steps:
- name: Checkout code
Expand All @@ -42,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
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
level: 8
paths:
- src
ignoreErrors:
- identifier: missingType.generics
6 changes: 4 additions & 2 deletions src/Handlers/DefaultResponseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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);
}
}
4 changes: 3 additions & 1 deletion src/Handlers/ResponseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
7 changes: 4 additions & 3 deletions src/Http/Middleware/VeryBasicAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion tests/Fixtures/CustomResponseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit ae2213c

Please sign in to comment.