Shell   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 28
ccs 5
cts 6
cp 0.8333
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDocumentWidthWindows() 0 4 1
A getDocumentWidthFromOS() 0 7 3
A getDocumentWidthUnix() 0 3 1
1
<?php
2
3
namespace VPA\Console;
4
5
use VPA\DI\Injectable;
6
7
#[Injectable]
8
class Shell
9
{
10 1
    public function getDocumentWidthFromOS(): int
11
    {
12 1
        $os = (PHP_OS_FAMILY === 'Windows' ? 'Windows' : isset($_SERVER['TERM'])) ? 'Unix' : 'undefined';
13 1
        return match ($os) {
14
            'Windows' => $this->getDocumentWidthWindows(),
15 1
            'Unix' => $this->getDocumentWidthUnix(),
16 1
            default => 80
17
        };
18
    }
19
20
    /**
21
     * @codeCoverageIgnore
22
     */
23
    private function getDocumentWidthWindows(): int
24
    {
25
        $arr = explode("\n", shell_exec('mode con') ?? "");
26
        return intval(explode(':', $arr[4])[1]);
27
    }
28
29
    /**
30
     * @codeCoverageIgnore
31
     */
32
    private function getDocumentWidthUnix(): int
33
    {
34
        return intval(exec('tput cols'));
35
    }
36
}
37