Skip to content

Commit 6fc2900

Browse files
committed
Merge pull request #24 from aik099/normalize-return-types
Make all completion related method return empty array for no completions
2 parents bf67640 + 56b5ccd commit 6fc2900

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

src/Completion.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,15 @@ public function __construct($commandName, $targetName, $type, $completion)
4848

4949
/**
5050
* Return the result of the completion helper
51-
* @return array|mixed
51+
* @return array
5252
*/
5353
public function run()
5454
{
5555
if ($this->isCallable()) {
5656
return call_user_func($this->completion);
5757
}
58-
return (array) $this->completion;
58+
59+
return $this->completion;
5960
}
6061

6162
/**

src/Completion/CompletionInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function getTargetName();
4444
*
4545
* Returns an array of possible completions or null to indicate that no completions are available.
4646
*
47-
* @return array|null
47+
* @return array
4848
*/
4949
public function run();
5050
}

src/CompletionHandler.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ public function getContext()
5454
}
5555

5656
/**
57-
* @param array|Completion $array
57+
* @param Completion[] $array
5858
*/
59-
public function addHandlers($array)
59+
public function addHandlers(array $array)
6060
{
6161
$this->helpers = array_merge($this->helpers, $array);
6262
}
@@ -92,9 +92,11 @@ public function runCompletion()
9292
);
9393

9494
foreach ($process as $methodName) {
95-
if (is_array($result = $this->{$methodName}())) {
95+
$result = $this->{$methodName}();
96+
97+
if (false !== $result) {
9698
// Return the result of the first completion mode that matches
97-
return $this->filterResults($result);
99+
return $this->filterResults((array) $result);
98100
}
99101
}
100102

@@ -284,11 +286,13 @@ protected function getCompletionHelper($name, $type)
284286
}
285287
}
286288
}
289+
290+
return null;
287291
}
288292

289293
/**
290294
* @param InputOption $option
291-
* @return array|mixed
295+
* @return array|false
292296
*/
293297
protected function completeOption(InputOption $option)
294298
{
@@ -299,6 +303,8 @@ protected function completeOption(InputOption $option)
299303
if ($this->command instanceof CompletionAwareInterface) {
300304
return $this->command->completeOptionValues($option->getName(), $this->context);
301305
}
306+
307+
return false;
302308
}
303309

304310
/**
@@ -331,7 +337,6 @@ protected function mapArgumentsToWords($argumentDefinitions)
331337
}
332338

333339
foreach ($this->context->getWords() as $wordIndex => $word) {
334-
335340
// Skip program name, command name, options, and option values
336341
if ($wordIndex < 2
337342
|| ($word && '-' === $word[0])
@@ -369,6 +374,11 @@ protected function filterResults(array $array)
369374
});
370375
}
371376

377+
/**
378+
* Returns list of all options.
379+
*
380+
* @return InputOption[]
381+
*/
372382
protected function getAllOptions()
373383
{
374384
return array_merge(

0 commit comments

Comments
 (0)