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

codeigniter4 / CodeIgniter4 / 8677009716

13 Apr 2024 11:45PM UTC coverage: 84.44% (-2.2%) from 86.607%
8677009716

push

github

web-flow
Merge pull request #8776 from kenjis/fix-findQualifiedNameFromPath-Cannot-declare-class-v3

fix: Cannot declare class CodeIgniter\Config\Services, because the name is already in use

0 of 3 new or added lines in 1 file covered. (0.0%)

478 existing lines in 72 files now uncovered.

20318 of 24062 relevant lines covered (84.44%)

188.23 hits per line

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

66.67
/system/CLI/InputOutput.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
/**
17
 * Input and Output for CLI.
18
 */
19
class InputOutput
20
{
21
    /**
22
     * Is the readline library on the system?
23
     */
24
    private readonly bool $readlineSupport;
25

26
    public function __construct()
27
    {
28
        // Readline is an extension for PHP that makes interactivity with PHP
29
        // much more bash-like.
30
        // http://www.php.net/manual/en/readline.installation.php
31
        $this->readlineSupport = extension_loaded('readline');
37✔
32
    }
33

34
    /**
35
     * Get input from the shell, using readline or the standard STDIN
36
     *
37
     * Named options must be in the following formats:
38
     * php index.php user -v --v -name=John --name=John
39
     *
40
     * @param string|null $prefix You may specify a string with which to prompt the user.
41
     */
42
    public function input(?string $prefix = null): string
43
    {
44
        // readline() can't be tested.
45
        if ($this->readlineSupport && ENVIRONMENT !== 'testing') {
4✔
UNCOV
46
            return readline($prefix); // @codeCoverageIgnore
×
47
        }
48

49
        echo $prefix;
4✔
50

51
        $input = fgets(fopen('php://stdin', 'rb'));
4✔
52

53
        if ($input === false) {
4✔
54
            $input = '';
×
55
        }
56

57
        return $input;
4✔
58
    }
59

60
    /**
61
     * While the library is intended for use on CLI commands,
62
     * commands can be called from controllers and elsewhere
63
     * so we need a way to allow them to still work.
64
     *
65
     * For now, just echo the content, but look into a better
66
     * solution down the road.
67
     *
68
     * @param resource $handle
69
     */
70
    public function fwrite($handle, string $string): void
71
    {
72
        if (! is_cli()) {
180✔
73
            echo $string;
×
74

75
            return;
×
76
        }
77

78
        fwrite($handle, $string);
180✔
79
    }
80
}
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