1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Todolo\Helper; |
6
|
|
|
|
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
8
|
|
|
|
9
|
|
|
class OutputHelper |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @param array<int|string, array<array>> $todos |
13
|
|
|
*/ |
14
|
1 |
|
protected function dirHasFilesWithTodos(array $todos, string $dirToCheck): bool |
15
|
|
|
{ |
16
|
1 |
|
foreach ($todos as $dir => $entries) { |
17
|
1 |
|
foreach ($entries as $todoList) { |
18
|
1 |
|
if ($dir == $dirToCheck && 0 < \count($todoList)) { |
19
|
1 |
|
return true; |
20
|
|
|
} |
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
return false; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param array<int|string, array<array>> $todos |
29
|
|
|
* @param array<int|string, mixed> $config |
30
|
|
|
*/ |
31
|
1 |
|
public function printTodos(OutputInterface $output, array $todos, array $config): void |
32
|
|
|
{ |
33
|
1 |
|
$output->writeln(''); |
34
|
1 |
|
foreach ($todos as $dir => $entries) { |
35
|
1 |
|
$dir = (string) $dir; |
36
|
1 |
|
$dirIsShown = false; |
37
|
|
|
|
38
|
|
|
/* |
39
|
|
|
* if show_empty_dir_info is ON only show dir name if we have TODOs |
40
|
|
|
*/ |
41
|
1 |
|
if ($config['show_empty_dir'] && !$this->dirHasFilesWithTodos($todos, $dir)) { |
42
|
|
|
$output->writeln('> '.$dir); |
43
|
|
|
$dirIsShown = true; |
44
|
1 |
|
} elseif ($this->dirHasFilesWithTodos($todos, $dir)) { |
45
|
1 |
|
$output->writeln('> '.$dir); |
46
|
1 |
|
$dirIsShown = true; |
47
|
|
|
} |
48
|
|
|
|
49
|
1 |
|
if (0 == \count($entries)) { |
50
|
|
|
/* |
51
|
|
|
* show_no_files_info |
52
|
|
|
*/ |
53
|
|
|
if ($config['show_no_files_info'] && $dirIsShown) { |
54
|
|
|
$output->writeln(' <fg=cyan>No files found.</>'); |
55
|
|
|
} |
56
|
|
|
continue; |
57
|
|
|
} |
58
|
|
|
|
59
|
1 |
|
foreach ($entries as $file => $todoList) { |
60
|
1 |
|
if (0 == \count($todoList)) { |
61
|
|
|
if ($config['show_files_with_no_todos']) { |
62
|
|
|
$output->writeln(' '.$file); |
63
|
|
|
} |
64
|
|
|
} else { |
65
|
1 |
|
$output->writeln(' '.$file); |
66
|
1 |
|
foreach ($todoList as $todo) { |
67
|
1 |
|
$output->writeln(' - '.$todo['message']); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
72
|
1 |
|
$output->writeln(''); |
73
|
1 |
|
} |
74
|
|
|
} |
75
|
|
|
|