@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | $multiselect = $this->multiselect; |
| 123 | 123 | $isAssoc = $this->isAssoc($choices); |
| 124 | 124 | |
| 125 | - return function ($selected) use ($choices, $errorMessage, $multiselect, $isAssoc) { |
|
| 125 | + return function($selected) use ($choices, $errorMessage, $multiselect, $isAssoc) { |
|
| 126 | 126 | if ($multiselect) { |
| 127 | 127 | // Check for a separated comma values |
| 128 | 128 | if (!preg_match('/^[^,]+(?:,[^,]+)*$/', $selected, $matches)) { |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | // For associative choices, consistently return the key as string: |
| 173 | - $multiselectChoices[] = $isAssoc ? (string) $result : $result; |
|
| 173 | + $multiselectChoices[] = $isAssoc ? (string)$result : $result; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | if ($multiselect) { |
@@ -41,12 +41,12 @@ |
||
| 41 | 41 | $default = $this->getDefault(); |
| 42 | 42 | $regex = $this->trueAnswerRegex; |
| 43 | 43 | |
| 44 | - return function ($answer) use ($default, $regex) { |
|
| 44 | + return function($answer) use ($default, $regex) { |
|
| 45 | 45 | if (\is_bool($answer)) { |
| 46 | 46 | return $answer; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - $answerIsTrue = (bool) preg_match($regex, $answer); |
|
| 49 | + $answerIsTrue = (bool)preg_match($regex, $answer); |
|
| 50 | 50 | if (false === $default) { |
| 51 | 51 | return $answer && $answerIsTrue; |
| 52 | 52 | } |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | throw new LogicException('A hidden question cannot use the autocompleter.'); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - $this->hidden = (bool) $hidden; |
|
| 110 | + $this->hidden = (bool)$hidden; |
|
| 111 | 111 | |
| 112 | 112 | return $this; |
| 113 | 113 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | */ |
| 132 | 132 | public function setHiddenFallback($fallback) |
| 133 | 133 | { |
| 134 | - $this->hiddenFallback = (bool) $fallback; |
|
| 134 | + $this->hiddenFallback = (bool)$fallback; |
|
| 135 | 135 | |
| 136 | 136 | return $this; |
| 137 | 137 | } |
@@ -160,12 +160,12 @@ discard block |
||
| 160 | 160 | if (\is_array($values)) { |
| 161 | 161 | $values = $this->isAssoc($values) ? array_merge(array_keys($values), array_values($values)) : array_values($values); |
| 162 | 162 | |
| 163 | - $callback = static function () use ($values) { |
|
| 163 | + $callback = static function() use ($values) { |
|
| 164 | 164 | return $values; |
| 165 | 165 | }; |
| 166 | 166 | } elseif ($values instanceof \Traversable) { |
| 167 | 167 | $valueCache = null; |
| 168 | - $callback = static function () use ($values, &$valueCache) { |
|
| 168 | + $callback = static function() use ($values, &$valueCache) { |
|
| 169 | 169 | return $valueCache ?? $valueCache = iterator_to_array($values, false); |
| 170 | 170 | }; |
| 171 | 171 | } else { |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | public function setMaxAttempts(?int $attempts) |
| 236 | 236 | { |
| 237 | 237 | if (null !== $attempts) { |
| 238 | - $attempts = (int) $attempts; |
|
| 238 | + $attempts = (int)$attempts; |
|
| 239 | 239 | if ($attempts < 1) { |
| 240 | 240 | throw new InvalidArgumentException('Maximum number of attempts must be a positive value.'); |
| 241 | 241 | } |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | |
| 287 | 287 | protected function isAssoc(array $array) |
| 288 | 288 | { |
| 289 | - return (bool) \count(array_filter(array_keys($array), 'is_string')); |
|
| 289 | + return (bool)\count(array_filter(array_keys($array), 'is_string')); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | public function isTrimmable(): bool |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | { |
| 27 | 27 | $width = getenv('COLUMNS'); |
| 28 | 28 | if (false !== $width) { |
| 29 | - return (int) trim($width); |
|
| 29 | + return (int)trim($width); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | if (null === self::$width) { |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | { |
| 46 | 46 | $height = getenv('LINES'); |
| 47 | 47 | if (false !== $height) { |
| 48 | - return (int) trim($height); |
|
| 48 | + return (int)trim($height); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | if (null === self::$height) { |
@@ -82,16 +82,16 @@ discard block |
||
| 82 | 82 | if (preg_match('/^(\d+)x(\d+)(?: \((\d+)x(\d+)\))?$/', trim(getenv('ANSICON')), $matches)) { |
| 83 | 83 | // extract [w, H] from "wxh (WxH)" |
| 84 | 84 | // or [w, h] from "wxh" |
| 85 | - self::$width = (int) $matches[1]; |
|
| 86 | - self::$height = isset($matches[4]) ? (int) $matches[4] : (int) $matches[2]; |
|
| 85 | + self::$width = (int)$matches[1]; |
|
| 86 | + self::$height = isset($matches[4]) ? (int)$matches[4] : (int)$matches[2]; |
|
| 87 | 87 | } elseif (!self::hasVt100Support() && self::hasSttyAvailable()) { |
| 88 | 88 | // only use stty on Windows if the terminal does not support vt100 (e.g. Windows 7 + git-bash) |
| 89 | 89 | // testing for stty in a Windows 10 vt100-enabled console will implicitly disable vt100 support on STDOUT |
| 90 | 90 | self::initDimensionsUsingStty(); |
| 91 | 91 | } elseif (null !== $dimensions = self::getConsoleMode()) { |
| 92 | 92 | // extract [w, h] from "wxh" |
| 93 | - self::$width = (int) $dimensions[0]; |
|
| 94 | - self::$height = (int) $dimensions[1]; |
|
| 93 | + self::$width = (int)$dimensions[0]; |
|
| 94 | + self::$height = (int)$dimensions[1]; |
|
| 95 | 95 | } |
| 96 | 96 | } else { |
| 97 | 97 | self::initDimensionsUsingStty(); |
@@ -114,12 +114,12 @@ discard block |
||
| 114 | 114 | if ($sttyString = self::getSttyColumns()) { |
| 115 | 115 | if (preg_match('/rows.(\d+);.columns.(\d+);/i', $sttyString, $matches)) { |
| 116 | 116 | // extract [w, h] from "rows h; columns w;" |
| 117 | - self::$width = (int) $matches[2]; |
|
| 118 | - self::$height = (int) $matches[1]; |
|
| 117 | + self::$width = (int)$matches[2]; |
|
| 118 | + self::$height = (int)$matches[1]; |
|
| 119 | 119 | } elseif (preg_match('/;.(\d+).rows;.(\d+).columns/i', $sttyString, $matches)) { |
| 120 | 120 | // extract [w, h] from "; h rows; w columns" |
| 121 | - self::$width = (int) $matches[2]; |
|
| 122 | - self::$height = (int) $matches[1]; |
|
| 121 | + self::$width = (int)$matches[2]; |
|
| 122 | + self::$height = (int)$matches[1]; |
|
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | } |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | return null; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - return [(int) $matches[2], (int) $matches[1]]; |
|
| 140 | + return [(int)$matches[2], (int)$matches[1]]; |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -68,7 +68,7 @@ |
||
| 68 | 68 | $definition = $this->definition; |
| 69 | 69 | $givenArguments = $this->arguments; |
| 70 | 70 | |
| 71 | - $missingArguments = array_filter(array_keys($definition->getArguments()), function ($argument) use ($definition, $givenArguments) { |
|
| 71 | + $missingArguments = array_filter(array_keys($definition->getArguments()), function($argument) use ($definition, $givenArguments) { |
|
| 72 | 72 | return !\array_key_exists($argument, $givenArguments) && $definition->getArgument($argument)->isRequired(); |
| 73 | 73 | }); |
| 74 | 74 | |
@@ -49,11 +49,11 @@ |
||
| 49 | 49 | $cursor = 0; |
| 50 | 50 | while ($cursor < $length) { |
| 51 | 51 | if (preg_match('/\s+/A', $input, $match, 0, $cursor)) { |
| 52 | - } elseif (preg_match('/([^="\'\s]+?)(=?)('.self::REGEX_QUOTED_STRING.'+)/A', $input, $match, 0, $cursor)) { |
|
| 53 | - $tokens[] = $match[1].$match[2].stripcslashes(str_replace(['"\'', '\'"', '\'\'', '""'], '', substr($match[3], 1, \strlen($match[3]) - 2))); |
|
| 54 | - } elseif (preg_match('/'.self::REGEX_QUOTED_STRING.'/A', $input, $match, 0, $cursor)) { |
|
| 52 | + } elseif (preg_match('/([^="\'\s]+?)(=?)(' . self::REGEX_QUOTED_STRING . '+)/A', $input, $match, 0, $cursor)) { |
|
| 53 | + $tokens[] = $match[1] . $match[2] . stripcslashes(str_replace(['"\'', '\'"', '\'\'', '""'], '', substr($match[3], 1, \strlen($match[3]) - 2))); |
|
| 54 | + } elseif (preg_match('/' . self::REGEX_QUOTED_STRING . '/A', $input, $match, 0, $cursor)) { |
|
| 55 | 55 | $tokens[] = stripcslashes(substr($match[0], 1, \strlen($match[0]) - 2)); |
| 56 | - } elseif (preg_match('/'.self::REGEX_STRING.'/A', $input, $match, 0, $cursor)) { |
|
| 56 | + } elseif (preg_match('/' . self::REGEX_STRING . '/A', $input, $match, 0, $cursor)) { |
|
| 57 | 57 | $tokens[] = stripcslashes($match[1]); |
| 58 | 58 | } else { |
| 59 | 59 | // should never happen |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | if ($option->isNegatable()) { |
| 256 | - $negatedName = 'no-'.$option->getName(); |
|
| 256 | + $negatedName = 'no-' . $option->getName(); |
|
| 257 | 257 | if (isset($this->options[$negatedName])) { |
| 258 | 258 | throw new LogicException(sprintf('An option named "%s" already exists.', $negatedName)); |
| 259 | 259 | } |
@@ -410,19 +410,19 @@ discard block |
||
| 410 | 410 | |
| 411 | 411 | $tail = ''; |
| 412 | 412 | foreach ($this->getArguments() as $argument) { |
| 413 | - $element = '<'.$argument->getName().'>'; |
|
| 413 | + $element = '<' . $argument->getName() . '>'; |
|
| 414 | 414 | if ($argument->isArray()) { |
| 415 | 415 | $element .= '...'; |
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | if (!$argument->isRequired()) { |
| 419 | - $element = '['.$element; |
|
| 419 | + $element = '[' . $element; |
|
| 420 | 420 | $tail .= ']'; |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | $elements[] = $element; |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | - return implode(' ', $elements).$tail; |
|
| 426 | + return implode(' ', $elements) . $tail; |
|
| 427 | 427 | } |
| 428 | 428 | } |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | */ |
| 297 | 297 | public function hasParameterOption($values, bool $onlyParams = false) |
| 298 | 298 | { |
| 299 | - $values = (array) $values; |
|
| 299 | + $values = (array)$values; |
|
| 300 | 300 | |
| 301 | 301 | foreach ($this->tokens as $token) { |
| 302 | 302 | if ($onlyParams && '--' === $token) { |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | // Options with values: |
| 307 | 307 | // For long options, test for '--option=' at beginning |
| 308 | 308 | // For short options, test for '-o' at beginning |
| 309 | - $leading = 0 === strpos($value, '--') ? $value.'=' : $value; |
|
| 309 | + $leading = 0 === strpos($value, '--') ? $value . '=' : $value; |
|
| 310 | 310 | if ($token === $value || '' !== $leading && 0 === strpos($token, $leading)) { |
| 311 | 311 | return true; |
| 312 | 312 | } |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | */ |
| 322 | 322 | public function getParameterOption($values, $default = false, bool $onlyParams = false) |
| 323 | 323 | { |
| 324 | - $values = (array) $values; |
|
| 324 | + $values = (array)$values; |
|
| 325 | 325 | $tokens = $this->tokens; |
| 326 | 326 | |
| 327 | 327 | while (0 < \count($tokens)) { |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | // Options with values: |
| 338 | 338 | // For long options, test for '--option=' at beginning |
| 339 | 339 | // For short options, test for '-o' at beginning |
| 340 | - $leading = 0 === strpos($value, '--') ? $value.'=' : $value; |
|
| 340 | + $leading = 0 === strpos($value, '--') ? $value . '=' : $value; |
|
| 341 | 341 | if ('' !== $leading && 0 === strpos($token, $leading)) { |
| 342 | 342 | return substr($token, \strlen($leading)); |
| 343 | 343 | } |
@@ -354,9 +354,9 @@ discard block |
||
| 354 | 354 | */ |
| 355 | 355 | public function __toString() |
| 356 | 356 | { |
| 357 | - $tokens = array_map(function ($token) { |
|
| 357 | + $tokens = array_map(function($token) { |
|
| 358 | 358 | if (preg_match('{^(-[^=]+=)(.+)}', $token, $match)) { |
| 359 | - return $match[1].$this->escapeToken($match[2]); |
|
| 359 | + return $match[1] . $this->escapeToken($match[2]); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | if ($token && '-' !== $token[0]) { |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | public function hasParameterOption($values, bool $onlyParams = false) |
| 57 | 57 | { |
| 58 | - $values = (array) $values; |
|
| 58 | + $values = (array)$values; |
|
| 59 | 59 | |
| 60 | 60 | foreach ($this->parameters as $k => $v) { |
| 61 | 61 | if (!\is_int($k)) { |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | public function getParameterOption($values, $default = false, bool $onlyParams = false) |
| 81 | 81 | { |
| 82 | - $values = (array) $values; |
|
| 82 | + $values = (array)$values; |
|
| 83 | 83 | |
| 84 | 84 | foreach ($this->parameters as $k => $v) { |
| 85 | 85 | if ($onlyParams && ('--' === $k || (\is_int($k) && '--' === $v))) { |
@@ -111,10 +111,10 @@ discard block |
||
| 111 | 111 | $glue = ('-' === $param[1]) ? '=' : ' '; |
| 112 | 112 | if (\is_array($val)) { |
| 113 | 113 | foreach ($val as $v) { |
| 114 | - $params[] = $param.('' != $v ? $glue.$this->escapeToken($v) : ''); |
|
| 114 | + $params[] = $param . ('' != $v ? $glue . $this->escapeToken($v) : ''); |
|
| 115 | 115 | } |
| 116 | 116 | } else { |
| 117 | - $params[] = $param.('' != $val ? $glue.$this->escapeToken($val) : ''); |
|
| 117 | + $params[] = $param . ('' != $val ? $glue . $this->escapeToken($val) : ''); |
|
| 118 | 118 | } |
| 119 | 119 | } else { |
| 120 | 120 | $params[] = \is_array($val) ? implode(' ', array_map([$this, 'escapeToken'], $val)) : $this->escapeToken($val); |