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

ICanBoogie / bind-activerecord / 6361577548

30 Sep 2023 08:34AM UTC coverage: 31.624% (-2.6%) from 34.211%
6361577548

push

github

olvlvl
Tidy

24 of 24 new or added lines in 2 files covered. (100.0%)

37 of 117 relevant lines covered (31.62%)

0.34 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;
6
use ICanBoogie\ActiveRecord\ModelIterator;
7
use ICanBoogie\ActiveRecord\ModelProvider;
8
use Symfony\Component\Console\Attribute\AsCommand;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
use Throwable;
13

14
use function array_filter;
15
use function sprintf;
16

17
#[AsCommand('activerecord:install', "Install models")]
18
final class InstallCommand extends Command
19
{
20
    public function __construct(
21
        private readonly ModelProvider $models,
22
        private readonly ModelIterator $iterator,
23
    ) {
24
        parent::__construct();
×
25
    }
26

27
    protected function execute(InputInterface $input, OutputInterface $output): int
28
    {
29
        /**
30
         * @var array<class-string<ActiveRecord>, true|null> $tried
31
         */
32
        $tried = [];
×
33

34
        $recursive_install = function (string $activerecord_class) use (&$recursive_install, &$tried, $output): bool {
35
            /** @var class-string<ActiveRecord> $activerecord_class */
36

37
            if (isset($tried[$activerecord_class])) {
×
38
                return $tried[$activerecord_class];
×
39
            }
40

41
            $model = $this->models->model_for_record($activerecord_class);
×
42

43
            if ($model->is_installed()) {
×
44
                $output->writeln("<info>Model already installed: $activerecord_class</info>");
×
45

46
                return $tried[$activerecord_class] = true;
×
47
            }
48

49
            $parent_activerecord_class = $model->parent?->activerecord_class;
×
50

51
            if ($parent_activerecord_class) {
×
52
                $rc = $recursive_install($parent_activerecord_class);
×
53

54
                if (!$rc) {
×
55
                    $output->writeln(
×
56
                        sprintf(
×
57
                            "<error>Unable to install model '%s', parent install failed: '%s'",
×
58
                            $activerecord_class,
×
59
                            $parent_activerecord_class
×
60
                        )
×
61
                    );
×
62

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

67
            try {
68
                $model->install();
×
69
                $output->writeln("<info>Model installed: $activerecord_class</info>");
×
70

71
                return $tried[$activerecord_class] = true;
×
72
            } catch (Throwable $e) {
×
73
                $output->writeln("<error>Unable to install model '$activerecord_class': {$e->getMessage()}</error>");
×
74
            }
75

76
            return $tried[$activerecord_class] = false;
×
77
        };
78

79
        foreach ($this->iterator->model_iterator() as $activerecord_class => $_) {
×
80
            $recursive_install($activerecord_class);
×
81
        }
82

83
        return count(array_filter($tried, fn($v) => $v === false))
×
84
            ? Command::FAILURE
×
85
            : Command::SUCCESS;
×
86
    }
87
}
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