From dfdab2ab441fb009716e1229bcc21fef70ffc1b3 Mon Sep 17 00:00:00 2001 From: Filis Futsarov Date: Fri, 21 Mar 2025 20:10:19 +0100 Subject: [PATCH 1/6] php8.4 support among other improvements --- .gitattributes | 16 ++++++++-------- .github/workflows/main.yaml | 5 +---- .gitignore | 2 ++ .php-cs-fixer.php | 10 ++++++++++ .phpstan.neon | 6 ++++++ CHANGELOG.md | 10 ++++------ LICENSE | 2 +- README.md | 4 ++-- composer.json | 16 ++++++++-------- phpcs.xml | 16 ++++++++++++++++ phpunit.xml | 33 +++++++++++++++++++++++++++++++++ src/Debugbar.php | 28 +++++++++++++++------------- tests/DebugbarTest.php | 14 +++++++++----- 13 files changed, 115 insertions(+), 47 deletions(-) create mode 100644 .php-cs-fixer.php create mode 100644 .phpstan.neon create mode 100644 phpcs.xml create mode 100644 phpunit.xml diff --git a/.gitattributes b/.gitattributes index c540470..b67c7ca 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.dist export-ignore +phpunit.xml.dist 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..0561872 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,9 @@ 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.1.2] - 2025-03-18 -### Fixed -- Compatibility with PHP 8.4 -- Updated dependencies [#17]. +## [2.2.0] - 2025-03-21 +### Added +- Support for PHP 8.4 ## [2.1.1] - 2024-03-21 ### Fixed @@ -86,9 +85,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). First version [#12]: https://github.com/middlewares/debugbar/issues/12 -[#17]: https://github.com/middlewares/debugbar/issues/17 -[2.1.2]: https://github.com/middlewares/debugbar/compare/v2.1.1...v2.1.2 +[2.2.0]: https://github.com/middlewares/debugbar/compare/v2.1.1...v2.2.0 [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 [2.0.1]: https://github.com/middlewares/debugbar/compare/v2.0.0...v2.0.1 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..919008d 100644 --- a/README.md +++ b/README.md @@ -63,12 +63,12 @@ $debugbar = (new Middlewares\Debugbar())->inline(); ``` ### renderOptions -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 +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/maximebf/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. ```php -$debugbar = (new Middlewares\Debugbar())->renderOptions(array('base_url' => "/MyProjectsSubDirectory/php-debugbar/php-debugbar/")); +$debugbar = (new Middlewares\Debugbar())->renderOptions(array('base_url' => "/MyProjectsSubDirectory/maximebf/debugbar/")); ``` --- diff --git a/composer.json b/composer.json index df7895a..3185c6c 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" + "maximebf/debugbar": "^1.13", + "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" }, @@ -47,4 +47,4 @@ "coverage": "phpunit --coverage-text", "coverage-html": "phpunit --coverage-html=coverage" } -} +} \ No newline at end of file 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( [ From ecfc6f3d839f329374d503f790f218468c31bbe5 Mon Sep 17 00:00:00 2001 From: Filis Futsarov Date: Sun, 23 Mar 2025 19:25:50 +0000 Subject: [PATCH 2/6] Update CHANGELOG.md --- CHANGELOG.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0561872..519884b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,15 @@ 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-21 +## [2.2.0] - 2025-03-22 ### Added - Support for PHP 8.4 +## [2.1.2] - 2025-03-18 +### Fixed +- Compatibility with PHP 8.4 +- Updated dependencies [#17]. + ## [2.1.1] - 2024-03-21 ### Fixed - Allow middlewares/utils 4.0 @@ -86,7 +91,8 @@ First version [#12]: https://github.com/middlewares/debugbar/issues/12 -[2.2.0]: https://github.com/middlewares/debugbar/compare/v2.1.1...v2.2.0 +[2.2.0]: https://github.com/middlewares/debugbar/compare/v2.1.3...v2.2.0 +[2.1.3]: https://github.com/middlewares/debugbar/compare/v2.1.1...v2.1.3 [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 [2.0.1]: https://github.com/middlewares/debugbar/compare/v2.0.0...v2.0.1 From b7182fa5a58b3abff18727a64a9df32db7face8e Mon Sep 17 00:00:00 2001 From: Filis Futsarov Date: Sun, 23 Mar 2025 19:27:41 +0000 Subject: [PATCH 3/6] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 519884b..73c9e70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [2.2.0] - 2025-03-22 ### Added -- Support for PHP 8.4 +- Improve support for PHP 8.4 and typying. ## [2.1.2] - 2025-03-18 ### Fixed From cf295b2f9499073746441c290199f851c319c8ed Mon Sep 17 00:00:00 2001 From: Filis Futsarov Date: Sun, 23 Mar 2025 19:33:46 +0000 Subject: [PATCH 4/6] Update CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73c9e70..6dae825 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -91,8 +91,8 @@ First version [#12]: https://github.com/middlewares/debugbar/issues/12 -[2.2.0]: https://github.com/middlewares/debugbar/compare/v2.1.3...v2.2.0 -[2.1.3]: https://github.com/middlewares/debugbar/compare/v2.1.1...v2.1.3 +[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 [2.0.1]: https://github.com/middlewares/debugbar/compare/v2.0.0...v2.0.1 From 9dd2829f69b36eceb669f21b924871ef83d8c046 Mon Sep 17 00:00:00 2001 From: Filis Futsarov Date: Sun, 23 Mar 2025 19:38:33 +0000 Subject: [PATCH 5/6] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dae825..d2586b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -90,6 +90,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). 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 From 602d3961dfe0673f886905cd20359b17dcff26a6 Mon Sep 17 00:00:00 2001 From: Filis Futsarov Date: Sun, 23 Mar 2025 20:47:07 +0100 Subject: [PATCH 6/6] update debugbar composer package --- .gitattributes | 4 ++-- README.md | 6 +++--- composer.json | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.gitattributes b/.gitattributes index b67c7ca..12e8e4b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,6 +5,6 @@ .gitattributes export-ignore .gitignore export-ignore .php-cs-fixer.php export-ignore -phpcs.xml.dist export-ignore -phpunit.xml.dist export-ignore +phpcs.xml export-ignore +phpunit.xml export-ignore .phpstan.neon export-ignore diff --git a/README.md b/README.md index 919008d..0cd757a 100644 --- a/README.md +++ b/README.md @@ -63,12 +63,12 @@ $debugbar = (new Middlewares\Debugbar())->inline(); ``` ### renderOptions -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/maximebf/php-debugbar/blob/master/src/DebugBar/JavascriptRenderer.php#L132 +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/maximebf/debugbar/")); +$debugbar = (new Middlewares\Debugbar())->renderOptions(array('base_url' => "/MyProjectsSubDirectory/php-debugbar/php-debugbar")); ``` --- diff --git a/composer.json b/composer.json index 3185c6c..2cd9e93 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ }, "require": { "php": "^7.2 || ^8.0", - "maximebf/debugbar": "^1.13", + "php-debugbar/php-debugbar": "^1 || ^2", "middlewares/utils": "^2 || ^3 || ^4", "psr/http-server-middleware": "^1" }, @@ -47,4 +47,4 @@ "coverage": "phpunit --coverage-text", "coverage-html": "phpunit --coverage-html=coverage" } -} \ No newline at end of file +}