Tty   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 18
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A isTtySupported() 0 11 3
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