Code Duplication    Length = 24-25 lines in 2 locations

src/CompletionHandler.php 2 locations

@@ 190-214 (lines=25) @@
187
     *
188
     * @return array|false
189
     */
190
    protected function completeForOptionShortcutValues()
191
    {
192
        $wordIndex = $this->context->getWordIndex();
193
194
        if ($this->command && $wordIndex > 1) {
195
            $left = $this->context->getWordAtIndex($wordIndex - 1);
196
197
            // Complete short options
198
            if ($left[0] == '-' && strlen($left) == 2) {
199
                $shortcut = substr($left, 1);
200
                $def = $this->command->getNativeDefinition();
201
202
                if (!$def->hasShortcut($shortcut)) {
203
                    return false;
204
                }
205
206
                $opt = $def->getOptionForShortcut($shortcut);
207
                if ($opt->isValueRequired() || $opt->isValueOptional()) {
208
                    return $this->completeOption($opt);
209
                }
210
            }
211
        }
212
213
        return false;
214
    }
215
216
    /**
217
     * Attemp to complete the current word as the value of a long-form option
@@ 221-244 (lines=24) @@
218
     *
219
     * @return array|false
220
     */
221
    protected function completeForOptionValues()
222
    {
223
        $wordIndex = $this->context->getWordIndex();
224
225
        if ($this->command && $wordIndex > 1) {
226
            $left = $this->context->getWordAtIndex($wordIndex - 1);
227
228
            if (strpos($left, '--') === 0) {
229
                $name = substr($left, 2);
230
                $def = $this->command->getNativeDefinition();
231
232
                if (!$def->hasOption($name)) {
233
                    return false;
234
                }
235
236
                $opt = $def->getOption($name);
237
                if ($opt->isValueRequired() || $opt->isValueOptional()) {
238
                    return $this->completeOption($opt);
239
                }
240
            }
241
        }
242
243
        return false;
244
    }
245
246
    /**
247
     * Attempt to complete the current word as a command name