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

Base implementation #1

Merged
merged 64 commits into from
Jun 13, 2024
Merged
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
e2a2d7d
Install composer into Docker container and packages
Aeliot-Tm May 30, 2024
54e8672
Install PHPUnit
Aeliot-Tm May 30, 2024
86036b8
Allow testing of final classes
Aeliot-Tm May 30, 2024
b88a30a
Implement filtering of single line comment
Aeliot-Tm May 30, 2024
97ce513
Implement filtering of multi line comment (doc block)
Aeliot-Tm May 30, 2024
c3fc029
Implement filtering of multi line comment
Aeliot-Tm May 30, 2024
55eeb27
Move responsibility for tokens array keys refreshing to tests
Aeliot-Tm May 30, 2024
3938ed3
Define namespace for services
Aeliot-Tm May 30, 2024
ccd0cb7
Refactor DetectorTest.php
Aeliot-Tm May 30, 2024
0ea816d
Implement extractor of TODO from comment
Aeliot-Tm May 31, 2024
41a1520
Add testing on CI
Aeliot-Tm May 31, 2024
7f96868
Require lesstif/php-jira-rest-client
Aeliot-Tm May 31, 2024
0449ac3
Add extra test for extractor
Aeliot-Tm May 31, 2024
34a4a34
Extract tag detector
Aeliot-Tm May 31, 2024
2ba4540
Fix method visibility
Aeliot-Tm Jun 3, 2024
a91b311
Update splitting of comment on lines to make them friendly for the pr…
Aeliot-Tm Jun 4, 2024
3d872e2
Refactor detector of tags in comment
Aeliot-Tm Jun 4, 2024
ef4fda1
Implement file processor
Aeliot-Tm Jun 4, 2024
e37cc14
Implement finder of files
Aeliot-Tm Jun 6, 2024
fca0352
Add namespace for file handlers
Aeliot-Tm Jun 6, 2024
a68e6c3
Extract file tokenizer
Aeliot-Tm Jun 6, 2024
7ee0712
Extract file saver
Aeliot-Tm Jun 6, 2024
b86fd7b
Extract comment registrar
Aeliot-Tm Jun 6, 2024
832ba3d
Fix method visibility
Aeliot-Tm Jun 6, 2024
338883f
Implement application
Aeliot-Tm Jun 6, 2024
388f608
Implement registrar for JIRA
Aeliot-Tm Jun 6, 2024
4e5c04b
Update lock file
Aeliot-Tm Jun 6, 2024
52f3205
Test CommentParts
Aeliot-Tm Jun 8, 2024
08a0da0
Test CommentPart
Aeliot-Tm Jun 8, 2024
5f72df6
Add custom exception
Aeliot-Tm Jun 8, 2024
2cca792
Fix tests namespace
Aeliot-Tm Jun 10, 2024
eaec776
Add custom exception
Aeliot-Tm Jun 10, 2024
51d614d
Update messages of exceptions
Aeliot-Tm Jun 10, 2024
5977aa9
Test file tokenizer and saver
Aeliot-Tm Jun 11, 2024
4d7b1ce
Test file finder
Aeliot-Tm Jun 11, 2024
56548ea
Test file processor
Aeliot-Tm Jun 11, 2024
b747955
Test comment registrar
Aeliot-Tm Jun 11, 2024
0c49453
Permit easy extending of classes
Aeliot-Tm Jun 12, 2024
6b67d48
Move responsibility for key injection out of Registrar into CommentRe…
Aeliot-Tm Jun 12, 2024
c4096b4
Fix methods visibility
Aeliot-Tm Jun 12, 2024
252f552
Add assertion to shore that nothing was changed
Aeliot-Tm Jun 12, 2024
1efa816
Install xDebug
Aeliot-Tm Jun 12, 2024
ec98f2d
Config code coverage reports for PHPUnit
Aeliot-Tm Jun 12, 2024
0c2f5b7
Permit configuring of custom registrar factory
Aeliot-Tm Jun 12, 2024
12bb278
Extend validation of bin-file arguments
Aeliot-Tm Jun 12, 2024
a8c4665
Add guessing of default config file
Aeliot-Tm Jun 12, 2024
199d376
Describe project and add some small instructions
Aeliot-Tm Jun 12, 2024
9769f6b
Extract IssueFieldFactory
Aeliot-Tm Jun 12, 2024
9e4bdad
Test JIRA IssueConfig
Aeliot-Tm Jun 12, 2024
1940c5a
Add link to documentation
Aeliot-Tm Jun 12, 2024
d814059
Sort results of finder to stable behavior of test
Aeliot-Tm Jun 12, 2024
64e30f1
Add tokenizer extension as requirements in composer.json
Aeliot-Tm Jun 13, 2024
ab3712c
Permit configuring of detected tags
Aeliot-Tm Jun 13, 2024
797a7e8
Describe supported patterns
Aeliot-Tm Jun 13, 2024
decd1bb
Fix misprint
Aeliot-Tm Jun 13, 2024
81cc4b5
Describe assignee-part of tag
Aeliot-Tm Jun 13, 2024
4e407b9
Add suggestion to install package for monitoring of outdated comments
Aeliot-Tm Jun 13, 2024
e775aed
Add link to support into composer file
Aeliot-Tm Jun 13, 2024
f19a196
Change package type
Aeliot-Tm Jun 13, 2024
25a02ba
Require security vulnerability advisor
Aeliot-Tm Jun 13, 2024
e019347
Fix: loading of prerequisites
Aeliot-Tm Jun 13, 2024
3751c01
Fix: JIRA config array keys using
Aeliot-Tm Jun 13, 2024
8477417
Fix: config finder example
Aeliot-Tm Jun 13, 2024
810fdd3
Fix: return data type
Aeliot-Tm Jun 13, 2024
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
Prev Previous commit
Next Next commit
Implement extractor of TODO from comment
  • Loading branch information
