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 |
|
foreach ($todos as $dir => $entries) { |
34
|
1 |
|
$dir = (string) $dir; |
35
|
1 |
|
$showDir = false; |
36
|
1 |
|
$firstFileInDir = true; |
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
|
|
|
$showDir = true; |
43
|
1 |
|
} elseif ($this->dirHasFilesWithTodos($todos, $dir)) { |
44
|
1 |
|
$showDir = true; |
45
|
|
|
} |
46
|
|
|
|
47
|
1 |
|
if (0 == \count($entries)) { |
48
|
|
|
/* |
49
|
|
|
* show_no_files_info |
50
|
|
|
*/ |
51
|
|
|
if ($config['show_no_files_info'] && $showDir) { |
52
|
|
|
$output->writeln(''); |
53
|
|
|
$output->writeln('-----------------------------------------------------'); |
54
|
|
|
$output->writeln('<info>'.$dir.'</info>'); |
55
|
|
|
$output->writeln('-----------------------------------------------------'); |
56
|
|
|
$output->writeln('<comment>No TODOs found.</comment>'); |
57
|
|
|
$output->writeln('-----------------------------------------------------'); |
58
|
|
|
} |
59
|
|
|
continue; |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
foreach ($entries as $file => $todoList) { |
63
|
1 |
|
if (0 == \count($todoList)) { |
64
|
|
|
if ($config['show_files_with_no_todos']) { |
65
|
|
|
$output->writeln(''); |
66
|
|
|
$output->writeln('-----------------------------------------------------'); |
67
|
|
|
$output->writeln('<info>'.$dir.'</info>'.$file); |
68
|
|
|
$output->writeln('-----------------------------------------------------'); |
69
|
|
|
$output->writeln('<comment>No TODOs found.</comment>'); |
70
|
|
|
$output->writeln('-----------------------------------------------------'); |
71
|
|
|
} |
72
|
|
|
} else { |
73
|
1 |
|
if (!$firstFileInDir) { |
74
|
|
|
$output->writeln(''); |
75
|
|
|
} else { |
76
|
1 |
|
$firstFileInDir = false; |
77
|
|
|
} |
78
|
|
|
|
79
|
1 |
|
$output->writeln(''); |
80
|
1 |
|
$output->writeln('-----------------------------------------------------'); |
81
|
1 |
|
$output->writeln('<info>'.$dir.'</info>'.$file); |
82
|
1 |
|
$output->writeln('-----------------------------------------------------'); |
83
|
1 |
|
foreach ($todoList as $todo) { |
84
|
1 |
|
$output->writeln('- '.$todo['message']); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
} |
89
|
1 |
|
$output->writeln(''); |
90
|
1 |
|
} |
91
|
|
|
} |
92
|
|
|
|