Skip to content

Commit

Permalink
refactor analyze task
Browse files Browse the repository at this point in the history
  • Loading branch information
savinmikhail committed Jan 3, 2025
1 parent 96f4190 commit bd747db
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
10 changes: 4 additions & 6 deletions src/AnalyzeComments/Analyzer/Analyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ final class Analyzer
public function __construct(
private readonly ConfigDTO $configDTO,
private readonly CommentFactory $commentFactory,
private readonly MissingDocBlockAnalyzer $missingDocBlock,
private readonly MetricsFacade $metrics,
private readonly MissingDocBlockAnalyzer $docBlockAnalyzer,
private readonly MissingDocBlockAnalyzer $missingDocBlockAnalyzer,
private readonly BaselineStorageInterface $baselineStorage,
private readonly CacheInterface $cache,
private readonly CommentStatisticsAggregator $statisticsAggregator,
Expand All @@ -45,12 +44,11 @@ public function analyze(iterable $files): Report
$filesAnalyzed = 0;

foreach ($files as $file) {
$task = new AnalyzeFileTask(
$task = new FileCommentFinder(
$this->cache,
$this->docBlockAnalyzer,
$this->missingDocBlock,
$this->commentFactory,
$this->configDTO,
$this->missingDocBlockAnalyzer,
);

$response = $task->run($file);
Expand All @@ -77,7 +75,7 @@ private function checkThresholdsExceeded(): bool
if ($this->metrics->hasExceededThreshold()) {
return true;
}
if ($this->missingDocBlock->hasExceededThreshold()) {
if ($this->missingDocBlockAnalyzer->hasExceededThreshold()) {
return true;
}
foreach ($this->commentFactory->getCommentTypes() as $commentType) {
Expand Down
1 change: 0 additions & 1 deletion src/AnalyzeComments/Analyzer/AnalyzerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function getAnalyzer(
return new Analyzer(
$configDto,
$commentFactory,
$missingDocBlock,
$metrics,
$missingDocBlock,
$baselineStorage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
use const T_COMMENT;
use const T_DOC_COMMENT;

final readonly class AnalyzeFileTask
final readonly class FileCommentFinder
{
public function __construct(
private CacheInterface $cache,
private MissingDocBlockAnalyzer $docBlockAnalyzer,
private MissingDocBlockAnalyzer $missingDocBlock,
private CommentFactory $commentFactory,
private ConfigDTO $configDTO,
private MissingDocBlockAnalyzer $missingDocBlockAnalyzer
) {}

/**
Expand Down Expand Up @@ -76,7 +75,7 @@ private function analyzeFile(string $filename): array

$comments = $this->getCommentsFromFile($tokens, $filename);
if ($this->shouldAnalyzeMissingDocBlocks()) {
$missingDocBlocks = $this->docBlockAnalyzer->getMissingDocblocks($code, $filename);
$missingDocBlocks = $this->missingDocBlockAnalyzer->getMissingDocblocks($code, $filename);
$comments = array_merge($missingDocBlocks, $comments);
}

Expand All @@ -88,7 +87,7 @@ private function shouldAnalyzeMissingDocBlocks(): bool
return
$this->configDTO->getAllowedTypes() === []
|| in_array(
$this->missingDocBlock->getName(),
$this->missingDocBlockAnalyzer->getName(),
$this->configDTO->getAllowedTypes(),
true,
);
Expand Down

0 comments on commit bd747db

Please sign in to comment.