From 93ccd7d4669a28c749165fbd6e7dba613bf63be4 Mon Sep 17 00:00:00 2001 From: Jamie Schouten Date: Wed, 3 Apr 2024 22:06:49 +0200 Subject: [PATCH] Add Laravel 11 support (#12) * Add Laravel 11 support * Remove unused dependencies * Increase phpstan level. * Remove Windows from test matrix --- .github/workflows/run-tests.yml | 9 ++++++--- composer.json | 15 +++------------ phpstan.neon.dist | 6 +----- src/XhprofServiceProvider.php | 12 ++++++++++-- src/middleware/XhprofProfiler.php | 2 +- 5 files changed, 21 insertions(+), 23 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index d3cc1c5..941b45a 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -12,14 +12,17 @@ jobs: strategy: fail-fast: true matrix: - os: [ubuntu-latest, windows-latest] - php: [8.2, 8.1] - laravel: [10.*] + os: [ubuntu-latest] + php: [8.2] + laravel: [10.*, 11.*] stability: [prefer-lowest, prefer-stable] include: - laravel: 10.* testbench: 8.* carbon: ^2.63 + - laravel: 11.* + testbench: 9.* + carbon: ^2.72 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} diff --git a/composer.json b/composer.json index 05f9008..ce4f4da 100644 --- a/composer.json +++ b/composer.json @@ -18,22 +18,13 @@ ], "require": { "php": "^8.1", - "illuminate/contracts": "^10.0", - "spatie/laravel-package-tools": "^1.14.0", + "illuminate/contracts": "^10.0|^11.0", "spiral-packages/profiler": "^1.0" }, "require-dev": { "laravel/pint": "^1.0", - "nunomaduro/collision": "^7.8", - "nunomaduro/larastan": "^2.0.1", - "orchestra/testbench": "^8.8", - "pestphp/pest": "^2.20", - "pestphp/pest-plugin-arch": "^2.0", - "pestphp/pest-plugin-laravel": "^2.0", - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan-deprecation-rules": "^1.0", - "phpstan/phpstan-phpunit": "^1.0", - "spatie/laravel-ray": "^1.26" + "orchestra/testbench": "^8.8|^9.0", + "pestphp/pest": "^2.20" }, "autoload": { "psr-4": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 9914a5e..38e1e79 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,11 +2,7 @@ includes: - phpstan-baseline.neon parameters: - level: 4 + level: 8 paths: - src - tmpDir: build/phpstan - checkOctaneCompatibility: true - checkModelProperties: true - checkMissingIterableValueType: false diff --git a/src/XhprofServiceProvider.php b/src/XhprofServiceProvider.php index 5021df5..db823fb 100644 --- a/src/XhprofServiceProvider.php +++ b/src/XhprofServiceProvider.php @@ -9,6 +9,7 @@ use SpiralPackages\Profiler\Profiler; use SpiralPackages\Profiler\Storage\WebStorage; use Symfony\Component\HttpClient\NativeHttpClient; +use Throwable; class XhprofServiceProvider extends ServiceProvider { @@ -38,10 +39,13 @@ public function register(): void /** * Registers the XhprofProfiler middleware + * + * @throws Throwable */ protected function registerMiddleware(): void { - $kernel = $this->app[Kernel::class]; + /** @var \Illuminate\Foundation\Http\Kernel $kernel */ + $kernel = $this->app->get(Kernel::class); if ( method_exists($kernel, 'hasMiddleware') @@ -72,6 +76,10 @@ private function isEnabled(): bool return filter_var(request()->header(XhprofProfiler::HEADER), FILTER_VALIDATE_BOOLEAN); } - return config()->get('xhprof.enabled'); + try { + return config()->get('xhprof.enabled'); + } catch (Throwable) { + return false; + } } } diff --git a/src/middleware/XhprofProfiler.php b/src/middleware/XhprofProfiler.php index 057ff4e..e86c388 100644 --- a/src/middleware/XhprofProfiler.php +++ b/src/middleware/XhprofProfiler.php @@ -19,7 +19,7 @@ public function __construct(private readonly Profiler $profiler) /** * Handle an incoming request. * - * @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next + * @param Closure(Request): (Response) $next */ public function handle(Request $request, Closure $next): Response {