Linux   A
last analyzed

Coupling/Cohesion

Components 1
Dependencies 1

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 46.15%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 70
ccs 6
cts 13
cp 0.4615
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A width() 0 4 1
A height() 0 4 1
A getDimension() 0 4 2
A systemHasAnsiSupport() 0 4 2
A canAccessBash() 0 4 1
A hiddenResponsePrompt() 0 6 1
1
<?php
2
3
namespace League\CLImate\Util\System;
4
5
class Linux extends System
6
{
7
    /**
8
     * Get the width of the terminal
9
     *
10
     * @return integer|null
11
     */
12 8
    public function width()
13
    {
14 8
        return $this->getDimension($this->exec('tput cols'));
15
    }
16
17
    /**
18
     * Get the height of the terminal
19
     *
20
     * @return integer|null
21
     */
22 8
    public function height()
23
    {
24 8
        return $this->getDimension($this->exec('tput lines'));
25
    }
26
27
    /**
28
     * Determine if system has access to bash commands
29
     *
30
     * @return bool
31
     */
32
    public function canAccessBash()
33
    {
34
        return (rtrim($this->exec("/usr/bin/env bash -c 'echo OK'")) === 'OK');
35
    }
36
37
    /**
38
     * Display a hidden response prompt and return the response
39
     *
40
     * @param string $prompt
41
     *
42
     * @return string
43
     */
44
    public function hiddenResponsePrompt($prompt)
45
    {
46
        $bash_command = 'read -s -p "' . $prompt . '" response && echo $response';
47
48
        return rtrim($this->exec("/usr/bin/env bash -c '{$bash_command}'"));
49
    }
50
51
    /**
52
     * Determine if dimension is numeric and return it
53
     *
54
     * @param integer|string|null $dimension
55
     *
56
     * @return integer|null
57
     */
58 16
    protected function getDimension($dimension)
59
    {
60 16
        return (is_numeric($dimension)) ? $dimension : null;
61
    }
62
63
    /**
64
     * Check if the stream supports ansi escape characters.
65
     *
66
     * Based on https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Output/StreamOutput.php
67
     *
68
     * @return bool
69
     */
70
    protected function systemHasAnsiSupport()
71
    {
72
        return (function_exists('posix_isatty') && @posix_isatty(STDOUT));
73
    }
74
}
75