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

codeigniter4 / shield / 10587800883

28 Aug 2024 12:14AM UTC coverage: 92.788% (-0.03%) from 92.822%
10587800883

push

github

web-flow
Merge pull request #1190 from datamweb/chore-fix-phpstan

chore: fix phpstan error for `$credentials`

2792 of 3009 relevant lines covered (92.79%)

49.08 hits per line

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

77.78
/src/Commands/BaseCommand.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of CodeIgniter Shield.
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\Shield\Commands;
15

16
use CodeIgniter\CLI\BaseCommand as FrameworkBaseCommand;
17
use CodeIgniter\CLI\Commands;
18
use CodeIgniter\Shield\Commands\Utils\InputOutput;
19
use Psr\Log\LoggerInterface;
20

21
abstract class BaseCommand extends FrameworkBaseCommand
22
{
23
    protected static ?InputOutput $io = null;
24

25
    /**
26
     * The group the command is lumped under
27
     * when listing commands.
28
     *
29
     * @var string
30
     */
31
    protected $group = 'Shield';
32

33
    public function __construct(LoggerInterface $logger, Commands $commands)
34
    {
35
        parent::__construct($logger, $commands);
68✔
36

37
        $this->ensureInputOutput();
68✔
38
    }
39

40
    /**
41
     * Asks the user for input.
42
     *
43
     * @param string       $field      Output "field" question
44
     * @param array|string $options    String to a default value, array to a list of options (the first option will be the default value)
45
     * @param array|string $validation Validation rules
46
     *
47
     * @return string The user input
48
     */
49
    protected function prompt(string $field, $options = null, $validation = null): string
50
    {
51
        return self::$io->prompt($field, $options, $validation);
36✔
52
    }
53

54
    /**
55
     * Outputs a string to the cli on its own line.
56
     */
57
    protected function write(
58
        string $text = '',
59
        ?string $foreground = null,
60
        ?string $background = null
61
    ): void {
62
        self::$io->write($text, $foreground, $background);
64✔
63
    }
64

65
    /**
66
     * Outputs an error to the CLI using STDERR instead of STDOUT
67
     */
68
    protected function error(
69
        string $text,
70
        string $foreground = 'light_red',
71
        ?string $background = null
72
    ): void {
73
        self::$io->error($text, $foreground, $background);
×
74
    }
75

76
    protected function ensureInputOutput(): void
77
    {
78
        if (self::$io === null) {
68✔
79
            self::$io = new InputOutput();
×
80
        }
81
    }
82

83
    /**
84
     * @internal Testing purpose only
85
     */
86
    public static function setInputOutput(InputOutput $io): void
87
    {
88
        self::$io = $io;
64✔
89
    }
90

91
    /**
92
     * @internal Testing purpose only
93
     */
94
    public static function resetInputOutput(): void
95
    {
96
        self::$io = null;
58✔
97
    }
98
}
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