Shell::getDocumentWidthUnix()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
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