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

ConsoleHelper   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 10
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 27
rs 10
c 10
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A mockWindowsOs() 0 3 1
A canUseLaravelPrompts() 0 7 4
A disableLaravelPrompts() 0 3 1
A clearMocks() 0 3 1
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