From 1ea2df019b5de9976e3a3be53b59cac57ee2614e Mon Sep 17 00:00:00 2001 From: Alexandre Gomes Gaigalas Date: Sat, 14 Mar 2026 21:45:39 -0300 Subject: [PATCH] Add PHPStan, PHPCS, and composer QA scripts Add static analysis (PHPStan level 1) and code style checking (PHPCS with respect/coding-standard) as dev dependencies. Configure composer scripts for phpcs, phpstan, phpunit, and qa. PHPStan ignores are set for magic method patterns (__callStatic, new static()) and known test quirks (duplicate array keys, property unsetting with hooks) that are by-design in this project. --- .gitignore | 3 ++- composer.json | 21 ++++++++++++++++++++- phpcs.xml.dist | 18 ++++++++++++++++++ phpstan.neon.dist | 11 +++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 phpcs.xml.dist create mode 100644 phpstan.neon.dist diff --git a/.gitignore b/.gitignore index 2ad28e1..69ae8d8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ /.couscous/ /vendor/ Makefile -.phpunit.result.cache \ No newline at end of file +.phpunit.result.cache +.phpcs.cache \ No newline at end of file diff --git a/composer.json b/composer.json index d87f263..6e131c8 100644 --- a/composer.json +++ b/composer.json @@ -14,18 +14,37 @@ "homepage": "https://github.com/Respect/Relational/graphs/contributors" } ], + "config": { + "sort-packages": true, + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } + }, "require": { "php": ">=8.5.0", "respect/data": "dev-master" }, "require-dev": { - "phpunit/phpunit": "^10.0" + "phpstan/phpstan": "^2.0", + "phpunit/phpunit": "^10.0", + "respect/coding-standard": "^5.0", + "squizlabs/php_codesniffer": "^4.0" }, "autoload": { "psr-4": { "Respect\\": "library/Respect" } }, + "scripts": { + "phpcs": "vendor/bin/phpcs", + "phpstan": "vendor/bin/phpstan analyze", + "phpunit": "vendor/bin/phpunit", + "qa": [ + "@phpcs", + "@phpstan", + "@phpunit" + ] + }, "extra": { "branch-alias": { "dev-master": "3.0-dev" diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..0572243 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,18 @@ + + + + + + + + + + library/ + tests/ + + + diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..6250649 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,11 @@ +parameters: + level: 1 + paths: + - library/ + - tests/ + ignoreErrors: + - message: '/Call to an undefined static method Respect\\Relational\\Sql::\w+\(\)\./' + - message: '/Call to an undefined static method Respect\\Data\\Collections\\(Collection|Filtered|Mix|Typed)::\w+\(\)\./' + - message: '/Unsafe usage of new static\(\)\./' + - message: '/Cannot unset property .+ because it might have hooks in a subclass\./' + - message: '/Array has \d+ duplicate keys/'