Skip to content

Commit

Permalink
Add HydeStan helper to create a todo list
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Sep 9, 2024
1 parent 09dd00d commit ad55e0c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions monorepo/HydeStan/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
todo.md
2 changes: 2 additions & 0 deletions monorepo/HydeStan/HydeStan.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ public function run(string $file, string $contents): void
if (str_contains($contents, 'extends TestCase') && ! str_contains($contents, 'extends UnitTestCase')) {
$lineNumber = substr_count(substr($contents, 0, strpos($contents, 'extends TestCase')), "\n") + 1;

todo(realpath(__DIR__.'/../../packages/framework/'.$file), $lineNumber, 'Refactor unit test to extend UnitTestCase instead of TestCase');

echo sprintf('Test in unit namespace extends TestCase instead of UnitTestCase at %s', fileLink($file, $lineNumber, false))."\n";
}
}
Expand Down
58 changes: 58 additions & 0 deletions monorepo/HydeStan/includes/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,61 @@ function recursiveFileFinder(string $directory): array

return $files;
}

class TodoBuffer
{
private static array $todos = [];

public static function add(string $file, int $line, string $todo): void
{
self::$todos[] = [
'file' => $file,
'line' => $line,
'todo' => $todo,
];
}

public static function getTodos(): array
{
return self::$todos;
}

public static function writeTaskFile(): void
{
$todos = self::getTodos();

if (empty($todos)) {
return;
}

$taskFile = __DIR__.'/../todo.md';

$content = '# Todos'."\n\n";
$groupedTodos = [];

$baseDir = realpath(__DIR__.'/../../../');

foreach ($todos as $todo) {
$path = "{$todo['file']}:{$todo['line']}";
$path = str_replace('\\', '/', $path);

$path = substr($path, strlen($baseDir) + 1);

$groupedTodos[$todo['todo']][] = "[$path]($path)";
}

foreach ($groupedTodos as $todo => $items) {
$content .= "## $todo\n\n";
foreach ($items as $item) {
$content .= "- $item\n";
}
}

file_put_contents($taskFile, $content);
}
}

function todo(string $file, int $line, string $todo): void
{
TodoBuffer::add($file, $line, $todo);
}
3 changes: 3 additions & 0 deletions monorepo/HydeStan/run.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
$analyser = new HydeStan($debug);
$analyser->run();

// Todo: Could add a flag for this
TodoBuffer::writeTaskFile();

if ($analyser->hasErrors()) {
exit(1);
}
Expand Down

0 comments on commit ad55e0c

Please sign in to comment.