Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ on:
- main
paths-ignore:
- '**.md'
pull_request:
branches:
- main
paths-ignore:
- '**.md'
workflow_dispatch:
inputs:
coverage_report:
Expand All @@ -20,7 +25,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
Expand Down Expand Up @@ -77,7 +82,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: Prepare integration tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php-sdk-development-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-and-integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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
Expand Down
3 changes: 3 additions & 0 deletions src/Client/AbstractClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public function __construct(
parent::__construct($configs, $this->capiHandler, $logger);
}

/**
* @psalm-api
*/
public function getCapiHandler(): CapiHandlerInterface
{
return $this->capiHandler;
Expand Down
1 change: 1 addition & 0 deletions src/Client/CapiHandler/CapiHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface CapiHandlerInterface extends RequestHandlerInterface
{
/**
* Retrieve decisions list from a blocklist url.
* @psalm-api
*/
public function getListDecisions(string $url, array $headers = []): string;
}
7 changes: 6 additions & 1 deletion src/Client/CapiHandler/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
*
* @copyright Copyright (c) 2022+ CrowdSec
* @license MIT License
*
* @psalm-api
*/
class Curl extends CommonCurl implements CapiHandlerInterface
{
#[\Override]
public function getListDecisions(string $url, array $headers = []): string
{
$handle = curl_init();
Expand All @@ -30,7 +33,9 @@ public function getListDecisions(string $url, array $headers = []): string

$statusCode = $this->getResponseHttpCode($handle);

curl_close($handle);
if (PHP_VERSION_ID < 80000) {
curl_close($handle);
}

return 200 === $statusCode ? (string) $response : '';
}
Expand Down
4 changes: 4 additions & 0 deletions src/Client/CapiHandler/FileGetContents.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
*
* @copyright Copyright (c) 2022+ CrowdSec
* @license MIT License
*
* @psalm-api
*
*/
class FileGetContents extends CommonFileGetContents implements CapiHandlerInterface
{
#[\Override]
public function getListDecisions(string $url, array $headers = []): string
{
$config = $this->createListContextConfig($headers);
Expand Down
1 change: 1 addition & 0 deletions src/Configuration/Signal.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Signal extends AbstractConfiguration
* @throws \RuntimeException
* @throws \InvalidArgumentException
*/
#[\Override]
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('signalConfig');
Expand Down
2 changes: 2 additions & 0 deletions src/Configuration/Signal/Decisions.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Decisions extends AbstractConfiguration
* Keep only necessary configs
* Override because $configs is an array of array (decision) and we want to clean each decision.
*/
#[\Override]
public function cleanConfigs(array $configs): array
{
$result = [];
Expand All @@ -54,6 +55,7 @@ public function cleanConfigs(array $configs): array
* @throws \InvalidArgumentException
* @throws \RuntimeException
*/
#[\Override]
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('signalDecisionsConfig');
Expand Down
1 change: 1 addition & 0 deletions src/Configuration/Signal/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Source extends AbstractConfiguration
'as_number',
];

#[\Override]
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('signalSourceConfig');
Expand Down
1 change: 1 addition & 0 deletions src/Configuration/Watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Watcher extends AbstractConfiguration
* @throws \InvalidArgumentException
* @throws \RuntimeException
*/
#[\Override]
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('watcherConfig');
Expand Down
10 changes: 10 additions & 0 deletions src/Storage/FileStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*
* @copyright Copyright (c) 2022+ CrowdSec
* @license MIT License
*
* @psalm-api
*/
class FileStorage implements StorageInterface
{
Expand All @@ -38,34 +40,39 @@ public function __construct(string $rootDir = __DIR__, string $env = Constants::
$this->env = $env;
}

#[\Override]
public function retrieveMachineId(): ?string
{
$storageContent = $this->readFile($this->getBasePath() . self::MACHINE_ID_FILE);

return !empty($storageContent['machine_id']) ? $storageContent['machine_id'] : null;
}

#[\Override]
public function retrievePassword(): ?string
{
$storageContent = $this->readFile($this->getBasePath() . self::PASSWORD_FILE);

return !empty($storageContent['password']) ? $storageContent['password'] : null;
}

#[\Override]
public function retrieveScenarios(): ?array
{
$storageContent = $this->readFile($this->getBasePath() . self::SCENARIOS_FILE);

return !empty($storageContent['scenarios']) ? $storageContent['scenarios'] : null;
}

#[\Override]
public function retrieveToken(): ?string
{
$storageContent = $this->readFile($this->getBasePath() . self::TOKEN_FILE);

return !empty($storageContent['token']) ? $storageContent['token'] : null;
}

#[\Override]
public function storeMachineId(string $machineId): bool
{
try {
Expand All @@ -78,6 +85,7 @@ public function storeMachineId(string $machineId): bool
return true;
}

#[\Override]
public function storePassword(string $password): bool
{
try {
Expand All @@ -90,6 +98,7 @@ public function storePassword(string $password): bool
return true;
}

#[\Override]
public function storeScenarios(array $scenarios): bool
{
try {
Expand All @@ -102,6 +111,7 @@ public function storeScenarios(array $scenarios): bool
return true;
}

#[\Override]
public function storeToken(string $token): bool
{
try {
Expand Down
2 changes: 2 additions & 0 deletions src/Storage/StorageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*
* @copyright Copyright (c) 2022+ CrowdSec
* @license MIT License
*
* @psalm-api
*/
interface StorageInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*
* @see https://crowdsec.net CrowdSec Official Website
*
* @psalm-api
*
* @copyright Copyright (c) 2022+ CrowdSec
* @license MIT License
*/
Expand Down
5 changes: 4 additions & 1 deletion tests/PHPUnitUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions tools/coding-standards/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions tools/coding-standards/psalm/psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<psalm
errorLevel="5"
resolveFromConfigFile="true"
findUnusedIssueHandlerSuppression="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
Expand All @@ -14,6 +15,7 @@
</ignoreFiles>
</projectFiles>
<issueHandlers>
<UnusedMethodCall errorLevel="info"/>
<UndefinedInterfaceMethod>
<errorLevel type="suppress">
<referencedMethod name="Symfony\Component\Config\Definition\Builder\NodeParentInterface::integerNode"/>
Expand Down
Loading