From a24301379b5e5430ec05de5d4eac37c0ec54c734 Mon Sep 17 00:00:00 2001 From: Alexandre Gomes Gaigalas Date: Sat, 14 Mar 2026 21:42:49 -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, __call, new static()) that are by-design in this project. --- .gitignore | 3 ++- composer.json | 21 ++++++++++++++++++++- phpcs.xml.dist | 18 ++++++++++++++++++ phpstan.neon.dist | 9 +++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 phpcs.xml.dist create mode 100644 phpstan.neon.dist diff --git a/.gitignore b/.gitignore index a0bf9c4..bd0d78a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ composer.lock Makefile /vendor/ -.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 b88538e..0e683fc 100644 --- a/composer.json +++ b/composer.json @@ -14,17 +14,36 @@ "homepage": "https://github.com/Respect/Data/graphs/contributors" } ], + "config": { + "sort-packages": true, + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } + }, "require": { "php": ">=8.5" }, "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..e46b5b1 --- /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..863cf16 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,9 @@ +parameters: + level: 1 + paths: + - library/ + - tests/ + ignoreErrors: + - message: '/Call to an undefined static method Respect\\Data\\Collections\\(Collection|Filtered|Mix|Typed)::\w+\(\)\./' + - message: '/Call to an undefined method Respect\\Data\\AbstractMapper::\w+\(\)\./' + - message: '/Unsafe usage of new static\(\)\./'