From 5085c84fb839e4a0c1f4e0fc7653317f1d91d9d8 Mon Sep 17 00:00:00 2001 From: Julien Loizelet Date: Fri, 21 Nov 2025 18:25:34 +0900 Subject: [PATCH 1/3] feat(*): Handle deprecated warning for PHP 8.5 --- .github/workflows/coding-standards.yml | 1 + tests/PHPUnitUtil.php | 5 ++++- tools/coding-standards/composer.json | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 6658d0b..75c6b86 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -82,6 +82,7 @@ jobs: ddev composer update --working-dir ./${{env.EXTENSION_PATH}}/tools/coding-standards - name: Run PHPCS + if: contains(fromJson('["7.4","8.0","8.1","8.2","8.3", "8.4"]'),matrix.php-version) run: ddev phpcs ./${{env.EXTENSION_PATH}}/tools/coding-standards ${{env.EXTENSION_PATH}}/src PSR12 - name: Run PHPMD diff --git a/tests/PHPUnitUtil.php b/tests/PHPUnitUtil.php index fc3c6c6..4d1e6e7 100644 --- a/tests/PHPUnitUtil.php +++ b/tests/PHPUnitUtil.php @@ -22,7 +22,10 @@ public static function callMethod($obj, $name, array $args) { $class = new \ReflectionClass($obj); $method = $class->getMethod($name); - $method->setAccessible(true); + // setAccessible() is only needed for PHP < 8.1 and deprecated in PHP 8.5 + if (PHP_VERSION_ID < 80100) { + $method->setAccessible(true); + } return $method->invokeArgs($obj, $args); } diff --git a/tools/coding-standards/composer.json b/tools/coding-standards/composer.json index c35932d..051c784 100644 --- a/tools/coding-standards/composer.json +++ b/tools/coding-standards/composer.json @@ -4,8 +4,8 @@ "friendsofphp/php-cs-fixer": "^v3.8.0", "phpstan/phpstan": "^1.8.0", "phpmd/phpmd": "^2.12.0", - "squizlabs/php_codesniffer": "3.7.1", - "vimeo/psalm": "^4.24.0 || ^5.26", + "squizlabs/php_codesniffer": "3.7.1 || ^4.0.1", + "vimeo/psalm": "^4.24.0 || ^5.26 || ^6.13.1", "phpunit/phpunit": "^9.3", "phpunit/php-code-coverage": "^9.2.15", "mikey179/vfsstream": "^1.6.11", From aad13516890eaf3e7a6f5fc15ab039192a49bb07 Mon Sep 17 00:00:00 2001 From: julien Date: Fri, 6 Feb 2026 15:41:27 +0900 Subject: [PATCH 2/3] style(psalm): Fix psalm error for php 8.5 --- .github/workflows/coding-standards.yml | 4 +--- docs/DEVELOPER.md | 10 ++++++++-- src/Bouncer.php | 2 ++ src/Configuration.php | 1 + src/Configuration/Alert.php | 1 + src/Configuration/Alert/Decision.php | 1 + src/Configuration/Alert/Event.php | 1 + src/Configuration/Alert/Meta.php | 1 + src/Configuration/Alert/Source.php | 1 + src/Configuration/Metrics.php | 1 + src/Configuration/Metrics/Items.php | 2 ++ src/Configuration/Metrics/Meta.php | 1 + src/Configuration/Watcher.php | 2 ++ src/Payload/Alert.php | 2 ++ src/Watcher.php | 3 +++ tools/coding-standards/psalm/psalm.xml | 13 +++++++------ 16 files changed, 35 insertions(+), 11 deletions(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 3427d72..fe94617 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -27,7 +27,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ] + php-version: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ] name: Coding standards test runs-on: ubuntu-latest @@ -80,7 +80,6 @@ jobs: ddev composer update --working-dir ./${{env.EXTENSION_PATH}}/tools/coding-standards - name: Run PHPCS - if: contains(fromJson('["7.4","8.0","8.1","8.2","8.3", "8.4"]'),matrix.php-version) run: ddev phpcs ./${{env.EXTENSION_PATH}}/tools/coding-standards ${{env.EXTENSION_PATH}}/src PSR12 - name: Run PHPMD @@ -90,7 +89,6 @@ jobs: run: ddev phpstan /var/www/html/${{env.EXTENSION_PATH}}/tools/coding-standards phpstan/phpstan.neon /var/www/html/${{env.EXTENSION_PATH}}/src - name: Run PSALM - if: contains(fromJson('["7.4","8.0","8.1","8.2","8.3"]'),matrix.php-version) run: ddev psalm ./${{env.EXTENSION_PATH}}/tools/coding-standards /var/www/html/${{env.EXTENSION_PATH}}/tools/coding-standards/psalm - name: Run PHPUNIT Code Coverage diff --git a/docs/DEVELOPER.md b/docs/DEVELOPER.md index 784fbc1..9938a69 100644 --- a/docs/DEVELOPER.md +++ b/docs/DEVELOPER.md @@ -129,12 +129,18 @@ mkdir cfssl cp -r .ddev/okaeli-add-on/custom_files/crowdsec/cfssl/* cfssl ``` +Delete existing decisions: + +```bash +ddev exec -s crowdsec cscli alerts delete --all +``` + Finally, run In order to launch integration tests, we have to set some environment variables: ```bash -ddev exec BOUNCER_KEY= AGENT_TLS_PATH=/var/www/html/cfssl APPSEC_URL=http://crowdsec:7422 LAPI_URL=https://crowdsec:8080 php ./my-code/lapi-client/vendor/bin/phpunit ./my-code/lapi-client/tests/Integration --configuration ./my-code/lapi-client/tools/coding-standards/phpunit/phpunit.xml --testdox --exclude-group timeout +ddev exec BOUNCER_KEY= AGENT_TLS_PATH=/var/www/html/cfssl APPSEC_URL=http://crowdsec:7422 LAPI_URL=https://crowdsec:8080 php ./my-code/lapi-client/vendor/bin/phpunit --configuration ./my-code/lapi-client/tools/coding-standards/phpunit/phpunit.xml --testsuite Integration-Watcher,Integration-Bouncer --testdox --exclude-group timeout,appsec ``` `` should have been created and retrieved before this test by running `ddev create-bouncer`. @@ -143,7 +149,7 @@ If you need to test with a TLS authentication, you should launch: ```bash ddev exec BOUNCER_TLS_PATH=/var/www/html/cfssl BOUNCER_KEY= AGENT_TLS_PATH=/var/www/html/cfssl -APPSEC_URL=http://crowdsec:7422 LAPI_URL=https://crowdsec:8080 php ./my-code/lapi-client/vendor/bin/phpunit ./my-code/lapi-client/tests/Integration --testdox --exclude-group timeout +APPSEC_URL=http://crowdsec:7422 LAPI_URL=https://crowdsec:8080 php ./my-code/lapi-client/vendor/bin/phpunit --configuration ./my-code/lapi-client/tools/coding-standards/phpunit/phpunit.xml --testsuite Integration-Watcher,Integration-Bouncer --testdox --exclude-group timeout ``` #### Coding standards diff --git a/src/Bouncer.php b/src/Bouncer.php index 00aaf05..6f95099 100644 --- a/src/Bouncer.php +++ b/src/Bouncer.php @@ -14,6 +14,8 @@ * @copyright Copyright (c) 2022+ CrowdSec * @license MIT License * + * @psalm-api + * * @psalm-import-type TMetric from \CrowdSec\LapiClient\Metrics * @psalm-import-type TOS from \CrowdSec\LapiClient\Metrics * @psalm-import-type TMeta from \CrowdSec\LapiClient\Metrics diff --git a/src/Configuration.php b/src/Configuration.php index 3fa0190..d2b2634 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -60,6 +60,7 @@ class Configuration extends AbstractConfiguration * @throws \InvalidArgumentException * @throws \RuntimeException */ + #[\Override] public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('config'); diff --git a/src/Configuration/Alert.php b/src/Configuration/Alert.php index dc1cac2..6be754b 100644 --- a/src/Configuration/Alert.php +++ b/src/Configuration/Alert.php @@ -25,6 +25,7 @@ class Alert extends AbstractConfiguration 'remediation', ]; + #[\Override] public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('alert'); diff --git a/src/Configuration/Alert/Decision.php b/src/Configuration/Alert/Decision.php index 994d3a9..da168e1 100644 --- a/src/Configuration/Alert/Decision.php +++ b/src/Configuration/Alert/Decision.php @@ -20,6 +20,7 @@ class Decision extends AbstractConfiguration 'scenario', ]; + #[\Override] public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('decision'); diff --git a/src/Configuration/Alert/Event.php b/src/Configuration/Alert/Event.php index 293f42a..34c3fcb 100644 --- a/src/Configuration/Alert/Event.php +++ b/src/Configuration/Alert/Event.php @@ -15,6 +15,7 @@ class Event extends AbstractConfiguration 'timestamp', ]; + #[\Override] public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('event'); diff --git a/src/Configuration/Alert/Meta.php b/src/Configuration/Alert/Meta.php index 3a82f78..bc1fc9d 100644 --- a/src/Configuration/Alert/Meta.php +++ b/src/Configuration/Alert/Meta.php @@ -15,6 +15,7 @@ class Meta extends AbstractConfiguration 'value', ]; + #[\Override] public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('meta'); diff --git a/src/Configuration/Alert/Source.php b/src/Configuration/Alert/Source.php index 80d2e61..8a32d78 100644 --- a/src/Configuration/Alert/Source.php +++ b/src/Configuration/Alert/Source.php @@ -22,6 +22,7 @@ class Source extends AbstractConfiguration 'longitude', ]; + #[\Override] public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('source'); diff --git a/src/Configuration/Metrics.php b/src/Configuration/Metrics.php index 80f46ab..7cb0c50 100644 --- a/src/Configuration/Metrics.php +++ b/src/Configuration/Metrics.php @@ -36,6 +36,7 @@ class Metrics extends AbstractConfiguration * @throws \InvalidArgumentException * @throws \RuntimeException */ + #[\Override] public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('metricsConfig'); diff --git a/src/Configuration/Metrics/Items.php b/src/Configuration/Metrics/Items.php index e01a646..ff860df 100644 --- a/src/Configuration/Metrics/Items.php +++ b/src/Configuration/Metrics/Items.php @@ -32,6 +32,7 @@ class Items extends AbstractConfiguration * Keep only necessary configs * Override because $configs is an array of array (metrics item) and we want to clean each item. */ + #[\Override] public function cleanConfigs(array $configs): array { $result = []; @@ -46,6 +47,7 @@ public function cleanConfigs(array $configs): array * @throws \InvalidArgumentException * @throws \RuntimeException */ + #[\Override] public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('metricsItemsConfig'); diff --git a/src/Configuration/Metrics/Meta.php b/src/Configuration/Metrics/Meta.php index ee2e480..f16865d 100644 --- a/src/Configuration/Metrics/Meta.php +++ b/src/Configuration/Metrics/Meta.php @@ -30,6 +30,7 @@ class Meta extends AbstractConfiguration * @throws \InvalidArgumentException * @throws \RuntimeException */ + #[\Override] public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('metricsMetaConfig'); diff --git a/src/Configuration/Watcher.php b/src/Configuration/Watcher.php index 8c36d6f..19bf8b9 100644 --- a/src/Configuration/Watcher.php +++ b/src/Configuration/Watcher.php @@ -67,6 +67,7 @@ class Watcher extends Configuration * @throws \InvalidArgumentException * @throws \RuntimeException */ + #[\Override] public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = parent::getConfigTreeBuilder(); @@ -88,6 +89,7 @@ public function getConfigTreeBuilder(): TreeBuilder * @throws \InvalidArgumentException * @throws \RuntimeException */ + #[\Override] protected function validateApiKey($rootNode): void { $rootNode diff --git a/src/Payload/Alert.php b/src/Payload/Alert.php index ba3f491..eeefd3b 100644 --- a/src/Payload/Alert.php +++ b/src/Payload/Alert.php @@ -133,6 +133,7 @@ public function __construct( } /** + * @psalm-api * @param TAlertFull $data */ public static function fromArray(array $data): self @@ -186,6 +187,7 @@ public function toArray(): array * @return array */ #[\ReturnTypeWillChange] + #[\Override] public function jsonSerialize() { return $this->toArray(); diff --git a/src/Watcher.php b/src/Watcher.php index 7328bd7..e322803 100644 --- a/src/Watcher.php +++ b/src/Watcher.php @@ -18,6 +18,8 @@ * * If you use `auth_type = api_key` you must provide configs `machine_id` and `password`. * + * @psalm-api + * * @psalm-import-type TWatcherConfig from WatcherConfig * @psalm-import-type TAlertFull from \CrowdSec\LapiClient\Payload\Alert * @psalm-import-type TDecision from \CrowdSec\LapiClient\Payload\Alert @@ -210,6 +212,7 @@ public function getAlertById(int $id): ?array /** * @inheritDoc */ + #[\Override] protected function getConfiguration(): Configuration { return new WatcherConfig(); diff --git a/tools/coding-standards/psalm/psalm.xml b/tools/coding-standards/psalm/psalm.xml index 2ab17a7..252f339 100644 --- a/tools/coding-standards/psalm/psalm.xml +++ b/tools/coding-standards/psalm/psalm.xml @@ -14,26 +14,27 @@ - + + + - + From e3fcc4fb0c95c3f7a7f9954b43e891be69113bd3 Mon Sep 17 00:00:00 2001 From: julien Date: Fri, 6 Feb 2026 15:49:39 +0900 Subject: [PATCH 3/3] style(psalm): Fix psalm error for php 8.5 --- .github/workflows/php-sdk-development-tests.yml | 2 +- .github/workflows/release.yml | 3 +-- .github/workflows/unit-and-integration-test.yml | 2 +- tools/coding-standards/psalm/psalm.xml | 13 +++++++------ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/php-sdk-development-tests.yml b/.github/workflows/php-sdk-development-tests.yml index 6fbc895..b03bfba 100644 --- a/.github/workflows/php-sdk-development-tests.yml +++ b/.github/workflows/php-sdk-development-tests.yml @@ -37,7 +37,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: [ "7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3", "8.4" ] + php-version: [ "7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3", "8.4", "8.5" ] name: Unit and integration test runs-on: ubuntu-latest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 412baad..be2f941 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,12 +2,11 @@ name: Create Release # example: gh workflow run release.yml -f tag_name=v1.1.4 on: workflow_dispatch: - branches: - - main inputs: tag_name: type: string required: true + description: Tag with v prefix jobs: prepare-release: diff --git a/.github/workflows/unit-and-integration-test.yml b/.github/workflows/unit-and-integration-test.yml index 85c9ea4..b25c983 100644 --- a/.github/workflows/unit-and-integration-test.yml +++ b/.github/workflows/unit-and-integration-test.yml @@ -33,7 +33,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: [ "7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3", "8.4" ] + php-version: [ "7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3", "8.4", "8.5" ] name: Unit and integration test runs-on: ubuntu-latest diff --git a/tools/coding-standards/psalm/psalm.xml b/tools/coding-standards/psalm/psalm.xml index 252f339..aaed981 100644 --- a/tools/coding-standards/psalm/psalm.xml +++ b/tools/coding-standards/psalm/psalm.xml @@ -1,6 +1,7 @@ - - + - +