forked from spaceemotion/php-coding-standard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCli.php
More file actions
65 lines (43 loc) · 1.35 KB
/
Cli.php
File metadata and controls
65 lines (43 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types=1);
namespace Spaceemotion\PhpCodingStandard;
use function stream_set_blocking;
use const STDIN;
class Cli
{
public const FLAG_CI = 'ci';
public const FLAG_INTERACTIVE = 'interactive';
public const FLAG_CONTINUE = 'continue';
public const FLAG_FIX = 'fix';
public const FLAG_ANSI = 'ansi';
public const FLAG_HIDE_SOURCE = 'hide-source';
public const FLAG_LINT_STAGED = 'lint-staged';
public const FLAG_NO_FAIL = 'no-fail';
public const PARAMETER_SKIP = 'skip';
public const PARAMETER_ONLY = 'only';
public const PARAMETER_MEMORY_LIMIT = 'memory-limit';
public static function isOnWindows(): bool
{
return PHP_OS_FAMILY === 'Windows';
}
/**
* @return string[]
*/
public static function parseFilesFromInput(): array
{
// Windows does not support nonblocking input streams:
// https://bugs.php.net/bug.php?id=34972
if (self::isOnWindows()) {
return [];
}
// Don't block execution if we don't have any piped input
stream_set_blocking(STDIN, false);
// Read each file path per line from the input
$files = [];
while (($file = fgets(STDIN)) !== false) {
$files[] = trim($file);
}
stream_set_blocking(STDIN, true);
return $files;
}
}