• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ICanBoogie / Module / 4256459796

pending completion
4256459796

push

github

Olivier Laviale
Add the console command 'modules:list'

22 of 22 new or added lines in 1 file covered. (100.0%)

135 of 451 relevant lines covered (29.93%)

0.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.45
/lib/Module/Console/ListModulesCommand.php
1
<?php
2

3
namespace ICanBoogie\Module\Console;
4

5
use ICanBoogie\Binding\Module\Config;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Helper\Table;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10

11
use function getcwd;
12
use function implode;
13
use function is_string;
14
use function str_starts_with;
15
use function strlen;
16
use function substr;
17

18
final class ListModulesCommand extends Command
19
{
20
    public function __construct(
21
        private readonly Config $config,
22
        private readonly string $style,
23
    ) {
24
        parent::__construct();
1✔
25
    }
26

27
    protected function execute(InputInterface $input, OutputInterface $output): int
28
    {
29
        $rows = [];
1✔
30

31
        foreach ($this->config->descriptors as $descriptor) {
1✔
32
            $rows[] = [
1✔
33
                $descriptor->id,
1✔
34
                $descriptor->parent,
1✔
35
                implode(' ', $descriptor->required),
1✔
36
                implode(' ', $descriptor->models),
1✔
37
                self::cwd_relative($descriptor->path ?? ''),
1✔
38
            ];
1✔
39
        }
40

41
        $table = new Table($output);
1✔
42
        $table->setHeaders([ 'Id', 'Parent', 'Required', 'Models', 'Path' ]);
1✔
43
        $table->setRows($rows);
1✔
44
        $table->setStyle($this->style);
1✔
45
        $table->render();
1✔
46

47
        return Command::SUCCESS;
1✔
48
    }
49

50
    private static function cwd_relative(string $path): string
51
    {
52
        if (!$path) {
1✔
53
            return $path;
1✔
54
        }
55

56
        $cwd = getcwd();
1✔
57

58
        assert(is_string($cwd));
59

60
        if (str_starts_with($path, $cwd)) {
1✔
61
            return substr($path, strlen($cwd) + 1);
1✔
62
        }
63

64
        return $path;
×
65
    }
66
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc