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

ICanBoogie / Module / 4256938836

pending completion
4256938836

push

github

Olivier Laviale
Replace descriptor files with configuration fragments

135 of 448 relevant lines covered (30.13%)

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
    protected static $defaultDescription = "List modules";
21

22
    public function __construct(
23
        private readonly Config $config,
24
        private readonly string $style,
25
    ) {
26
        parent::__construct();
1✔
27
    }
28

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

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

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

49
        return Command::SUCCESS;
1✔
50
    }
51

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

58
        $cwd = getcwd();
1✔
59

60
        assert(is_string($cwd));
61

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

66
        return $path;
×
67
    }
68
}
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