Completed
Push — master ( 10cab8...549589 )
by Pierre
35:30 queued 32:24
created

Terminal   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 63
ccs 0
cts 20
cp 0
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setDimensions() 0 26 5
A __construct() 0 3 1
A isWindows() 0 3 1
1
<?php
2
3
namespace App\Component\Console;
4
5
use App\Component\Console\Dimensions;
0 ignored issues
show
Bug introduced by
The type App\Component\Console\Dimensions was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use App\Component\Console\Process;
0 ignored issues
show
Bug introduced by
The type App\Component\Console\Process was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
class Terminal
9
{
10
11
    const TTY_DIM_COMMAND_0 = 'stty size';
12
    const TTY_DIM_COMMAND_1 = 'stty -a | grep rows';
13
    const _S = ' ';
14
15
    /**
16
     * terminal dimensions
17
     *
18
     * @var Dimensions
19
     */
20
    protected $dimensions;
21
22
    /**
23
     * instanciate
24
     */
25
    public function __construct()
26
    {
27
        $this->setDimensions();
28
    }
29
30
    /**
31
     * setDimensions
32
     *
33
     * @return void
34
     */
35
    protected function setDimensions(): Terminal
36
    {
37
        $this->dimensions = new Dimensions();
38
        if (!$this->isWindows()) {
39
            $matcher = [0,0,0];
40
            
41
            //$ttyDims = Process::readFromProcess(self::TTY_DIM_COMMAND_0);
42
            //echo $ttyDims;die;*/
43
            //var_dump($ttyDims);
44
            $ttyDims  = [];
45
            if (!empty($ttyDims)) {
46
                $matcher = explode(self::_S, self::_S . $ttyDims);
0 ignored issues
show
Bug introduced by
Are you sure $ttyDims of type array can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

46
                $matcher = explode(self::_S, self::_S . /** @scrutinizer ignore-type */ $ttyDims);
Loading history...
47
            } else {
48
                $ttyDims = Process::readFromProcess(self::TTY_DIM_COMMAND_1);
49
                var_dump($ttyDims);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($ttyDims) looks like debug code. Are you sure you do not want to remove it?
Loading history...
50
51
                if (preg_match('/(\d+)+;.\w{7}.(\d+)+;/', $ttyDims, $matches)) {
52
                    $matcher = $matches;
53
                } elseif (preg_match('/;(\d+).\w{4};.(\d+)/i', $ttyDims, $matches)) {
54
                    $matcher = $matches;
55
                }
56
            }
57
            var_dump($matcher, $ttyDims);
58
            $this->dimensions->set((int) $matcher[2], (int) $matcher[1]);
59
        }
60
        return $this;
61
    }
62
63
    /**
64
     * return true if microsoft platform
65
     *
66
     * @return boolean
67
     */
68
    protected function isWindows(): bool
69
    {
70
        return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
71
    }
72
}
73