diff --git a/.gitattributes b/.gitattributes index c540470..12e8e4b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,10 +1,10 @@ * text=auto eol=lf -/tests export-ignore -.editorconfig export-ignore -.gitattributes export-ignore -.gitignore export-ignore -.php_cs export-ignore -.travis.yml export-ignore -phpcs.xml.dist export-ignore -phpunit.xml.dist export-ignore +/tests export-ignore +.editorconfig export-ignore +.gitattributes export-ignore +.gitignore export-ignore +.php-cs-fixer.php export-ignore +phpcs.xml export-ignore +phpunit.xml export-ignore +.phpstan.neon export-ignore diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index e361d1b..5d14a59 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -23,7 +23,7 @@ jobs: uses: actions/cache@v4 with: path: vendor - key: ${{ runner.os }}-php-${{ hashFiles('**/composer.json') }} + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} restore-keys: | ${{ runner.os }}-php- @@ -71,6 +71,3 @@ jobs: - name: Tests run: composer test - - - name: Tests coverage - run: composer coverage diff --git a/.gitignore b/.gitignore index 364d1a4..5ae8693 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ vendor composer.lock coverage *.cache +.idea +kit diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..90b12a3 --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,10 @@ +setFinder( + PhpCsFixer\Finder::create() + ->files() + ->name('*.php') + ->in(__DIR__.'/src') + ->in(__DIR__.'/tests') + ); \ No newline at end of file diff --git a/.phpstan.neon b/.phpstan.neon new file mode 100644 index 0000000..9045762 --- /dev/null +++ b/.phpstan.neon @@ -0,0 +1,6 @@ +parameters: + level: 8 + paths: + - src + - tests + inferPrivatePropertyTypeFromConstructor: true diff --git a/CHANGELOG.md b/CHANGELOG.md index 27bcc1f..d2586b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [2.2.0] - 2025-03-22 +### Added +- Improve support for PHP 8.4 and typying. + ## [2.1.2] - 2025-03-18 ### Fixed - Compatibility with PHP 8.4 @@ -88,6 +92,7 @@ First version [#12]: https://github.com/middlewares/debugbar/issues/12 [#17]: https://github.com/middlewares/debugbar/issues/17 +[2.2.0]: https://github.com/middlewares/debugbar/compare/v2.1.2...v2.2.0 [2.1.2]: https://github.com/middlewares/debugbar/compare/v2.1.1...v2.1.2 [2.1.1]: https://github.com/middlewares/debugbar/compare/v2.1.0...v2.1.1 [2.1.0]: https://github.com/middlewares/debugbar/compare/v2.0.1...v2.1.0 diff --git a/LICENSE b/LICENSE index 017c0cd..374fb13 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2019 +Copyright (c) 2019-2025 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index f7fe7bf..0cd757a 100644 --- a/README.md +++ b/README.md @@ -65,10 +65,10 @@ $debugbar = (new Middlewares\Debugbar())->inline(); Use this option to pass render options to the debugbar as an array. A list of available options can be found at https://github.com/php-debugbar/php-debugbar/blob/master/src/DebugBar/JavascriptRenderer.php#L132 -An example usage would be to pass a new location for the ``base_url`` so that you can rewrite the location of the files needed to render the debug bar. This can be used with symlinks, .htaccess or routes to the files to ensure the debugbar files are accessible. +An example usage would be to pass a new location for the `base_url` so that you can rewrite the location of the files needed to render the debug bar. This can be used with symlinks, .htaccess or routes to the files to ensure the debugbar files are accessible. ```php -$debugbar = (new Middlewares\Debugbar())->renderOptions(array('base_url' => "/MyProjectsSubDirectory/php-debugbar/php-debugbar/")); +$debugbar = (new Middlewares\Debugbar())->renderOptions(array('base_url' => "/MyProjectsSubDirectory/php-debugbar/php-debugbar")); ``` --- diff --git a/composer.json b/composer.json index df7895a..2cd9e93 100644 --- a/composer.json +++ b/composer.json @@ -17,15 +17,15 @@ }, "require": { "php": "^7.2 || ^8.0", - "middlewares/utils": "^3.0 || ^4.0", - "php-debugbar/php-debugbar": "^1.13", - "psr/http-server-middleware": "^1.0" + "php-debugbar/php-debugbar": "^1 || ^2", + "middlewares/utils": "^2 || ^3 || ^4", + "psr/http-server-middleware": "^1" }, "require-dev": { - "phpunit/phpunit": "^8|^9", - "friendsofphp/php-cs-fixer": "^3.0", - "squizlabs/php_codesniffer": "^3.0", - "oscarotero/php-cs-fixer-config": "^1 || ^2", + "phpunit/phpunit": "^8 || ^9", + "friendsofphp/php-cs-fixer": "^3", + "squizlabs/php_codesniffer": "^3", + "oscarotero/php-cs-fixer-config": "^2", "phpstan/phpstan": "^1 || ^2", "laminas/laminas-diactoros": "^2 || ^3" }, diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..7814331 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,16 @@ + + + Middlewares coding standard + + + + + + + + + + + src + tests + diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..270f0c0 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,33 @@ + + + + + tests + + + + + + ./src + + ./tests + ./vendor + + + + diff --git a/src/Debugbar.php b/src/Debugbar.php index e142032..41a5a4a 100644 --- a/src/Debugbar.php +++ b/src/Debugbar.php @@ -15,13 +15,16 @@ class Debugbar implements MiddlewareInterface { + /** + * @var array + */ private static $mimes = [ 'css' => 'text/css', 'js' => 'text/javascript', ]; /** - * @var Bar|null The debugbar + * The debugbar */ private $debugbar; @@ -36,27 +39,25 @@ class Debugbar implements MiddlewareInterface private $inline = false; /** - * @var array A rewrite of the root path for the loaded files + * @var array|null A rewrite of the root path for the loaded files */ private $renderOptions = null; - /** - * @var ResponseFactoryInterface - */ private $responseFactory; - /** - * @var StreamFactoryInterface - */ private $streamFactory; /** * Set the debug bar. + * + * @param Bar|null $debugbar + * @param ResponseFactoryInterface|null $responseFactory + * @param StreamFactoryInterface|null $streamFactory */ public function __construct( - Bar $debugbar = null, - ResponseFactoryInterface $responseFactory = null, - StreamFactoryInterface $streamFactory = null + ?Bar $debugbar = null, + ?ResponseFactoryInterface $responseFactory = null, + ?StreamFactoryInterface $streamFactory = null ) { $this->debugbar = $debugbar ?: new StandardDebugBar(); $this->responseFactory = $responseFactory ?: Factory::getResponseFactory(); @@ -65,8 +66,10 @@ public function __construct( /** * Set the roo path variable + * + * @param array $renderOptions */ - public function renderOptions(array $renderOptions = null): self + public function renderOptions(?array $renderOptions = null): self { $this->renderOptions = $renderOptions; @@ -98,7 +101,6 @@ public function inline(bool $inline = true): self */ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { - $renderer = $this->debugbar->getJavascriptRenderer(); if ($this->renderOptions) { $renderer->setOptions($this->renderOptions); diff --git a/tests/DebugbarTest.php b/tests/DebugbarTest.php index 7da0bd4..43b52b4 100644 --- a/tests/DebugbarTest.php +++ b/tests/DebugbarTest.php @@ -11,6 +11,9 @@ class DebugbarTest extends TestCase { + /** + * @return array> + */ public function debugBarProvider(): array { return [ @@ -23,8 +26,9 @@ public function debugBarProvider(): array /** * @dataProvider debugBarProvider + * @param array $headers */ - public function testDebugbar(string $contentType, array $headers, bool $expectedBody, bool $expectedHeader) + public function testDebugbar(string $contentType, array $headers, bool $expectedBody, bool $expectedHeader): void { $request = Factory::createServerRequest('GET', '/'); @@ -55,7 +59,7 @@ function () use ($contentType) { } } - public function testInline() + public function testInline(): void { $response = Dispatcher::run([ (new Debugbar())->inline(), @@ -73,7 +77,7 @@ function () { $this->assertNotFalse(strpos($body, '')); } - public function testAsset() + public function testAsset(): void { $debugbar = new StandardDebugBar(); $renderer = $debugbar->getJavascriptRenderer(); @@ -98,7 +102,7 @@ function () { /** * @runInSeparateProcess */ - public function testRedirection() + public function testRedirection(): void { session_start(); @@ -118,7 +122,7 @@ function () { $this->assertEquals(302, $response->getStatusCode()); } - public function testRenderOptions() + public function testRenderOptions(): void { $response = Dispatcher::run( [