Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
FIX: Optional Arguments invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
Maximilian Schmidt committed Nov 8, 2018
1 parent 32c6580 commit 7698ef3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Classes/Command/AbstractCommand.php
Expand Up @@ -8,6 +8,7 @@
use MCStreetguy\SmartConsole\Utility\Args;
use Webmozart\Console\Api\Command\Command;
use MCStreetguy\SmartConsole\Utility\IO;
use MCStreetguy\SmartConsole\Annotations\Command\OptionalArgument;

/**
* The base class for command handlers.
Expand Down Expand Up @@ -81,7 +82,11 @@ final public function invoke(ArgsApi $args, IOApi $io, Command $cmd, string $nam
foreach ($params as $parameter) {
$param = $parameter->getName();

if ($parameter->isOptional()) {
$optionalArgumentMap = array_filter((new AnnotationReader)->getMethodAnnotations($reflector), function ($elem) use ($param) {
return ($elem instanceof OptionalArgument) && ($elem->getArgument() === $param);
});

if ($parameter->isOptional() && empty($optionalArgumentMap)) {
$optionName = preg_replace_callback('/(?<=.)([A-Z])/', function ($matches) {
return '-' . strtolower($matches[1]);
}, $param);
Expand All @@ -96,7 +101,7 @@ final public function invoke(ArgsApi $args, IOApi $io, Command $cmd, string $nam

if (is_int($result)) {
if ($result > 255) {
$result = 255;
$result = $result % 255;
}

return $result;
Expand Down

0 comments on commit 7698ef3

Please sign in to comment.