From facb1e5fd4c925bfc3a1de106946ac515cb6d7c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Felix=20=C5=A0ulc?= Date: Fri, 13 Dec 2024 10:58:23 +0100 Subject: [PATCH] Readme: mention static analyses --- .docs/README.md | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/.docs/README.md b/.docs/README.md index 7dc0b29..56d1d62 100755 --- a/.docs/README.md +++ b/.docs/README.md @@ -15,6 +15,7 @@ Integration of [Doctrine ORM](https://www.doctrine-project.org/projects/orm.html - [Helper](#helper) - [DBAL](#dbal) - [Console](#console) +- [Static analyses](#static-analyses) - [Troubleshooting](#troubleshooting) - [Examples](#examples) @@ -386,6 +387,57 @@ Since this moment when you type `bin/console`, there'll be registered commands f ![Console Commands](https://raw.githubusercontent.com/nettrine/orm/master/.docs/assets/console.png) +## Static analyses + +You can use [PHPStan](https://github.com/phpstan) to analyze your code. + +1. Install PHPStan and Doctrine extension. + +```bash +composer require --dev phpstan/phpstan phpstan/phpstan-doctrine +``` + +2. Create ORM loader for PHPStan, e.q. `phpstan-doctrine.php`. + +```php +createContainer() + ->getByType(Doctrine\ORM\EntityManagerInterface::class); +``` + +3. Configure PHPStan in `phpstan.neon`. + +```neon +includes: + - vendor/phpstan/phpstan-doctrine/extension.neon + +parameters: + level: 9 + phpVersion: 80200 + + tmpDir: %currentWorkingDirectory%/var/tmp/phpstan + + fileExtensions: + - php + - phpt + + paths: + - app + + doctrine: + objectManagerLoader: phpstan-doctrine.php +``` + +4. And run PHPStan. + +```bash +vendor/bin/phpstan analyse -c phpstan.neon +``` + ## Troubleshooting 1. Are you looking for custom types? You can register custom types in DBAL, see [Nettrine DBAL](https://github.com/contributte/doctrine-dbal/blob/master/.docs/README.md#types).