{
$name = substr($token, 1);
- if (strlen($name) > 1) {
+ if (\strlen($name) > 1) {
if ($this->definition->hasShortcut($name[0]) && $this->definition->getOptionForShortcut($name[0])->acceptValue()) {
// an option with a value (with no space)
$this->addShortOption($name[0], substr($name, 1));
*/
private function parseShortOptionSet($name)
{
- $len = strlen($name);
+ $len = \strlen($name);
for ($i = 0; $i < $len; ++$i) {
if (!$this->definition->hasShortcut($name[$i])) {
- throw new RuntimeException(sprintf('The "-%s" option does not exist.', $name[$i]));
+ $encoding = mb_detect_encoding($name, null, true);
+ throw new RuntimeException(sprintf('The "-%s" option does not exist.', false === $encoding ? $name[$i] : mb_substr($name, $i, 1, $encoding)));
}
$option = $this->definition->getOptionForShortcut($name[$i]);
$name = substr($token, 2);
if (false !== $pos = strpos($name, '=')) {
- if (0 === strlen($value = substr($name, $pos + 1))) {
+ if (0 === \strlen($value = substr($name, $pos + 1))) {
// if no value after "=" then substr() returns "" since php7 only, false before
// see http://php.net/manual/fr/migration70.incompatible.php#119151
if (\PHP_VERSION_ID < 70000 && false === $value) {
*/
private function parseArgument($token)
{
- $c = count($this->arguments);
+ $c = \count($this->arguments);
// if input is expecting another argument, add it
if ($this->definition->hasArgument($c)) {
// unexpected argument
} else {
$all = $this->definition->getArguments();
- if (count($all)) {
+ if (\count($all)) {
throw new RuntimeException(sprintf('Too many arguments, expected arguments "%s".', implode('" "', array_keys($all))));
}
throw new RuntimeException(sprintf('The "--%s" option does not accept a value.', $name));
}
- if (in_array($value, array('', null), true) && $option->acceptValue() && count($this->parsed)) {
+ if (\in_array($value, array('', null), true) && $option->acceptValue() && \count($this->parsed)) {
// if option accepts an optional or mandatory argument
// let's see if there is one provided
$next = array_shift($this->parsed);
- if ((isset($next[0]) && '-' !== $next[0]) || in_array($next, array('', null), true)) {
+ if ((isset($next[0]) && '-' !== $next[0]) || \in_array($next, array('', null), true)) {
$value = $next;
} else {
array_unshift($this->parsed, $next);
$values = (array) $values;
$tokens = $this->tokens;
- while (0 < count($tokens)) {
+ while (0 < \count($tokens)) {
$token = array_shift($tokens);
if ($onlyParams && '--' === $token) {
- return false;
+ return $default;
}
foreach ($values as $value) {
// For short options, test for '-o' at beginning
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
if ('' !== $leading && 0 === strpos($token, $leading)) {
- return substr($token, strlen($leading));
+ return substr($token, \strlen($leading));
}
}
}