Skip to content

Commit 5d33d5d

Browse files
committed
rename comment factory
1 parent 46cbb1e commit 5d33d5d

File tree

10 files changed

+34
-29
lines changed

10 files changed

+34
-29
lines changed

src/AnalyzeComments/Analyzer/Analyzer.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output\CommentDTO;
99
use SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output\CommentStatisticsDTO;
1010
use SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output\Report;
11-
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\CommentFactory;
11+
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\CommentTypeFactory;
1212
use SavinMikhail\CommentsDensity\AnalyzeComments\Config\DTO\ConfigDTO;
1313
use SavinMikhail\CommentsDensity\AnalyzeComments\Exception\CommentsDensityException;
1414
use SavinMikhail\CommentsDensity\AnalyzeComments\Metrics\MetricsFacade;
@@ -24,12 +24,12 @@ final class Analyzer
2424
private int $totalLinesOfCode = 0;
2525

2626
public function __construct(
27-
private readonly ConfigDTO $configDTO,
28-
private readonly CommentFactory $commentFactory,
29-
private readonly MetricsFacade $metrics,
30-
private readonly MissingDocBlockAnalyzer $missingDocBlockAnalyzer,
31-
private readonly BaselineStorageInterface $baselineStorage,
32-
private readonly CacheInterface $cache,
27+
private readonly ConfigDTO $configDTO,
28+
private readonly CommentTypeFactory $commentFactory,
29+
private readonly MetricsFacade $metrics,
30+
private readonly MissingDocBlockAnalyzer $missingDocBlockAnalyzer,
31+
private readonly BaselineStorageInterface $baselineStorage,
32+
private readonly CacheInterface $cache,
3333
private readonly CommentStatisticsAggregator $statisticsAggregator,
3434
) {}
3535

src/AnalyzeComments/Analyzer/AnalyzerFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer;
66

