Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove VersionNormalizer #36

Merged
merged 3 commits into from
Dec 20, 2023
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
3 changes: 0 additions & 3 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ services:
arguments:
- %todo_by.referenceVersion%

-
class: staabm\PHPStanTodoBy\utils\VersionNormalizer

-
class: staabm\PHPStanTodoBy\utils\ExpiredCommentErrorBuilder
arguments:
Expand Down
8 changes: 0 additions & 8 deletions src/TodoByDateRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,11 @@

use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Node\VirtualNode;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\ShouldNotHappenException;
use staabm\PHPStanTodoBy\utils\CommentMatcher;
use staabm\PHPStanTodoBy\utils\ExpiredCommentErrorBuilder;
use function preg_match_all;
use function strtotime;
use function substr_count;
use function time;
use function trim;
use const PREG_OFFSET_CAPTURE;
use const PREG_SET_ORDER;

/**
* @implements Rule<Node>
Expand Down
1 change: 0 additions & 1 deletion src/TodoByPackageVersionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use staabm\PHPStanTodoBy\utils\CommentMatcher;
use staabm\PHPStanTodoBy\utils\ExpiredCommentErrorBuilder;
use staabm\PHPStanTodoBy\utils\ReferenceVersionFinder;
use staabm\PHPStanTodoBy\utils\VersionNormalizer;
use function preg_match_all;
use function substr_count;
use function trim;
Expand Down
15 changes: 2 additions & 13 deletions src/TodoByVersionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@

namespace staabm\PHPStanTodoBy;

use Composer\Semver\Comparator;
use Composer\Semver\VersionParser;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Node\VirtualNode;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use staabm\PHPStanTodoBy\utils\CommentMatcher;
use staabm\PHPStanTodoBy\utils\ExpiredCommentErrorBuilder;
use staabm\PHPStanTodoBy\utils\ReferenceVersionFinder;
use staabm\PHPStanTodoBy\utils\VersionNormalizer;
use function preg_match_all;
use function substr_count;
use function trim;
use const PREG_OFFSET_CAPTURE;
use const PREG_SET_ORDER;

/**
* @implements Rule<Node>
Expand All @@ -38,8 +30,6 @@ final class TodoByVersionRule implements Rule
}ix
REGEXP;

private VersionNormalizer $versionNormalizer;

private ReferenceVersionFinder $referenceVersionFinder;

private bool $singleGitRepo;
Expand All @@ -54,13 +44,11 @@ final class TodoByVersionRule implements Rule
public function __construct(
bool $singleGitRepo,
ReferenceVersionFinder $refVersionFinder,
VersionNormalizer $versionNormalizer,
ExpiredCommentErrorBuilder $errorBuilder
) {
$this->referenceVersionFinder = $refVersionFinder;
$this->errorBuilder = $errorBuilder;
$this->singleGitRepo = $singleGitRepo;
$this->versionNormalizer = $versionNormalizer;
}

public function getNodeType(): string
Expand Down Expand Up @@ -140,8 +128,9 @@ private function getReferenceVersion(Scope $scope): string
}

if (!array_key_exists($cacheKey, $this->referenceVersions)) {
$versionParser = new VersionParser();
// lazy get the version, as it might incur subprocess creation
$this->referenceVersions[$cacheKey] = $this->versionNormalizer->normalize(
$this->referenceVersions[$cacheKey] = $versionParser->normalize(
$this->referenceVersionFinder->find($workingDirectory)
);
}
Expand Down
20 changes: 0 additions & 20 deletions src/utils/VersionNormalizer.php

This file was deleted.

4 changes: 0 additions & 4 deletions tests/TodoByPackageVersionRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use staabm\PHPStanTodoBy\TodoByPackageVersionRule;
use staabm\PHPStanTodoBy\TodoByVersionRule;
use staabm\PHPStanTodoBy\utils\ExpiredCommentErrorBuilder;
use staabm\PHPStanTodoBy\utils\GitTagFetcher;
use staabm\PHPStanTodoBy\utils\ReferenceVersionFinder;
use staabm\PHPStanTodoBy\utils\VersionNormalizer;

/**
* @extends RuleTestCase<TodoByPackageVersionRule>
Expand Down
2 changes: 0 additions & 2 deletions tests/TodoByVersionRuleAlwaysThrowingFetchterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use staabm\PHPStanTodoBy\TodoByVersionRule;
use staabm\PHPStanTodoBy\utils\ExpiredCommentErrorBuilder;
use staabm\PHPStanTodoBy\utils\ReferenceVersionFinder;
use staabm\PHPStanTodoBy\utils\VersionNormalizer;

/**
* @extends RuleTestCase<TodoByVersionRule>
Expand All @@ -20,7 +19,6 @@ protected function getRule(): Rule
return new TodoByVersionRule(
true,
new ReferenceVersionFinder($this->referenceVersion, new AlwaysThrowingTagFetcher()),
new VersionNormalizer(),
new ExpiredCommentErrorBuilder(true)
);
}
Expand Down
2 changes: 0 additions & 2 deletions tests/TodoByVersionRuleSingleTimeFetchterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use staabm\PHPStanTodoBy\TodoByVersionRule;
use staabm\PHPStanTodoBy\utils\ExpiredCommentErrorBuilder;
use staabm\PHPStanTodoBy\utils\ReferenceVersionFinder;
use staabm\PHPStanTodoBy\utils\VersionNormalizer;

/**
* @extends RuleTestCase<TodoByVersionRule>
Expand All @@ -20,7 +19,6 @@ protected function getRule(): Rule
return new TodoByVersionRule(
false,
new ReferenceVersionFinder($this->referenceVersion, new SingleTimeTagFetcher()),
new VersionNormalizer(),
new ExpiredCommentErrorBuilder(true)
);
}
Expand Down
2 changes: 0 additions & 2 deletions tests/TodoByVersionRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use staabm\PHPStanTodoBy\utils\ExpiredCommentErrorBuilder;
use staabm\PHPStanTodoBy\utils\GitTagFetcher;
use staabm\PHPStanTodoBy\utils\ReferenceVersionFinder;
use staabm\PHPStanTodoBy\utils\VersionNormalizer;

/**
* @extends RuleTestCase<TodoByVersionRule>
Expand All @@ -21,7 +20,6 @@ protected function getRule(): Rule
return new TodoByVersionRule(
true,
new ReferenceVersionFinder($this->referenceVersion, new GitTagFetcher()),
new VersionNormalizer(),
new ExpiredCommentErrorBuilder(true),
);
}
Expand Down