Conditions | 2 |
Paths | 2 |
Total Lines | 80 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
34 | protected function execute(InputInterface $input, OutputInterface $output) |
||
35 | { |
||
36 | if ($input->getOption('install')) { |
||
37 | $output->write(<<<'BASH' |
||
38 | #!/bin/bash |
||
39 | |||
40 | _deployer() |
||
41 | { |
||
42 | local cur script com opts |
||
43 | COMPREPLY=() |
||
44 | _get_comp_words_by_ref -n : cur words |
||
45 | |||
46 | # for an alias, get the real script behind it |
||
47 | if [[ $(type -t ${words[0]}) == "alias" ]]; then |
||
48 | script=$(alias ${words[0]} | sed -E "s/alias ${words[0]}='(.*)'/\1/") |
||
49 | else |
||
50 | script=${words[0]} |
||
51 | fi |
||
52 | |||
53 | # lookup for command |
||
54 | for word in ${words[@]:1}; do |
||
55 | if [[ $word != -* ]]; then |
||
56 | com=$word |
||
57 | break |
||
58 | fi |
||
59 | done |
||
60 | |||
61 | # completing for an option |
||
62 | if [[ ${cur} == --* ]] ; then |
||
63 | opts=$script |
||
64 | [[ -n $com ]] && opts=$opts" -h "$com |
||
65 | opts=$($opts --no-ansi 2>/dev/null | sed -n '/Options/,/^$/p' | sed -e '1d;$d' | sed 's/[^--]*\(--.*\)/\1/' | sed -En 's/[^ ]*(-(-[[:alnum:]]+){1,}).*/\1/p' | awk '{$1=$1};1'; exit ${PIPESTATUS[0]}); |
||
66 | [[ $? -eq 0 ]] || return 0; |
||
67 | COMPREPLY=($(compgen -W "${opts}" -- ${cur})) |
||
68 | __ltrim_colon_completions "$cur" |
||
69 | |||
70 | return 0 |
||
71 | fi |
||
72 | |||
73 | # completing for a command |
||
74 | if [[ $cur == $com ]]; then |
||
75 | coms=$($script list --raw 2>/dev/null | awk '{print $1}'; exit ${PIPESTATUS[0]}) |
||
76 | [[ $? -eq 0 ]] || return 0; |
||
77 | COMPREPLY=($(compgen -W "${coms}" -- ${cur})) |
||
78 | __ltrim_colon_completions "$cur" |
||
79 | |||
80 | return 0; |
||
81 | fi |
||
82 | } |
||
83 | |||
84 | complete -o default -F _deployer dep |
||
85 | |||
86 | BASH |
||
87 | ); |
||
88 | } else { |
||
89 | $output->write(<<<'HELP' |
||
90 | To install Deployer autocomplete run one of the following commands: |
||
91 | |||
92 | <comment># Bash (Ubuntu/Debian)</comment> |
||
93 | |||
94 | dep autocomplete --install | sudo tee /etc/bash_completion.d/deployer |
||
95 | |||
96 | <comment># Bash (Mac OSX with Homebrew "bash-completion")</comment> |
||
97 | |||
98 | dep autocomplete --install > $(brew --prefix)/etc/bash_completion.d/deployer |
||
99 | |||
100 | <comment># Zsh</comment> |
||
101 | |||
102 | dep autocomplete --install > ~/.deployer_completion && echo "source ~/.deployer_completion" >> ~/.zshrc |
||
103 | |||
104 | <comment># Fish</comment> |
||
105 | |||
106 | dep autocomplete --install > ~/.config/fish/completions/deployer.fish |
||
107 | |||
108 | Autocomplete will be working after restarting terminal or you can run "source ~/.bash_profile", etc. |
||
109 | |||
110 | HELP |
||
111 | ); |
||
112 | } |
||
113 | } |
||
114 | } |
||
115 |