Aeliot-Tm committed May 31, 2024
commit 0ea816d0bccf99a3809931a7a7bf36d1ba254fc9
42 changes: 42 additions & 0 deletions src/Dto/Comment/CommentPart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Aeliot\TodoRegistrar\Dto\Comment;

final class CommentPart
{
/**
* @var string[]
*/
protected array $lines;

public function __construct(
private ?string $tag,
private ?int $position,
) {
}

public function addLine(string $line): void
{
$this->lines[] = $line;
}

/**
* @return string[]
*/
public function getLines(): array
{
return $this->lines;
}

public function getPosition(): ?int
{
return $this->position;
}

public function getTag(): ?string
{
return $this->tag;
}
}
43 changes: 43 additions & 0 deletions src/Dto/Comment/CommentParts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Aeliot\TodoRegistrar\Dto\Comment;

final class CommentParts
{
/**
* @var CommentPart[]
*/
private array $parts = [];

/**
* @var CommentPart[]
*/
private array $todos = [];

public function addPart(CommentPart $part): void
{
$this->parts[] = $part;

if (null !== $part->getTag()) {
$this->todos[] = $part;
}
}

/**
* @return CommentPart[]
*/
public function getParts(): array
{
return $this->parts;
}

/**
* @return CommentPart[]
*/
public function getTodos(): array
{
return $this->todos;
}
}
73 changes: 73 additions & 0 deletions src/Service/Comment/Extractor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);

namespace Aeliot\TodoRegistrar\Service\Comment;

use Aeliot\TodoRegistrar\Dto\Comment\CommentPart;
use Aeliot\TodoRegistrar\Dto\Comment\CommentParts;

final class Extractor
{
public function __construct(private string $pattern = '/\\b(todo|fixme)\\b/i')
{
}

public function extract(string $comment): CommentParts
{
$part = null;
$parts = new CommentParts();
foreach ($this->splitLines($comment) as $line) {
if ($part && !$this->hasEmptyPrefix($line, $part)) {
$part = null;
}

$part ??= $this->registerPart($line, $parts);
$part->addLine($line);

if (null === $part->getTag()) {
$part = null;
}
}

return $parts;
}

/**
* @return array{0: string|null, 1: int|null}
*/
private function getCommentPosition(string $line): array
{
$tag = preg_match($this->pattern, $line, $matches) ? $matches[1] : null;

return null === $tag ? [null, null] : [strtoupper($tag), stripos($line, $tag)];
}

private function hasEmptyPrefix(string $line, CommentPart $part): bool
{
if (null === $part->getTag()) {
return false;
}

$prefixLength = $part->getPosition() + strlen($part->getTag());
$prefix = substr($line, 0, $prefixLength);

return strlen($prefix) === $prefixLength && \in_array(trim($prefix), ['*', '//'], true);
}

public function registerPart(string $line, CommentParts $parts): CommentPart
{
$part = new CommentPart(...$this->getCommentPosition($line));
$parts->addPart($part);

return $part;
}

/**
* @return string[]
*/
private function splitLines(string $comment): array
{
return preg_split("/\\r?\\n/", $comment);
}
}
50 changes: 50 additions & 0 deletions tests/Unit/Service/Comment/ExtractorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace Aeliot\TodoRegistrar\Test\Unit\Service\Comment;

use Aeliot\TodoRegistrar\Service\Comment\Extractor;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

#[CoversClass(Extractor::class)]
final class ExtractorTest extends TestCase
{
public static function getDataForTestCountOfParts(): iterable
{
yield [
1,
1,
'// TODO single line comment',
];
yield [
3,
1,
<<<CONT
/*
* TODO: inside of multi line comment
*/
CONT,
];
yield [
3,
1,
<<<CONT
/*
* TODO: multi line comment
* with some extra description.
*/
CONT,
];
}

#[DataProvider('getDataForTestCountOfParts')]
public function testCountOfParts(int $expectedTotalCount, int $expectedTodoCount, string $comment): void
{
$parts = (new Extractor())->extract($comment);
self::assertCount($expectedTotalCount, $parts->getParts());
self::assertCount($expectedTodoCount, $parts->getTodos());
}
}