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

codeigniter4 / CodeIgniter4 / 24122581833

08 Apr 2026 07:05AM UTC coverage: 86.507% (-0.05%) from 86.556%
24122581833

Pull #10086

github

web-flow
Merge 31d2b6fc8 into d636fe5d4
Pull Request #10086: feat(cast): Add precision and rounding mode in FloatCast

29 of 42 new or added lines in 4 files covered. (69.05%)

7 existing lines in 2 files now uncovered.

22721 of 26265 relevant lines covered (86.51%)

220.21 hits per line

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

90.32
/system/CLI/Console.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of CodeIgniter 4 framework.
7
 *
8
 * (c) CodeIgniter Foundation <admin@codeigniter.com>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace CodeIgniter\CLI;
15

16
use CodeIgniter\CodeIgniter;
17
use Config\App;
18
use Config\Services;
19

20
/**
21
 * @see \CodeIgniter\CLI\ConsoleTest
22
 */
23
class Console
24
{
25
    /**
26
     * @internal
27
     */
28
    public const DEFAULT_COMMAND = 'list';
29

30
    private string $command = '';
31

32
    /**
33
     * @var array<string, list<string|null>|string|null>
34
     */
35
    private array $options = [];
36

37
    /**
38
     * Runs the current command discovered on the CLI.
39
     *
40
     * @param list<string> $tokens
41
     *
42
     * @return int|null Exit code or null for legacy commands that don't return an exit code.
43
     */
44
    public function run(array $tokens = [])
45
    {
46
        if ($tokens === []) {
188✔
47
            $tokens = service('superglobals')->server('argv', []);
11✔
48
        }
49

50
        $parser = new CommandLineParser($tokens);
188✔
51

52
        $arguments     = $parser->getArguments();
188✔
53
        $this->options = $parser->getOptions();
188✔
54

55
        $this->showHeader($this->hasParameterOption(['no-header']));
188✔
56
        unset($this->options['no-header']);
188✔
57

58
        if ($this->hasParameterOption(['help'])) {
188✔
59
            unset($this->options['help']);
3✔
60

61
            if ($arguments === []) {
3✔
62
                $arguments = ['help', self::DEFAULT_COMMAND];
1✔
63
            } elseif ($arguments[0] !== 'help') {
2✔
64
                array_unshift($arguments, 'help');
1✔
65
            }
66
        }
67

68
        $this->command = array_shift($arguments) ?? self::DEFAULT_COMMAND;
188✔
69

70
        return service('commands')->run($this->command, array_merge($arguments, $this->options));
188✔
71
    }
72

73
    public function initialize(): static
74
    {
UNCOV
75
        Services::createRequest(config(App::class), true);
×
UNCOV
76
        service('routes')->loadRoutes();
×
77

UNCOV
78
        return $this;
×
79
    }
80

81
    /**
82
     * Returns the command that is being executed.
83
     */
84
    public function getCommand(): string
85
    {
86
        return $this->command;
1✔
87
    }
88

89
    /**
90
     * Displays basic information about the Console.
91
     *
92
     * @return void
93
     */
94
    public function showHeader(bool $suppress = false)
95
    {
96
        if ($suppress) {
188✔
97
            return;
178✔
98
        }
99

100
        CLI::write(sprintf(
10✔
101
            'CodeIgniter v%s Command Line Tool - Server Time: %s',
10✔
102
            CodeIgniter::CI_VERSION,
10✔
103
            date('Y-m-d H:i:s \\U\\T\\CP'),
10✔
104
        ), 'green');
10✔
105
        CLI::newLine();
10✔
106
    }
107

108
    /**
109
     * Checks whether any of the options are present in the command line.
110
     *
111
     * @param list<string> $options
112
     */
113
    private function hasParameterOption(array $options): bool
114
    {
115
        foreach ($options as $option) {
188✔
116
            if (array_key_exists($option, $this->options)) {
188✔
117
                return true;
181✔
118
            }
119
        }
120

121
        return false;
188✔
122
    }
123
}
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

© 2026 Coveralls, Inc