Code Duplication    Length = 24-25 lines in 2 locations

src/CompletionHandler.php 2 locations

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