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

JBZoo / Cli / 29985090680

20 Jul 2026 08:59PM UTC coverage: 82.146%. Remained the same
29985090680

push

github

web-flow
Merge pull request #37 from JBZoo/release/8.0

8.0.0 — PHP 8.3+ floor & lock-step major

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

11 existing lines in 2 files now uncovered.

1072 of 1305 relevant lines covered (82.15%)

235.21 hits per line

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

66.67
/src/CliApplication.php
1
<?php
2

3
/**
4
 * JBZoo Toolbox - Cli.
5
 *
6
 * This file is part of the JBZoo Toolbox project.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT
11
 * @copyright  Copyright (C) JBZoo.com, All rights reserved.
12
 * @see        https://github.com/JBZoo/Cli
13
 */
14

15
declare(strict_types=1);
16

17
namespace JBZoo\Cli;
18

19
use JBZoo\Cli\OutputMods\AbstractOutputMode;
20
use JBZoo\Cli\OutputMods\Text;
21
use JBZoo\Event\EventManager;
22
use JBZoo\Utils\FS;
23
use Symfony\Component\Console\Application;
24
use Symfony\Component\Console\Output\OutputInterface;
25

26
use function JBZoo\Utils\isStrEmpty;
27

28
/**
29
 * @psalm-suppress ClassMustBeFinal
30
 */
31
class CliApplication extends Application
32
{
33
    private ?EventManager       $eventManager = null;
34
    private ?string             $logo         = null;
35
    private ?AbstractOutputMode $outputMode   = null;
36

37
    /**
38
     * Register commands by directory path.
39
     */
40
    public function registerCommandsByPath(
41
        string $commandsDir,
42
        string $gloabalNamespace,
43
        bool $strictMode = true,
44
    ): self {
45
        if ($strictMode && !\is_dir($commandsDir)) {
852✔
46
            throw new Exception('First argument is not directory!');
×
47
        }
48

49
        /** @var string[] $files */
50
        $files = FS::ls($commandsDir);
852✔
51
        $files = \array_filter($files, static function (string $file) {
852✔
52
            return \str_ends_with($file, '.php');
852✔
53
        });
852✔
54

55
        if (\count($files) === 0) {
852✔
56
            return $this;
×
57
        }
58

59
        foreach ($files as $file) {
852✔
60
            if (!\file_exists($file)) {
852✔
61
                continue;
×
62
            }
63

64
            require_once $file;
852✔
65

66
            $taskNamespace    = \trim(\str_replace('/', '\\', (string)\strstr(\dirname($file), 'Commands')));
852✔
67
            $commandClassName = "{$gloabalNamespace}\\{$taskNamespace}\\" . FS::filename($file);
852✔
68

69
            if (\class_exists($commandClassName)) {
852✔
70
                $reflection = new \ReflectionClass($commandClassName);
852✔
71
            } else {
72
                throw new Exception("Command/Class \"{$commandClassName}\" can'be loaded from the file \"{$file}\"");
×
73
            }
74

75
            if (!$reflection->isAbstract() && $reflection->isSubclassOf(CliCommand::class)) {
852✔
76
                $command = $reflection->newInstance();
852✔
77
                // Symfony Console 8.0 removed Application::add(); addCommands() exists on 7.3+/8.x.
78
                $this->addCommands([$command]);
852✔
79
            }
80
        }
81

82
        return $this;
852✔
83
    }
84

85
    public function setEventManager(EventManager $eventManager): self
86
    {
UNCOV
87
        $this->eventManager = $eventManager;
×
88

UNCOV
89
        return $this;
×
90
    }
91

92
    public function getEventManager(): ?EventManager
93
    {
94
        return $this->eventManager;
858✔
95
    }
96

97
    public function setLogo(?string $logo = null): self
98
    {
UNCOV
99
        $this->logo = $logo;
×
100

UNCOV
101
        return $this;
×
102
    }
103

104
    /**
105
     * @SuppressWarnings(ShortVariable)
106
     */
107
    public function renderThrowable(\Throwable $e, OutputInterface $output): void
108
    {
109
        if ($this->outputMode === null || $this->outputMode instanceof Text) {
132✔
110
            parent::renderThrowable($e, $output);
90✔
111
        }
112
    }
113

114
    /**
115
     * Returns the long version of the application.
116
     */
117
    public function getLongVersion(): string
118
    {
UNCOV
119
        if (!isStrEmpty($this->logo)) {
×
120
            return "<info>{$this->logo}</info>\n<comment>{$this->getVersion()}</comment>";
×
121
        }
122

UNCOV
123
        return parent::getLongVersion();
×
124
    }
125

126
    public function setOutputMode(AbstractOutputMode $outputMode): self
127
    {
128
        $this->outputMode = $outputMode;
858✔
129

130
        return $this;
858✔
131
    }
132
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc