From f99cea900fbdf33b2e07f9d6972729a82a74082b Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Fri, 27 Jul 2018 20:26:18 -0500 Subject: [PATCH] Apply fixes from StyleCI (#69) --- src/Screens/Completers/Completer.php | 29 ++++++++++---------- src/Screens/Completers/FilenameCompleter.php | 11 ++++---- src/Screens/FilterFileName.php | 4 +-- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/Screens/Completers/Completer.php b/src/Screens/Completers/Completer.php index 83d11ca..dc72324 100644 --- a/src/Screens/Completers/Completer.php +++ b/src/Screens/Completers/Completer.php @@ -40,7 +40,7 @@ public function __construct(Readline $readline) } /** - * Start completion + * Start completion. * * @param string $word * @param int $startOffset @@ -59,7 +59,7 @@ public function __invoke($word, $startOffset, $endOffset) } /** - * Search for things related to the completed word and return an array of suggestions + * Search for things related to the completed word and return an array of suggestions. * * Use an array with one element to autocomplete the word * @@ -68,7 +68,7 @@ public function __invoke($word, $startOffset, $endOffset) abstract protected function search(); /** - * Display suggestions or complete the word depending on number of results + * Display suggestions or complete the word depending on number of results. * * When returning an array reactphp-stdio will display suggestions with the default behavior. * @@ -78,7 +78,7 @@ abstract protected function search(); protected function handleSearchResults($searchResults) { if (empty($searchResults)) { - return null; + return; } if (count($searchResults) > 1) { @@ -89,7 +89,7 @@ protected function handleSearchResults($searchResults) } /** - * Filter suggestions to display + * Filter suggestions to display. * * @param array $suggestions * @return array|null @@ -99,11 +99,12 @@ protected function filterSuggestions($suggestions) if (is_callable($this->filterSuggestionsCallback)) { $suggestions = ($this->filterSuggestionsCallback)($suggestions); } + return $suggestions; } /** - * Register callback called when more than one suggestion is available + * Register callback called when more than one suggestion is available. * * You can use this callback to filter suggestions or to abort the * default display behavior by returning null @@ -116,7 +117,7 @@ public function onSuggestions($callback) } /** - * Refresh the input with the completed word and move cursor to end of the word + * Refresh the input with the completed word and move cursor to end of the word. * * @param string $newWord */ @@ -125,14 +126,14 @@ protected function completeWord($newWord) $endQuotedWord = $this->appendQuoteIfNeeded($newWord); $this->readline->setInput( - $this->getInputBeforeWord() . $endQuotedWord . $this->getInputAfterWord() + $this->getInputBeforeWord().$endQuotedWord.$this->getInputAfterWord() ); $this->readline->moveCursorTo($this->wordStartOffset + mb_strlen($endQuotedWord)); } /** - * Return input string before the word + * Return input string before the word. * * @return string */ @@ -142,7 +143,7 @@ protected function getInputBeforeWord() } /** - * Return input string after the word + * Return input string after the word. * * @return string */ @@ -152,7 +153,7 @@ protected function getInputAfterWord() } /** - * Return the character before the word + * Return the character before the word. * * @return null|string */ @@ -164,7 +165,7 @@ protected function getCharBeforeWord() } /** - * Append a quote if word is prefixed with a quote + * Append a quote if word is prefixed with a quote. * * @param string $word * @return string @@ -174,12 +175,12 @@ protected function appendQuoteIfNeeded($word) $char = $this->getCharBeforeWord(); return ($char === '"' || $char === '\'') - ? $word . $char + ? $word.$char : $word; } /** - * Return the input string + * Return the input string. * * @return string */ diff --git a/src/Screens/Completers/FilenameCompleter.php b/src/Screens/Completers/FilenameCompleter.php index 012c67b..d2d0630 100644 --- a/src/Screens/Completers/FilenameCompleter.php +++ b/src/Screens/Completers/FilenameCompleter.php @@ -5,16 +5,17 @@ class FilenameCompleter extends Completer { /** - * Search for files and directories corresponding to the word to complete + * Search for files and directories corresponding to the word to complete. * * @return array */ - protected function search() { - return glob($this->word . '*', GLOB_MARK) ?: []; + protected function search() + { + return glob($this->word.'*', GLOB_MARK) ?: []; } /** - * Append a quote if path is prefixed with a quote, except for directories + * Append a quote if path is prefixed with a quote, except for directories. * * @param string $path * @return string @@ -28,7 +29,7 @@ protected function appendQuoteIfNeeded($path) $char = $this->getCharBeforeWord(); return ($char === '"' || $char === '\'') - ? $path . $char + ? $path.$char : $path; } } diff --git a/src/Screens/FilterFileName.php b/src/Screens/FilterFileName.php index 09c932a..92db281 100644 --- a/src/Screens/FilterFileName.php +++ b/src/Screens/FilterFileName.php @@ -64,13 +64,13 @@ protected function registerAutocompleter() protected function refreshScreenWithSuggestions($suggestions, $limit) { - $firstSuggestions = array_slice($suggestions, 0 , $limit); + $firstSuggestions = array_slice($suggestions, 0, $limit); $this->terminal->refreshScreen(); $stdio = $this->terminal->getStdio(); - $stdio->write("\n" . implode("\n", $firstSuggestions) . "\n"); + $stdio->write("\n".implode("\n", $firstSuggestions)."\n"); $count = count($suggestions) - $limit; if ($count > 0) {