11<?php
2-
3-
42namespace Ubiquity \devtools \cmd ;
53
64/**
75 * Class Screen
86 * Forked from https://github.com/symfony/console/blob/5.3/Terminal.php
9- * @package Ubiquity\devtools\cmd
7+ *
8+ * @package Ubiquity.devtools
109 */
1110class Screen {
11+
1212 private static $ width ;
13+
1314 private static $ height ;
15+
1416 private static $ stty ;
1517
1618 /**
@@ -28,7 +30,7 @@ public static function getWidth() {
2830 self ::initDimensions ();
2931 }
3032
31- return self ::$ width?? 80 ;
33+ return self ::$ width ?? 80 ;
3234 }
3335
3436 /**
@@ -46,10 +48,11 @@ public static function getHeight() {
4648 self ::initDimensions ();
4749 }
4850
49- return self ::$ height?? 50 ;
51+ return self ::$ height ?? 50 ;
5052 }
5153
5254 /**
55+ *
5356 * @internal
5457 *
5558 * @return bool
@@ -60,7 +63,7 @@ public static function hasSttyAvailable() {
6063 }
6164
6265 // skip check if exec function is disabled
63- if (!\function_exists ('exec ' )) {
66+ if (! \function_exists ('exec ' )) {
6467 return false ;
6568 }
6669
@@ -76,7 +79,7 @@ private static function initDimensions() {
7679 // or [w, h] from "wxh"
7780 self ::$ width = (int ) $ matches [1 ];
7881 self ::$ height = isset ($ matches [4 ]) ? (int ) $ matches [4 ] : (int ) $ matches [2 ];
79- } elseif (!self ::hasVt100Support () && self ::hasSttyAvailable ()) {
82+ } elseif (! self ::hasVt100Support () && self ::hasSttyAvailable ()) {
8083 // only use stty on Windows if the terminal does not support vt100 (e.g. Windows 7 + git-bash)
8184 // testing for stty in a Windows 10 vt100-enabled console will implicitly disable vt100 support on STDOUT
8285 self ::initDimensionsUsingStty ();
@@ -122,11 +125,14 @@ private static function initDimensionsUsingStty() {
122125 private static function getConsoleMode (): ?array {
123126 $ info = self ::readFromProcess ('mode CON ' );
124127
125- if (null === $ info || !preg_match ('/--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/ ' , $ info , $ matches )) {
128+ if (null === $ info || ! preg_match ('/--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/ ' , $ info , $ matches )) {
126129 return null ;
127130 }
128131
129- return [(int ) $ matches [2 ], (int ) $ matches [1 ]];
132+ return [
133+ (int ) $ matches [2 ],
134+ (int ) $ matches [1 ]
135+ ];
130136 }
131137
132138 /**
@@ -137,17 +143,25 @@ private static function getSttyColumns(): ?string {
137143 }
138144
139145 private static function readFromProcess (string $ command ): ?string {
140- if (!\function_exists ('proc_open ' )) {
146+ if (! \function_exists ('proc_open ' )) {
141147 return null ;
142148 }
143149
144150 $ descriptorspec = [
145- 1 => ['pipe ' , 'w ' ],
146- 2 => ['pipe ' , 'w ' ],
151+ 1 => [
152+ 'pipe ' ,
153+ 'w '
154+ ],
155+ 2 => [
156+ 'pipe ' ,
157+ 'w '
158+ ]
147159 ];
148160
149- $ process = \proc_open ($ command , $ descriptorspec , $ pipes , null , null , ['suppress_errors ' => true ]);
150- if (!\is_resource ($ process )) {
161+ $ process = \proc_open ($ command , $ descriptorspec , $ pipes , null , null , [
162+ 'suppress_errors ' => true
163+ ]);
164+ if (! \is_resource ($ process )) {
151165 return null ;
152166 }
153167
0 commit comments