Skip to content

Commit

Permalink
Fix backtrack limit issues with composer package names (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored Dec 22, 2023
1 parent 5dd7c89 commit 829088b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/TodoByPackageVersionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ final class TodoByPackageVersionRule implements Rule
private const COMPARATORS = ['<', '>', '='];

// composer package-name pattern from https://getcomposer.org/doc/04-schema.md#name
// adjusted because of backtrack limit issues https://github.com/staabm/phpstan-todo-by/issues/44
private const PATTERN = <<<'REGEXP'
{
@?TODO # possible @ prefix
@?[a-zA-Z0-9_-]* # optional username
\s*[:-]?\s* # optional colon or hyphen
\s+ # keyword/version separator
(?:(?P<package>(php|[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]|-{1,2})?[a-z0-9]+)*)):) # "php" or a composer package name, followed by ":"
(?:(?P<package>(php|[a-z0-9]([_.-]?[a-z0-9]++)*+/[a-z0-9](([_.]|-{1,2})?[a-z0-9]++)*+)):) # "php" or a composer package name, followed by ":"
(?P<version>[<>=]?[^\s:\-]+) # version
\s*[:-]?\s* # optional colon or hyphen
(?P<comment>.*) # rest of line as comment text
Expand Down
8 changes: 4 additions & 4 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public function testE2E(): void
$errors = $this->runAnalyse(__DIR__ . '/data/e2e.php');
static::assertCount(2, $errors);

$this->assertSame('Expired on 2023-12-14: fix it.', $errors[0]->getMessage());
$this->assertSame('"php" version requirement ">=7" satisfied.', $errors[1]->getMessage());
static::assertSame('Expired on 2023-12-14: fix it.', $errors[0]->getMessage());
static::assertSame('"php" version requirement ">=7" satisfied.', $errors[1]->getMessage());
}

public static function getAdditionalConfigFiles(): array
Expand All @@ -33,7 +33,7 @@ public static function getAdditionalConfigFiles(): array
* @param string[]|null $allAnalysedFiles
* @return Error[]
*/
private function runAnalyse(string $file, ?array $allAnalysedFiles = null): array
private function runAnalyse(string $file, array $allAnalysedFiles = null): array
{
$file = $this->getFileHelper()->normalizePath($file);
/** @var Analyser $analyser */
Expand All @@ -43,7 +43,7 @@ private function runAnalyse(string $file, ?array $allAnalysedFiles = null): arra
/** @phpstan-ignore-next-line missing bc promise */
$errors = $analyser->analyse([$file], null, null, true, $allAnalysedFiles)->getErrors();
foreach ($errors as $error) {
$this->assertSame($fileHelper->normalizePath($file), $error->getFilePath());
static::assertSame($fileHelper->normalizePath($file), $error->getFilePath());
}

return $errors;
Expand Down
5 changes: 5 additions & 0 deletions tests/TodoByPackageVersionRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,9 @@ public static function provideErrors(): iterable
],
];
}

public function testBug44(): void
{
$this->analyse([__DIR__ . '/data/bug44.php'], []);
}
}
6 changes: 6 additions & 0 deletions tests/data/bug44.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

namespace Bug44;

// TODO: minimumApiClientVersion:2.0 This can be removed once all API consumers use client version 2.0 or higher

0 comments on commit 829088b

Please sign in to comment.