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

ICanBoogie / bind-activerecord / 4437492734

pending completion
4437492734

push

github

Olivier Laviale
Use ActiveRecord's SchemaBuilder

28 of 28 new or added lines in 5 files covered. (100.0%)

38 of 119 relevant lines covered (31.93%)

0.39 hits per line

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

0.0
/lib/Console/InstallCommand.php
1
<?php
2

3
namespace ICanBoogie\Binding\ActiveRecord\Console;
4

5
use ICanBoogie\ActiveRecord\ModelIterator;
6
use ICanBoogie\ActiveRecord\ModelProvider;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Throwable;
11

12
use function array_filter;
13

14
final class InstallCommand extends Command
15
{
16
    protected static $defaultDescription = "Install models";
17

18
    public function __construct(
19
        private readonly ModelProvider $models,
20
        private readonly ModelIterator $iterator,
21
    ) {
22
        parent::__construct();
×
23
    }
24

25
    protected function execute(InputInterface $input, OutputInterface $output): int
26
    {
27
        $tried = [];
×
28

29
        $recursive_install = function (string $id) use (&$recursive_install, &$tried, $output): bool {
30
            if (isset($tried[$id])) {
×
31
                return $tried[$id];
×
32
            }
33

34
            $model = $this->models->model_for_id($id);
×
35

36
            if ($model->is_installed()) {
×
37
                $output->writeln("<info>Model already installed: $id</info>");
×
38

39
                return $tried[$id] = true;
×
40
            }
41

42
            $parent_id = $model->parent?->id;
×
43

44
            if ($parent_id) {
×
45
                $rc = $recursive_install($parent_id);
×
46

47
                if (!$rc) {
×
48
                    $output->writeln("<error>Unable to install model '$id', parent install failed: '{$parent_id}'");
×
49

50
                    return $tried[$id] = false;
×
51
                }
52
            }
53

54
            try {
55
                $model->install();
×
56
                $output->writeln("<info>Model installed: $id</info>");
×
57

58
                return $tried[$id] = true;
×
59
            } catch (Throwable $e) {
×
60
                $output->writeln("<error>Unable to install model '$id': {$e->getMessage()}</error>");
×
61
            }
62

63
            return $tried[$id] = false;
×
64
        };
65

66
        foreach ($this->iterator->model_iterator() as $id => $_) {
×
67
            $recursive_install($id);
×
68
        }
69

70
        return count(array_filter($tried, fn ($v) => $v === false))
×
71
            ? Command::FAILURE
×
72
            : Command::SUCCESS;
×
73
    }
74
}
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