Passed
Push — master ( ad6b2a...b41ca0 )
by Caen
07:45 queued 14s
created

ConsoleHelper::canUseLaravelPrompts()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 3
nc 4
nop 1
dl 0
loc 7
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Console\Helpers;
6
7
use Laravel\Prompts\Prompt;
8
use Symfony\Component\Console\Input\InputInterface;
9
10
/**
11
 * @internal This class contains internal helpers for interacting with the console, and for easier testing.
12
 *
13
 * @codeCoverageIgnore This class provides internal testing helpers and does not need to be tested.
14
 */
15
class ConsoleHelper
16
{
17
    /** Allows for mocking the Windows OS check. Remember to clear the mock after the test. */
18
    protected static ?bool $enableLaravelPrompts = null;
19
20
    public static function clearMocks(): void
21
    {
22
        static::$enableLaravelPrompts = null;
23
    }
24
25
    public static function disableLaravelPrompts(): void
26
    {
27
        static::$enableLaravelPrompts = false;
28
    }
29
30
    public static function mockWindowsOs(bool $isWindowsOs): void
31
    {
32
        static::$enableLaravelPrompts = ! $isWindowsOs;
33
    }
34
35
    public static function canUseLaravelPrompts(InputInterface $input): bool
36
    {
37
        if (static::$enableLaravelPrompts !== null) {
38
            return static::$enableLaravelPrompts;
39
        }
40
41
        return $input->isInteractive() && windows_os() === false && Prompt::shouldFallback() === false;
42
    }
43
}
44