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

daycry / auth / 22527357078

28 Feb 2026 07:22PM UTC coverage: 63.267% (+0.7%) from 62.568%
22527357078

push

github

daycry
Remove PHP 8.1 from PHPUnit CI matrix

Update .github/workflows/phpunit.yml to drop PHP 8.1 from the test matrix. CI will now run PHPUnit only on PHP 8.2 and 8.3, reducing the matrix to current supported versions.

3064 of 4843 relevant lines covered (63.27%)

41.52 hits per line

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

0.0
/src/CLI/CustomCLI.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of Daycry Auth.
7
 *
8
 * (c) Daycry <daycry9@proton.me>
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 Daycry\Auth\CLI;
15

16
use CodeIgniter\CLI\CLI;
17
use Config\Services;
18
use InvalidArgumentException;
19

20
class CustomCLI extends CLI
21
{
22
    /**
23
     * Asks the user for input.
24
     *
25
     * Usage:
26
     *
27
     * // Takes any input
28
     * $color = CLI::prompt('What is your favorite color?');
29
     *
30
     * // Takes any input, but offers default
31
     * $color = CLI::prompt('What is your favourite color?', 'white');
32
     *
33
     * // Will validate options with the in_list rule and accept only if one of the list
34
     * $color = CLI::prompt('What is your favourite color?', array('red','blue'));
35
     *
36
     * // Do not provide options but requires a valid email
37
     * $email = CLI::prompt('What is your email?', null, 'required|valid_email');
38
     *
39
     * @param string            $field      Output "field" question
40
     * @param array|string      $options    String to a default value, array to a list of options (the first option will be the default value)
41
     * @param array|string|null $validation Validation rules
42
     *
43
     * @return string The user input
44
     *
45
     * @codeCoverageIgnore
46
     */
47
    public static function prompt(string $field, $options = null, $validation = null, ?string $DBGroup = null): string
×
48
    {
49
        $extraOutput = '';
×
50
        $default     = '';
×
51

52
        if ($validation && ! is_array($validation) && ! is_string($validation)) {
×
53
            throw new InvalidArgumentException('$rules can only be of type string|array');
×
54
        }
55

56
        if (! is_array($validation)) {
×
57
            $validation = $validation ? explode('|', $validation) : [];
×
58
        }
59

60
        if (is_string($options)) {
×
61
            $extraOutput = ' [' . static::color($options, 'green') . ']';
×
62
            $default     = $options;
×
63
        }
64

65
        if (is_array($options) && $options) {
×
66
            $opts               = $options;
×
67
            $extraOutputDefault = static::color($opts[0], 'green');
×
68

69
            unset($opts[0]);
×
70

71
            if ($opts === []) {
×
72
                $extraOutput = $extraOutputDefault;
×
73
            } else {
74
                $extraOutput  = '[' . $extraOutputDefault . ', ' . implode(', ', $opts) . ']';
×
75
                $validation[] = 'in_list[' . implode(', ', $options) . ']';
×
76
            }
77

78
            $default = $options[0];
×
79
        }
80

81
        static::fwrite(STDOUT, $field . (trim($field) !== '' && trim($field) !== '0' ? ' ' : '') . $extraOutput . ': ');
×
82

83
        // Read the input from keyboard.
84
        $input = trim(static::input()) ?: $default;
×
85

86
        if ($validation !== []) {
×
87
            while (! static::validate('"' . trim($field) . '"', $input, $validation, $DBGroup)) {
×
88
                $input = static::prompt($field, $options, $validation, $DBGroup);
×
89
            }
90
        }
91

92
        return $input;
×
93
    }
94

95
    /**
96
     * Validate one prompt "field" at a time
97
     *
98
     * @param string       $field Prompt "field" output
99
     * @param string       $value Input value
100
     * @param array|string $rules Validation rules
101
     *
102
     * @codeCoverageIgnore
103
     */
104
    protected static function validate(string $field, string $value, $rules, ?string $DBGroup = null): bool
×
105
    {
106
        $label      = $field;
×
107
        $field      = 'temp';
×
108
        $validation = Services::validation(null, false);
×
109
        $validation->setRules([
×
110
            $field => [
×
111
                'label' => $label,
×
112
                'rules' => $rules,
×
113
            ],
×
114
        ]);
×
115
        $validation->run([$field => $value], null, $DBGroup);
×
116

117
        if ($validation->hasError($field)) {
×
118
            static::error($validation->getError($field));
×
119

120
            return false;
×
121
        }
122

123
        return true;
×
124
    }
125
}
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