Skip to content

Commit 072f9f7

Browse files
authored
Fix "Argument #1 ($string) must be of type string, bool given" (#11)
* Fix "Argument #1 ($string) must be of type string, bool given" * Update Terminal.php * extract method * Update Terminal.php * Update Terminal.php
1 parent f88ab09 commit 072f9f7

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/Console/Terminal.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ private static function initDimensions(): void
5555
$consoleMode = self::getConsoleMode();
5656

5757
if ('\\' === \DIRECTORY_SEPARATOR) {
58-
if (\preg_match('#^(\d+)x(\d+)(?: \((\d+)x(\d+)\))?$#', \trim(\getenv('ANSICON')), $matches)) {
59-
self::$width = (int) $matches[1];
58+
$width = self::getAnsiconWidth();
59+
if ($width !== null) {
60+
self::$width = $width;
6061
} elseif (! self::hasVt100Support() && self::hasSttyAvailable()) {
6162
self::initDimensionsUsingStty();
6263
} elseif ($consoleMode) {
@@ -123,4 +124,17 @@ private static function readFromProcess(string $command): ?string
123124
\proc_close($process);
124125
return $info;
125126
}
127+
128+
private static function getAnsiconWidth(): ?int
129+
{
130+
if (!is_string(\getenv('ANSICON'))) {
131+
return null;
132+
}
133+
134+
if (\preg_match('#^(\d+)x(\d+)(?: \((\d+)x(\d+)\))?$#', \trim(\getenv('ANSICON')), $matches)) {
135+
return (int) $matches[1];
136+
}
137+
138+
return null;
139+
}
126140
}

0 commit comments

Comments
 (0)