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
2 changes: 0 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ permissions:
jobs:
php:
uses: typisttech/.github/.github/workflows/lint-php.yml@v3
with:
phpstan: false
15 changes: 13 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
"require": {
"php": "^8.3",
"composer/semver": "^3.4",
"guzzlehttp/guzzle": "^7.9"
"guzzlehttp/guzzle": "^7.9",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-deprecation-rules": "^2.0",
"phpstan/phpstan-mockery": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0"
},
"require-dev": {
"mockery/mockery": "^1.6",
Expand All @@ -48,7 +53,8 @@
},
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
"pestphp/pest-plugin": true,
"phpstan/extension-installer": true
},
"sort-packages": true
},
Expand All @@ -57,6 +63,11 @@
"curl -o ./tests/Fixtures/vulnerabilities.production.json https://www.wordfence.com/api/intelligence/v2/vulnerabilities/production",
"curl -o ./tests/Fixtures/vulnerabilities.scanner.json https://www.wordfence.com/api/intelligence/v2/vulnerabilities/scanner"
],
"lint": [
"@composer normalize --dry-run",
"pint --test",
"phpstan analyse"
],
"pest": "pest -d memory_limit=512M",
"pest:e2e": "pest -d memory_limit=512M --group=e2e",
"pest:feature": "pest -d memory_limit=512M --group=feature",
Expand Down
247 changes: 246 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: max
paths:
- src
35 changes: 20 additions & 15 deletions src/AffectedVersionsParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,28 @@

readonly class AffectedVersionsParser
{
private const string UNKNOWN = 'unknown';

public function __construct(
private VersionParser $parser = new VersionParser,
) {}

/**
* @param array{from_version?: mixed, from_inclusive?: mixed, to_version?: mixed, to_inclusive?: mixed}[] $data
*/
public function parse(array $data): ?ConstraintInterface
{
$constraints = array_map(function (array $affected): ?string {
$fromVersion = (string) ($affected['from_version'] ?? self::UNKNOWN);
$fromVersion = $affected['from_version'] ?? null;
if (! is_string($fromVersion)) {
return null;
}

$fromInclusive = (bool) ($affected['from_inclusive'] ?? false);
$toVersion = (string) ($affected['to_version'] ?? self::UNKNOWN);

$toVersion = $affected['to_version'] ?? null;
if (! is_string($toVersion)) {
return null;
}

$toInclusive = (bool) ($affected['to_inclusive'] ?? false);

if ($fromVersion === '*' && $toVersion === '*') {
Expand All @@ -40,7 +50,7 @@ public function parse(array $data): ?ConstraintInterface
}

if ($toVersion !== '*') {
if (! empty($constraint)) {
if ($constraint !== '') {
$constraint .= ', ';
}

Expand All @@ -51,23 +61,18 @@ public function parse(array $data): ?ConstraintInterface
return $constraint;
}, $data);

$constraints = array_filter($constraints);
$constraints = array_filter($constraints, static fn (?string $c) => $c !== null);
$constraints = array_filter($constraints, static fn (string $c) => $c !== '');
$constraints = array_values($constraints);
$imploded = implode('||', $constraints);

if (empty($imploded)) {
return null;
}

return $this->parser->parseConstraints($imploded);
return $imploded === ''
? null
: $this->parser->parseConstraints($imploded);
}

private function isValid(string $version): bool
{
if ($version === self::UNKNOWN) {
return false;
}

if ($version === '*') {
return true;
}
Expand Down
Loading