7-
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\CommentFactory;
7+
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\CommentTypeFactory;
88
use SavinMikhail\CommentsDensity\AnalyzeComments\Config\DTO\ConfigDTO;
99
use SavinMikhail\CommentsDensity\AnalyzeComments\Metrics\CDS;
1010
use SavinMikhail\CommentsDensity\AnalyzeComments\Metrics\ComToLoc;
@@ -20,7 +20,7 @@ public function getAnalyzer(
2020
ConfigDTO $configDto,
2121
BaselineStorageInterface $baselineStorage,
2222
): Analyzer {
23-
$commentFactory = new CommentFactory($configDto->getAllowedTypes());
23+
$commentFactory = new CommentTypeFactory($configDto->getAllowedTypes());
2424
$missingDocBlock = new MissingDocBlockAnalyzer($configDto->docblockConfigDTO);
2525
$cds = new CDS($configDto->thresholds, $commentFactory);
2626

src/AnalyzeComments/Analyzer/CommentFinder.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use PhpToken;
88
use Psr\Cache\InvalidArgumentException;
99
use SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output\CommentDTO;
10-
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\CommentFactory;
10+
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\CommentTypeFactory;
1111
use SavinMikhail\CommentsDensity\AnalyzeComments\Config\DTO\ConfigDTO;
1212
use SavinMikhail\CommentsDensity\AnalyzeComments\MissingDocblock\MissingDocBlockAnalyzer;
1313
use SplFileInfo;
@@ -25,8 +25,8 @@
2525
final readonly class CommentFinder
2626
{
2727
public function __construct(
28-
private CommentFactory $commentFactory,
29-
private ConfigDTO $configDTO,
28+
private CommentTypeFactory $commentFactory,
29+
private ConfigDTO $configDTO,
3030
private MissingDocBlockAnalyzer $missingDocBlockAnalyzer
3131
) {}
3232

@@ -66,8 +66,7 @@ private function getCommentsFromFile(array $tokens, string $filename): array
6666
{
6767
$comments = [];
6868
foreach ($tokens as $token) {
69-
70-
if (!in_array($token->id, [T_COMMENT, T_DOC_COMMENT], true)) {
69+
if ($token->is([T_COMMENT, T_DOC_COMMENT])) {
7170
continue;
7271
}
7372
$commentType = $this->commentFactory->classifyComment($token->text);

src/AnalyzeComments/Analyzer/CommentStatisticsAggregator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output\CommentDTO;
88
use SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output\CommentStatisticsDTO;
9-
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\CommentFactory;
9+
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\CommentTypeFactory;
1010
use SavinMikhail\CommentsDensity\AnalyzeComments\Config\DTO\ConfigDTO;
1111
use SavinMikhail\CommentsDensity\AnalyzeComments\Exception\CommentsDensityException;
1212
use SavinMikhail\CommentsDensity\AnalyzeComments\MissingDocblock\MissingDocBlockAnalyzer;
@@ -18,8 +18,8 @@
1818
final readonly class CommentStatisticsAggregator
1919
{
2020
public function __construct(
21-
private ConfigDTO $configDTO,
22-
private CommentFactory $commentFactory,
21+
private ConfigDTO $configDTO,
22+
private CommentTypeFactory $commentFactory,
2323
private MissingDocBlockAnalyzer $missingDocBlock,
2424
) {}
2525

src/AnalyzeComments/Comments/CommentFactory.php renamed to src/AnalyzeComments/Comments/CommentTypeFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use function in_array;
88

9-
final readonly class CommentFactory
9+
final readonly class CommentTypeFactory
1010
{
1111
/** @var CommentTypeInterface[] */
1212
private array $commentTypes;

src/AnalyzeComments/Metrics/CDS.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
use Mikhail\PrimitiveWrappers\Int\Integer;
99
use SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output\CdsDTO;
1010
use SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output\CommentStatisticsDTO;
11-
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\CommentFactory;
11+
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\CommentTypeFactory;
1212

1313
use function in_array;
1414
use function round;
1515

16+
/**
17+
* comments density score (from 0 to 1)
18+
*/
1619
final class CDS
1720
{
1821
private const MISSING_DOCBLOCK_WEIGHT = -1;
@@ -23,8 +26,8 @@ final class CDS
2326
* @param array<string, float> $thresholds
2427
*/
2528
public function __construct(
26-
private readonly array $thresholds,
27-
private readonly CommentFactory $commentFactory,
29+
private readonly array $thresholds,
30+
private readonly CommentTypeFactory $commentFactory,
2831
) {}
2932

3033
/**

src/AnalyzeComments/Metrics/ComToLoc.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
use function round;
1111

12+
/**
13+
* lines of comments to lines of code relation
14+
*/
1215
final class ComToLoc
1316
{
1417
private bool $exceedThreshold = false;

tests/Analyzer/CommentStatisticsAggregatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output\CommentDTO;
1111
use SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output\CommentStatisticsDTO;
1212
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\Comment;
13-
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\CommentFactory;
13+
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\CommentTypeFactory;
1414
use SavinMikhail\CommentsDensity\AnalyzeComments\Config\DTO\ConfigDTO;
1515
use SavinMikhail\CommentsDensity\AnalyzeComments\Config\DTO\MissingDocblockConfigDTO;
1616
use SavinMikhail\CommentsDensity\AnalyzeComments\Config\DTO\OutputDTO as OutputConfigDTO;
@@ -38,7 +38,7 @@ protected function setUp(): void
3838
cacheDir: 'tmp',
3939
);
4040

41-
$this->commentFactory = $this->createMock(CommentFactory::class);
41+
$this->commentFactory = $this->createMock(CommentTypeFactory::class);
4242
$this->missingDocBlock = $this->createMock(MissingDocBlockAnalyzer::class);
4343
$this->aggregator = new CommentStatisticsAggregator(
4444
$configDTO,

tests/Comments/CommentTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use PHPUnit\Framework\TestCase;
99
use ReflectionClass;
1010
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\Comment;
11-
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\CommentFactory;
11+
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\CommentTypeFactory;
1212
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\DocBlockComment;
1313
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\FixMeComment;
1414
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\LicenseComment;
@@ -76,7 +76,7 @@ public static function getStatColorDataProvider(): array
7676
#[DataProvider('regularCommentRegexDataProvider')]
7777
public function testRegularCommentRegex(string $comment, string $class): void
7878
{
79-
$factory = new CommentFactory();
79+
$factory = new CommentTypeFactory();
8080
$commentType = $factory->classifyComment($comment);
8181
self::assertInstanceOf($class, $commentType);
8282
}

tests/Metrics/CDSTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
use ReflectionClass;
99
use SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output\CdsDTO;
1010
use SavinMikhail\CommentsDensity\AnalyzeComments\Analyzer\DTO\Output\CommentStatisticsDTO;
11-
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\CommentFactory;
11+
use SavinMikhail\CommentsDensity\AnalyzeComments\Comments\CommentTypeFactory;
1212
use SavinMikhail\CommentsDensity\AnalyzeComments\Metrics\CDS;
1313

1414
final class CDSTest extends TestCase
1515
{
1616
private CDS $cds;
1717

18-
private CommentFactory $commentFactory;
18+
private CommentTypeFactory $commentFactory;
1919

2020
protected function setUp(): void
2121
{
22-
$this->commentFactory = new CommentFactory();
22+
$this->commentFactory = new CommentTypeFactory();
2323
$this->cds = new CDS(['CDS' => 0.5], $this->commentFactory);
2424
}
2525

@@ -59,7 +59,7 @@ public function testGetColorForCDS(): void
5959
self::assertEquals('green', $method->invokeArgs($this->cds, [0.75]));
6060
self::assertEquals('red', $method->invokeArgs($this->cds, [0.25]));
6161

62-
$cds = new CDS([], new CommentFactory());
62+
$cds = new CDS([], new CommentTypeFactory());
6363
$reflection = new ReflectionClass($cds);
6464
$method = $reflection->getMethod('getColorForCDS');
6565
$method->setAccessible(true);

0 commit comments

Comments
 (0)