From 1032b9f652b02f90d125854eb47378ab6c98313a Mon Sep 17 00:00:00 2001 From: horea Date: Mon, 10 Mar 2025 17:58:00 +0200 Subject: [PATCH 1/7] Issue #34: Replace Psalm with PHPStan Signed-off-by: horea --- .github/workflows/static-analysis.yml | 49 +++++++++++++++++++ README.md | 17 ++++--- composer.json | 17 ++++--- config/debugbar.local.php | 4 +- docs/book/index.md | 2 +- docs/book/v1/overview.md | 19 ++++++- mkdocs.yml | 2 +- phpstan.neon | 15 ++++++ psalm-baseline.xml | 10 ---- psalm.xml | 18 ------- src/ConfigProvider.php | 6 --- src/Extension/DebugBarExtension.php | 2 +- test/DebugBarTest.php | 14 +++--- test/Extension/DebugBarExtensionTest.php | 5 -- test/Factory/DebugBarExtensionFactoryTest.php | 2 +- test/Factory/DebugBarFactoryTest.php | 2 +- .../Factory/DebugBarMiddlewareFactoryTest.php | 2 +- test/Middleware/DebugBarMiddlewareTest.php | 4 +- 18 files changed, 118 insertions(+), 72 deletions(-) create mode 100644 .github/workflows/static-analysis.yml mode change 100644 => 120000 docs/book/index.md create mode 100644 phpstan.neon delete mode 100644 psalm-baseline.xml delete mode 100644 psalm.xml diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 0000000..2423564 --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,49 @@ +on: + - push + +name: Run PHPStan checks + +jobs: + mutation: + name: PHPStan ${{ matrix.php }}-${{ matrix.os }} + + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: + - ubuntu-latest + + php: + - "8.1" + - "8.2" + - "8.3" + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php }}" + coverage: pcov + ini-values: assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On + tools: composer:v2, cs2pr + + - name: Determine composer cache directory + run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + + - name: Cache dependencies installed with composer + uses: actions/cache@v4 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + php${{ matrix.php }}-composer- + + - name: Install dependencies with composer + run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - name: Run static analysis with PHPStan + run: vendor/bin/phpstan analyse diff --git a/README.md b/README.md index eb2e743..a9ab716 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,17 @@ # dot-debugbar -> [!IMPORTANT] +Dotkernel's debug bar component + > dot-debugbar is a wrapper on top of [maximebf/php-debugbar](https://github.com/maximebf/php-debugbar) -> -> ![OSS Lifecycle](https://img.shields.io/osslifecycle/maximebf/php-debugbar) -## dot-debugbar badges +## Documentation + +Documentation is available at: https://docs.dotkernel.org/dot-debugbar/. + +## Badges ![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-debugbar) -![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-debugbar/1.2.0) +![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-debugbar/1.3.0) [![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-debugbar)](https://github.com/dotkernel/dot-debugbar/issues) [![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-debugbar)](https://github.com/dotkernel/dot-debugbar/network) @@ -18,8 +21,8 @@ [![Build Static](https://github.com/dotkernel/dot-debugbar/actions/workflows/continuous-integration.yml/badge.svg?branch=1.0)](https://github.com/dotkernel/dot-debugbar/actions/workflows/continuous-integration.yml) [![codecov](https://codecov.io/gh/dotkernel/dot-debugbar/graph/badge.svg?token=F0N8VWKTDW)](https://codecov.io/gh/dotkernel/dot-debugbar) [![docs-build](https://github.com/dotkernel/dot-debugbar/actions/workflows/docs-build.yml/badge.svg)](https://github.com/dotkernel/dot-debugbar/actions/workflows/docs-build.yml) +[![PHPStan](https://github.com/dotkernel/dot-debugbar/actions/workflows/static-analysis.yml/badge.svg?branch=1.0)](https://github.com/dotkernel/dot-debugbar/actions/workflows/static-analysis.yml) -[![SymfonyInsight](https://insight.symfony.com/projects/c1dc83af-a4b3-4a46-a80c-d87dff782089/big.svg)](https://insight.symfony.com/projects/c1dc83af-a4b3-4a46-a80c-d87dff782089) ## Install @@ -32,7 +35,7 @@ Install dot-debugbar in your application by running the following command: Once installed, the following components need to be registered by adding: * `$app->pipe(\Dot\DebugBar\Middleware\DebugBarMiddleware::class);` to `config/pipeline.php` (preferably after `ServerUrlMiddleware::class`) -* `\Dot\DebugBar\ConfigProvider::class,` to `config/config.php` (preferably at the beginning of the section where the `DotKernel packages` are loaded) +* `\Dot\DebugBar\ConfigProvider::class,` to `config/config.php` (preferably at the beginning of the section where the `Dotkernel packages` are loaded) * `\Dot\DebugBar\Extension\DebugBarExtension::class` to `config/autoload/templates.global.php` (inside the array founder under the key `twig` => `extensions`) Locate the library's assets directory, called `assets` and copy **its contents** to your application under `public/debugbar` directory. diff --git a/composer.json b/composer.json index f784fc0..b4aac88 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "dotkernel/dot-debugbar", - "description": "DotKernel's debug bar built on top of maximebf/debugbar", + "description": "Dotkernel's debug bar built on top of maximebf/debugbar", "type": "library", "license": "MIT", "homepage": "https://github.com/dotkernel/dot-debugbar", @@ -11,7 +11,7 @@ ], "authors": [ { - "name": "DotKernel Team", + "name": "Dotkernel Team", "email": "team@dotkernel.com" } ], @@ -44,19 +44,20 @@ } }, "require-dev": { - "laminas/laminas-coding-standard": "^2.5", - "phpunit/phpunit": "^10.5.7", - "vimeo/psalm": "^5.19.1" + "laminas/laminas-coding-standard": "^3.0", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^10.5.7" }, "scripts": { "check": [ "@cs-check", - "@test" + "@test", + "@static-analysis" ], "cs-check": "phpcs", "cs-fix": "phpcbf", "test": "phpunit --colors=always", - "test-coverage": "phpunit --colors=always --coverage-clover clover.xml", - "static-analysis": "psalm --shepherd --stats" + "static-analysis": "phpstan analyse --memory-limit 1G" } } diff --git a/config/debugbar.local.php b/config/debugbar.local.php index a15cc9d..13c0688 100644 --- a/config/debugbar.local.php +++ b/config/debugbar.local.php @@ -2,8 +2,10 @@ declare(strict_types=1); +use Dot\DebugBar\DebugBar; + return [ - Dot\DebugBar\DebugBar::class => [ + DebugBar::class => [ /** * Enable/Disable DebugBar */ diff --git a/docs/book/index.md b/docs/book/index.md deleted file mode 100644 index ae42a26..0000000 --- a/docs/book/index.md +++ /dev/null @@ -1 +0,0 @@ -../../README.md diff --git a/docs/book/index.md b/docs/book/index.md new file mode 120000 index 0000000..fe84005 --- /dev/null +++ b/docs/book/index.md @@ -0,0 +1 @@ +../../README.md \ No newline at end of file diff --git a/docs/book/v1/overview.md b/docs/book/v1/overview.md index 3b88947..0b93730 100644 --- a/docs/book/v1/overview.md +++ b/docs/book/v1/overview.md @@ -1,5 +1,20 @@ # Overview +Dotkernel's debug bar component + > dot-debugbar is a wrapper on top of [maximebf/php-debugbar](https://github.com/maximebf/php-debugbar) -> -> ![OSS Lifecycle](https://img.shields.io/osslifecycle/maximebf/php-debugbar) + +## Badges + +![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-debugbar) +![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-debugbar/1.3.0) + +[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-debugbar)](https://github.com/dotkernel/dot-debugbar/issues) +[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-debugbar)](https://github.com/dotkernel/dot-debugbar/network) +[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-debugbar)](https://github.com/dotkernel/dot-debugbar/stargazers) +[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-debugbar)](https://github.com/dotkernel/dot-debugbar/blob/1.0/LICENSE.md) + +[![Build Static](https://github.com/dotkernel/dot-debugbar/actions/workflows/continuous-integration.yml/badge.svg?branch=1.0)](https://github.com/dotkernel/dot-debugbar/actions/workflows/continuous-integration.yml) +[![codecov](https://codecov.io/gh/dotkernel/dot-debugbar/graph/badge.svg?token=F0N8VWKTDW)](https://codecov.io/gh/dotkernel/dot-debugbar) +[![docs-build](https://github.com/dotkernel/dot-debugbar/actions/workflows/docs-build.yml/badge.svg)](https://github.com/dotkernel/dot-debugbar/actions/workflows/docs-build.yml) +[![PHPStan](https://github.com/dotkernel/dot-debugbar/actions/workflows/static-analysis.yml/badge.svg?branch=1.0)](https://github.com/dotkernel/dot-debugbar/actions/workflows/static-analysis.yml) diff --git a/mkdocs.yml b/mkdocs.yml index 4050c1c..f5360a5 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -18,7 +18,7 @@ nav: - "Debug Doctrine queries": v1/usage/debug-doctrine-queries.md - "Debug Exceptions": v1/usage/debug-exceptions.md site_name: dot-debugbar -site_description: "DotKernel's debug bar component" +site_description: "Dotkernel's debug bar component" repo_url: "https://github.com/dotkernel/dot-debugbar" plugins: - search diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..3587a2e --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,15 @@ +includes: + - vendor/phpstan/phpstan-phpunit/extension.neon +parameters: + level: 5 + paths: + - src + - test + treatPhpDocTypesAsCertain: false + excludePaths: + - test/DummyResponse.php + ignoreErrors: + - message: '#Call to an undefined method .*::getJavascriptRenderer\(\)\.#' + path: src/Extension/DebugBarExtension.php + - message: '#.* is never read, only written.#' + path: src/DebugBar.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml deleted file mode 100644 index 45e60f8..0000000 --- a/psalm-baseline.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - getJavascriptRenderer - getJavascriptRenderer - getJavascriptRenderer - - - diff --git a/psalm.xml b/psalm.xml deleted file mode 100644 index 9dd8f07..0000000 --- a/psalm.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 749985b..171d662 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -13,9 +13,6 @@ class ConfigProvider { - /** - * @return array - */ public function __invoke(): array { return [ @@ -23,9 +20,6 @@ public function __invoke(): array ]; } - /** - * @return array - */ public function getDependencyConfig(): array { return [ diff --git a/src/Extension/DebugBarExtension.php b/src/Extension/DebugBarExtension.php index ee2bb66..4c5668c 100644 --- a/src/Extension/DebugBarExtension.php +++ b/src/Extension/DebugBarExtension.php @@ -14,7 +14,7 @@ class DebugBarExtension extends AbstractExtension { - private ?string $baseUrl; + private ?string $baseUrl = null; private DebugBarInterface $debugBar; public function __construct(DebugBarInterface $debugBar, string $baseUrl) diff --git a/test/DebugBarTest.php b/test/DebugBarTest.php index 9a1d2c9..41e13c3 100644 --- a/test/DebugBarTest.php +++ b/test/DebugBarTest.php @@ -22,7 +22,7 @@ public function testCanCreate(): void { $configuration = $this->createMock(Configuration::class); $dotDebugBar = new DebugBar($configuration, $this->config); - $this->assertInstanceOf(DebugBar::class, $dotDebugBar); + $this->assertSame(DebugBar::class, $dotDebugBar::class); } /** @@ -135,10 +135,10 @@ public function testWillToggle(): void $dotDebugBar = new DebugBar($configuration, $this->config); $this->assertFalse($dotDebugBar->isEnabled()); $dotDebugBar->enable(); - $this->assertInstanceOf(DebugBar::class, $dotDebugBar); + $this->assertSame(DebugBar::class, $dotDebugBar::class); $this->assertTrue($dotDebugBar->isEnabled()); $dotDebugBar->disable(); - $this->assertInstanceOf(DebugBar::class, $dotDebugBar); + $this->assertSame(DebugBar::class, $dotDebugBar::class); $this->assertFalse($dotDebugBar->isEnabled()); } @@ -152,7 +152,7 @@ public function testWillAddMessage(): void $dotDebugBar = new DebugBar($configuration, $this->config); $this->assertCount(0, $dotDebugBar->getMessagesCollector()->getMessages()); $dotDebugBar->addMessage('test'); - $this->assertInstanceOf(DebugBar::class, $dotDebugBar); + $this->assertSame(DebugBar::class, $dotDebugBar::class); $this->assertCount(1, $dotDebugBar->getMessagesCollector()->getMessages()); } @@ -166,10 +166,10 @@ public function testWillStartStopMeasureTimer(): void $dotDebugBar = new DebugBar($configuration, $this->config); $this->assertFalse($dotDebugBar->getTimeDataCollector()->hasStartedMeasure('test')); $dotDebugBar->startTimer('test'); - $this->assertInstanceOf(DebugBar::class, $dotDebugBar); + $this->assertSame(DebugBar::class, $dotDebugBar::class); $this->assertTrue($dotDebugBar->getTimeDataCollector()->hasStartedMeasure('test')); $dotDebugBar->stopTimer('test'); - $this->assertInstanceOf(DebugBar::class, $dotDebugBar); + $this->assertSame(DebugBar::class, $dotDebugBar::class); $this->assertFalse($dotDebugBar->getTimeDataCollector()->hasStartedMeasure('test')); } @@ -183,7 +183,7 @@ public function testWillAddThrowable(): void $dotDebugBar = new DebugBar($configuration, $this->config); $this->assertCount(0, $dotDebugBar->getExceptionsCollector()->getExceptions()); $dotDebugBar->addThrowable(new \Exception('test')); - $this->assertInstanceOf(DebugBar::class, $dotDebugBar); + $this->assertSame(DebugBar::class, $dotDebugBar::class); $this->assertCount(1, $dotDebugBar->getExceptionsCollector()->getExceptions()); } } diff --git a/test/Extension/DebugBarExtensionTest.php b/test/Extension/DebugBarExtensionTest.php index 980e982..f0aaeae 100644 --- a/test/Extension/DebugBarExtensionTest.php +++ b/test/Extension/DebugBarExtensionTest.php @@ -17,11 +17,6 @@ class DebugBarExtensionTest extends TestCase { use CommonTrait; - public function testConstructor(): void - { - $this->assertNull(null); - } - /** * @throws Exception */ diff --git a/test/Factory/DebugBarExtensionFactoryTest.php b/test/Factory/DebugBarExtensionFactoryTest.php index ee975b2..07e00f7 100644 --- a/test/Factory/DebugBarExtensionFactoryTest.php +++ b/test/Factory/DebugBarExtensionFactoryTest.php @@ -98,6 +98,6 @@ public function testWillCreateExtension(): void ]); $extension = (new DebugBarExtensionFactory())($container); - $this->assertInstanceOf(DebugBarExtension::class, $extension); + $this->assertContainsOnlyInstancesOf(DebugBarExtension::class, [$extension]); } } diff --git a/test/Factory/DebugBarFactoryTest.php b/test/Factory/DebugBarFactoryTest.php index c486461..51b95c4 100644 --- a/test/Factory/DebugBarFactoryTest.php +++ b/test/Factory/DebugBarFactoryTest.php @@ -214,6 +214,6 @@ public function testWillCreateService(): void $connection->expects($this->once())->method('getConfiguration')->willReturn($configuration); $service = (new DebugBarFactory())($container); - $this->assertInstanceOf(DebugBarInterface::class, $service); + $this->assertContainsOnlyInstancesOf(DebugBarInterface::class, [$service]); } } diff --git a/test/Factory/DebugBarMiddlewareFactoryTest.php b/test/Factory/DebugBarMiddlewareFactoryTest.php index df7ee15..8967c17 100644 --- a/test/Factory/DebugBarMiddlewareFactoryTest.php +++ b/test/Factory/DebugBarMiddlewareFactoryTest.php @@ -78,6 +78,6 @@ public function testWillCreateMiddleware(): void ]); $middleware = (new DebugBarMiddlewareFactory())($container); - $this->assertInstanceOf(DebugBarMiddlewareInterface::class, $middleware); + $this->assertContainsOnlyInstancesOf(DebugBarMiddlewareInterface::class, [$middleware]); } } diff --git a/test/Middleware/DebugBarMiddlewareTest.php b/test/Middleware/DebugBarMiddlewareTest.php index a895b68..32a197a 100644 --- a/test/Middleware/DebugBarMiddlewareTest.php +++ b/test/Middleware/DebugBarMiddlewareTest.php @@ -25,7 +25,7 @@ public function testCanCreateMiddleware(): void { $debugBar = $this->createMock(DebugBarInterface::class); $middleware = new DebugBarMiddleware($debugBar, new DummyResponse()); - $this->assertInstanceOf(DebugBarMiddlewareInterface::class, $middleware); + $this->assertContainsOnlyInstancesOf(DebugBarMiddlewareInterface::class, [$middleware]); } /** @@ -45,7 +45,7 @@ public function testCanProcess(): void $middleware = new DebugBarMiddleware($debugBar, new DummyResponse()); $response = $middleware->process($request, $handler); - $this->assertInstanceOf(ResponseInterface::class, $response); + $this->assertContainsOnlyInstancesOf(ResponseInterface::class, [$response]); } /** From 839c10d7ada20e25f35b9da01346f77805538716 Mon Sep 17 00:00:00 2001 From: horea Date: Mon, 10 Mar 2025 17:59:51 +0200 Subject: [PATCH 2/7] Issue #34: Replace Psalm with PHPStan Signed-off-by: horea --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index a9ab716..7437e7d 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,6 @@ Documentation is available at: https://docs.dotkernel.org/dot-debugbar/. [![docs-build](https://github.com/dotkernel/dot-debugbar/actions/workflows/docs-build.yml/badge.svg)](https://github.com/dotkernel/dot-debugbar/actions/workflows/docs-build.yml) [![PHPStan](https://github.com/dotkernel/dot-debugbar/actions/workflows/static-analysis.yml/badge.svg?branch=1.0)](https://github.com/dotkernel/dot-debugbar/actions/workflows/static-analysis.yml) - ## Install Install dot-debugbar in your application by running the following command: From 02c5d67602ef8e8b6331989af9f0e40319c7419a Mon Sep 17 00:00:00 2001 From: horea Date: Tue, 11 Mar 2025 16:50:43 +0200 Subject: [PATCH 3/7] Issue #34: Replace Psalm with PHPStan Signed-off-by: horea --- LICENSE.md | 2 +- README.md | 76 ++++++++++++++++++++++++++++++------------- composer.json | 2 +- docs/book/v1/setup.md | 2 +- 4 files changed, 56 insertions(+), 26 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 5b73c90..f5a5fff 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 DotKernel +Copyright (c) 2021 Dotkernel 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 7437e7d..0e8e513 100644 --- a/README.md +++ b/README.md @@ -27,15 +27,26 @@ Documentation is available at: https://docs.dotkernel.org/dot-debugbar/. Install dot-debugbar in your application by running the following command: +```shell composer require dotkernel/dot-debugbar +``` ## Setup Once installed, the following components need to be registered by adding: -* `$app->pipe(\Dot\DebugBar\Middleware\DebugBarMiddleware::class);` to `config/pipeline.php` (preferably after `ServerUrlMiddleware::class`) -* `\Dot\DebugBar\ConfigProvider::class,` to `config/config.php` (preferably at the beginning of the section where the `Dotkernel packages` are loaded) -* `\Dot\DebugBar\Extension\DebugBarExtension::class` to `config/autoload/templates.global.php` (inside the array founder under the key `twig` => `extensions`) +```php +$app->pipe(\Dot\DebugBar\Middleware\DebugBarMiddleware::class); +``` +to `config/pipeline.php` (preferably after `ServerUrlMiddleware::class`) +```php +\Dot\DebugBar\ConfigProvider::class +``` +to `config/config.php` (preferably at the beginning of the section where the `Dotkernel packages` are loaded) +```php +\Dot\DebugBar\Extension\DebugBarExtension::class +``` +to `config/autoload/templates.global.php` (inside the array founder under the key `twig` => `extensions`) Locate the library's assets directory, called `assets` and copy **its contents** to your application under `public/debugbar` directory. @@ -54,8 +65,15 @@ For more configuration values, follow the link in the related comment block. At this step, dot-debugbar is not displayed yet. In order to display it, you need to call the following Twig functions from your base layout: -* `{{ debugBarCss()|raw }}` (needs to be placed in the head section of the layout, where the CSS files are included) -* `{{ debugBarJs()|raw }}` (needs to be placed in the footer of the layout, where the JS files are included) +```Twig +{{ debugBarCss()|raw }} +``` +(needs to be placed in the head section of the layout, where the CSS files are included) + +```Twig +{{ debugBarJs()|raw }} +``` +(needs to be placed in the footer of the layout, where the JS files are included) If you plan to enable dot-debugbar on production, make sure you clear the relevant cache items by deleting: @@ -71,7 +89,9 @@ Other than the data being automatically collected during a session, dot-debugbar When you need an instance of DebugBar, locate an instance of it in your application's container using: - $debugBar = $container->get(\Dot\DebugBar\DebugBar::class); +```php +$debugBar = $container->get(\Dot\DebugBar\DebugBar::class); +``` then your factory can inject `$debugBar` as a dependency in your class. @@ -88,19 +108,23 @@ Results will show up in the debug bar under the `Messages` tab. Log messages (can be of any type): - $this->debugBar->addMessage(1); - $this->debugBar->addMessage(true); - $this->debugBar->addMessage('foo'); - $this->debugBar->addMessage(['foo']); - $this->debugBar->addMessage(new \stdClass()); +```php +$this->debugBar->addMessage(1); +$this->debugBar->addMessage(true); +$this->debugBar->addMessage('foo'); +$this->debugBar->addMessage(['foo']); +$this->debugBar->addMessage(new \stdClass()); +``` Log messages and set custom label by specifying the 2nd argument (you can use any label, but `error` and `warning` use custom highlight and icons): - $exception = new \Exception('something went wrong'); - $this->debugBar->addMessage($exception, 'error'); - $this->debugBar->addMessage($exception->getMessage(), 'error'); - $this->debugBar->addMessage('some warning', 'warning'); - $this->debugBar->addMessage('custom message', 'custom'); +```php +$exception = new \Exception('something went wrong'); +$this->debugBar->addMessage($exception, 'error'); +$this->debugBar->addMessage($exception->getMessage(), 'error'); +$this->debugBar->addMessage('some warning', 'warning'); +$this->debugBar->addMessage('custom message', 'custom'); +``` Also, clicking on a label (found on the bottom right of the debugbar) will toggle the visibility of all messages with that specific label. @@ -110,15 +134,19 @@ Results will show up in the debug bar under the `Timeline` tab. In order to measure how long does it take for a piece of code to execute, do the following: - $this->debugBar->measure('long operation', function () { - // your code here - }); +```php +$this->debugBar->measure('long operation', function () { + // your code here +}); +``` OR - $this->debugBar->startTimer('long operation', 'measuring long operation'); - // your code here - $this->debugBar->stopTimer('long operation'); +```php +$this->debugBar->startTimer('long operation', 'measuring long operation'); +// your code here +$this->debugBar->stopTimer('long operation'); +``` ### Debug Doctrine queries @@ -127,7 +155,9 @@ Results will show up in the debug bar under the `Database` tab. By default, all queries executed in order to load a page will be logged and displayed under this tab. If you submit a form that will perform a redirect, you won't see the executed CREATE/UPDATE queries unless you stack the collected data: - $this->debugBar->stackData(); +```php +$this->debugBar->stackData(); +``` The method needs to be called after all database operations have finished AND before emitting the redirect response. In this case, next to the `Memory usage` widget you'll see a dropdown that allows you to select between the previous page load (with the redirect) and the current one. diff --git a/composer.json b/composer.json index b4aac88..f1238b3 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ "mezzio/mezzio": "^3.18.0", "psr/container": "^1.1.2", "psr/http-message": "^1.1.0", - "twig/twig": "v3.14.0" + "twig/twig": "v3.19.0" }, "autoload-dev": { "psr-4": { diff --git a/docs/book/v1/setup.md b/docs/book/v1/setup.md index 79325e0..cf85b18 100644 --- a/docs/book/v1/setup.md +++ b/docs/book/v1/setup.md @@ -3,7 +3,7 @@ Once installed, the following components need to be registered by adding: * `$app->pipe(\Dot\DebugBar\Middleware\DebugBarMiddleware::class);` to `config/pipeline.php` (preferably after `ServerUrlMiddleware::class`) -* `\Dot\DebugBar\ConfigProvider::class,` to `config/config.php` (preferably at the beginning of the section where the `DotKernel packages` are loaded) +* `\Dot\DebugBar\ConfigProvider::class,` to `config/config.php` (preferably at the beginning of the section where the `Dotkernel packages` are loaded) * `\Dot\DebugBar\Extension\DebugBarExtension::class` to `config/autoload/templates.global.php` (inside the array founder under the key `twig` => `extensions`) Locate the library's assets directory, called `assets` and copy **its contents** to your application under `public/debugbar` directory. From 5abe9d188dda446c5cfa289c0a9a8a90ee2c2bc7 Mon Sep 17 00:00:00 2001 From: horea Date: Tue, 11 Mar 2025 16:53:57 +0200 Subject: [PATCH 4/7] Issue #34: Replace Psalm with PHPStan Signed-off-by: horea --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 0e8e513..d9c292e 100644 --- a/README.md +++ b/README.md @@ -38,14 +38,19 @@ Once installed, the following components need to be registered by adding: ```php $app->pipe(\Dot\DebugBar\Middleware\DebugBarMiddleware::class); ``` + to `config/pipeline.php` (preferably after `ServerUrlMiddleware::class`) + ```php \Dot\DebugBar\ConfigProvider::class ``` + to `config/config.php` (preferably at the beginning of the section where the `Dotkernel packages` are loaded) + ```php \Dot\DebugBar\Extension\DebugBarExtension::class ``` + to `config/autoload/templates.global.php` (inside the array founder under the key `twig` => `extensions`) Locate the library's assets directory, called `assets` and copy **its contents** to your application under `public/debugbar` directory. From 6104301795160db0cae89a7398406a02ac27042a Mon Sep 17 00:00:00 2001 From: horea Date: Tue, 11 Mar 2025 16:57:31 +0200 Subject: [PATCH 5/7] Issue #34: Replace Psalm with PHPStan Signed-off-by: horea --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d9c292e..fc9bf65 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Once installed, the following components need to be registered by adding: ```php $app->pipe(\Dot\DebugBar\Middleware\DebugBarMiddleware::class); -``` +``` to `config/pipeline.php` (preferably after `ServerUrlMiddleware::class`) @@ -73,11 +73,13 @@ At this step, dot-debugbar is not displayed yet. In order to display it, you nee ```Twig {{ debugBarCss()|raw }} ``` + (needs to be placed in the head section of the layout, where the CSS files are included) ```Twig {{ debugBarJs()|raw }} ``` + (needs to be placed in the footer of the layout, where the JS files are included) If you plan to enable dot-debugbar on production, make sure you clear the relevant cache items by deleting: From e7926b0949e2f835beca9ed910b0ed521a4b2292 Mon Sep 17 00:00:00 2001 From: horea Date: Tue, 11 Mar 2025 17:12:56 +0200 Subject: [PATCH 6/7] Issue #34: Replace Psalm with PHPStan Signed-off-by: horea --- README.md | 2 +- docs/book/v1/installation.md | 4 +++- docs/book/v1/setup.md | 35 ++++++++++++++++++++++++++++++----- docs/book/v1/usage.md | 4 +++- 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index fc9bf65..c40d729 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ At this step, dot-debugbar is not displayed yet. In order to display it, you nee (needs to be placed in the head section of the layout, where the CSS files are included) -```Twig +```twig {{ debugBarJs()|raw }} ``` diff --git a/docs/book/v1/installation.md b/docs/book/v1/installation.md index 9331c94..8220b3e 100644 --- a/docs/book/v1/installation.md +++ b/docs/book/v1/installation.md @@ -2,4 +2,6 @@ Install `dotkernel/dot-debugbar` by executing the following Composer command: - composer require dotkernel/dot-debugbar +```shell +composer require dotkernel/dot-debugbar +``` diff --git a/docs/book/v1/setup.md b/docs/book/v1/setup.md index cf85b18..91d2225 100644 --- a/docs/book/v1/setup.md +++ b/docs/book/v1/setup.md @@ -2,9 +2,25 @@ Once installed, the following components need to be registered by adding: -* `$app->pipe(\Dot\DebugBar\Middleware\DebugBarMiddleware::class);` to `config/pipeline.php` (preferably after `ServerUrlMiddleware::class`) -* `\Dot\DebugBar\ConfigProvider::class,` to `config/config.php` (preferably at the beginning of the section where the `Dotkernel packages` are loaded) -* `\Dot\DebugBar\Extension\DebugBarExtension::class` to `config/autoload/templates.global.php` (inside the array founder under the key `twig` => `extensions`) +Once installed, the following components need to be registered by adding: + +```php +$app->pipe(\Dot\DebugBar\Middleware\DebugBarMiddleware::class); +``` + +to `config/pipeline.php` (preferably after `ServerUrlMiddleware::class`) + +```php +\Dot\DebugBar\ConfigProvider::class +``` + +to `config/config.php` (preferably at the beginning of the section where the `Dotkernel packages` are loaded) + +```php +\Dot\DebugBar\Extension\DebugBarExtension::class +``` + +to `config/autoload/templates.global.php` (inside the array founder under the key `twig` => `extensions`) Locate the library's assets directory, called `assets` and copy **its contents** to your application under `public/debugbar` directory. @@ -26,8 +42,17 @@ For more configuration values, follow the link in the related comment block. At this step, dot-debugbar is not displayed yet. In order to display it, you need to call the following Twig functions from your base layout: -* `{{ debugBarCss()|raw }}` (needs to be placed in the head section of the layout, where the CSS files are included) -* `{{ debugBarJs()|raw }}` (needs to be placed in the footer of the layout, where the JS files are included) +```twig +{{ debugBarCss()|raw }} +``` + +(needs to be placed in the head section of the layout, where the CSS files are included) + +```twig +{{ debugBarJs()|raw }} +``` + +(needs to be placed in the footer of the layout, where the JS files are included) If you plan to enable dot-debugbar on production, make sure you clear the relevant cache items by deleting: diff --git a/docs/book/v1/usage.md b/docs/book/v1/usage.md index 5088bd2..f3ce15f 100644 --- a/docs/book/v1/usage.md +++ b/docs/book/v1/usage.md @@ -4,7 +4,9 @@ Other than the data being automatically collected during a session, dot-debugbar When you need an instance of DebugBar, locate an instance of it in your application's container using: - $debugBar = $container->get(\Dot\DebugBar\DebugBar::class); +```php +$debugBar = $container->get(\Dot\DebugBar\DebugBar::class); +``` then your factory can inject `$debugBar` as a dependency in your class. From 238f6460b638b5ff3daa837b55ed56e790edc3c6 Mon Sep 17 00:00:00 2001 From: horea Date: Wed, 12 Mar 2025 15:11:19 +0200 Subject: [PATCH 7/7] Issue #34: Replace Psalm with PHPStan Signed-off-by: horea --- README.md | 4 ++-- composer.json | 2 +- docs/book/v1/usage/debug-doctrine-queries.md | 2 +- docs/book/v1/usage/logging-messages.md | 20 ++++++++++---------- docs/book/v1/usage/measure-durations.md | 12 ++++++------ 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index c40d729..1dfb37b 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Documentation is available at: https://docs.dotkernel.org/dot-debugbar/. Install dot-debugbar in your application by running the following command: ```shell - composer require dotkernel/dot-debugbar +composer require dotkernel/dot-debugbar ``` ## Setup @@ -70,7 +70,7 @@ For more configuration values, follow the link in the related comment block. At this step, dot-debugbar is not displayed yet. In order to display it, you need to call the following Twig functions from your base layout: -```Twig +```twig {{ debugBarCss()|raw }} ``` diff --git a/composer.json b/composer.json index f1238b3..28745c5 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ "mezzio/mezzio": "^3.18.0", "psr/container": "^1.1.2", "psr/http-message": "^1.1.0", - "twig/twig": "v3.19.0" + "twig/twig": "^v3.19.0" }, "autoload-dev": { "psr-4": { diff --git a/docs/book/v1/usage/debug-doctrine-queries.md b/docs/book/v1/usage/debug-doctrine-queries.md index 3ec9c77..0a1340d 100644 --- a/docs/book/v1/usage/debug-doctrine-queries.md +++ b/docs/book/v1/usage/debug-doctrine-queries.md @@ -6,7 +6,7 @@ By default, all queries executed in order to load a page will be logged and disp If you submit a form that will perform a redirect, you won't see the executed CREATE/UPDATE queries unless you stack the collected data: ```php - $this->debugBar->stackData(); +$this->debugBar->stackData(); ``` The method needs to be called after all database operations have finished AND before emitting the redirect response. diff --git a/docs/book/v1/usage/logging-messages.md b/docs/book/v1/usage/logging-messages.md index 1c33a06..764a486 100644 --- a/docs/book/v1/usage/logging-messages.md +++ b/docs/book/v1/usage/logging-messages.md @@ -5,21 +5,21 @@ Results will show up in the debug bar under the `Messages` tab. Log messages (can be of any type): ```php - $this->debugBar->addMessage(1); - $this->debugBar->addMessage(true); - $this->debugBar->addMessage('foo'); - $this->debugBar->addMessage(['foo']); - $this->debugBar->addMessage(new \stdClass()); +$this->debugBar->addMessage(1); +$this->debugBar->addMessage(true); +$this->debugBar->addMessage('foo'); +$this->debugBar->addMessage(['foo']); +$this->debugBar->addMessage(new \stdClass()); ``` Log messages and set custom label by specifying the 2nd argument (you can use any label, but `error` and `warning` use custom highlight and icons): ```php - $exception = new \Exception('something went wrong'); - $this->debugBar->addMessage($exception, 'error'); - $this->debugBar->addMessage($exception->getMessage(), 'error'); - $this->debugBar->addMessage('some warning', 'warning'); - $this->debugBar->addMessage('custom message', 'custom'); +$exception = new \Exception('something went wrong'); +$this->debugBar->addMessage($exception, 'error'); +$this->debugBar->addMessage($exception->getMessage(), 'error'); +$this->debugBar->addMessage('some warning', 'warning'); +$this->debugBar->addMessage('custom message', 'custom'); ``` Also, clicking on a label (found on the bottom right of the debugbar) will toggle the visibility of all messages with that specific label. diff --git a/docs/book/v1/usage/measure-durations.md b/docs/book/v1/usage/measure-durations.md index bb0884a..062d404 100644 --- a/docs/book/v1/usage/measure-durations.md +++ b/docs/book/v1/usage/measure-durations.md @@ -5,15 +5,15 @@ Results will show up in the debug bar under the `Timeline` tab. In order to measure how long does it take for a piece of code to execute, do the following: ```php - $this->debugBar->measure('long operation', function () { - // your code here - }); +$this->debugBar->measure('long operation', function () { + // your code here +}); ``` OR ```php - $this->debugBar->startTimer('long operation', 'measuring long operation'); - // your code here - $this->debugBar->stopTimer('long operation'); +$this->debugBar->startTimer('long operation', 'measuring long operation'); +// your code here +$this->debugBar->stopTimer('long operation'); ```