Tty::isTtySupported()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
namespace Consolidation\SiteProcess\Util;
3
4
use Symfony\Component\Process\Process;
5
6
/**
7
 * Wrapper for universal support of TTY-related functionality across versions of
8
 * Symfony Process.
9
 */
10
class Tty
11
{
12
    /**
13
     * In Symfony Process 4+, this is simply a wrapper for Process::isTtySupported().
14
     * In lower versions, it mimics the same functionality.
15
     */
16
    public static function isTtySupported()
17
    {
18
        // Start off by checking STDIN with `posix_isatty`, as that appears to be more reliable
19
        if (function_exists('posix_isatty')) {
20
            return posix_isatty(STDIN);
21
        }
22
        if (method_exists('\Symfony\Component\Process\Process', 'isTtySupported')) {
23
            return Process::isTtySupported();
24
        }
25
        return (bool) @proc_open('echo 1 >/dev/null', array(array('file', '/dev/tty', 'r'), array('file', '/dev/tty', 'w'), array('file', '/dev/tty', 'w')), $pipes);
26
    }
27
}
28