Conditions | 14 |
Paths | 8 |
Total Lines | 53 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 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 |
||
97 | protected function buildOptions(Package $package, InputInterface $input, OutputInterface $output) |
||
98 | { |
||
99 | $helper = $this->getHelperSet()->get('question'); |
||
100 | |||
101 | $configureOptions = $input->getOption('with-configure-options'); |
||
102 | |||
103 | if ($configureOptions) { |
||
104 | if (!file_exists($configureOptions) || is_dir($configureOptions) || !is_readable($configureOptions)) { |
||
105 | throw new Exception("File '{$configureOptions}' is unusable"); |
||
106 | } |
||
107 | |||
108 | if (DIRECTORY_SEPARATOR !== '\\' && preg_match('_^/dev/fd/\d+$_', $configureOptions)) { |
||
109 | // https://bugs.php.net/bug.php?id=53465 |
||
110 | $configureOptions = str_replace('/dev/', 'php://', $configureOptions); |
||
111 | } |
||
112 | $configureOptions = preg_replace(',\\s+,', ' ', file_get_contents($configureOptions)); |
||
113 | |||
114 | return [null, $configureOptions]; |
||
115 | } |
||
116 | |||
117 | $options = $package->getConfigureOptions(); |
||
118 | $optionsValue = []; |
||
119 | |||
120 | foreach ($options as $name => $opt) { |
||
121 | /* enable/with-<extname> */ |
||
122 | if ($name == $package->getName() || str_replace('-', '_', $name) == $package->getName()) { |
||
123 | $optionsValue[$name] = (object) [ |
||
124 | 'type' => $opt->type, |
||
125 | 'input' => true, |
||
126 | ]; |
||
127 | |||
128 | continue; |
||
129 | } |
||
130 | |||
131 | if ($input->getOption('defaults')) { |
||
132 | $value = $opt->default; |
||
133 | } else { |
||
134 | if ($opt->type == 'enable') { |
||
135 | $prompt = new ConfirmationQuestion($opt->prompt . ' (default: ' . ($opt->default ? 'yes' : 'no') . '): ', $opt->default); |
||
136 | } else { |
||
137 | $prompt = new Question($opt->prompt . ' (default: ' . ($opt->default ?: '') . '): ', $opt->default); |
||
138 | } |
||
139 | |||
140 | $value = $helper->ask($input, $output, $prompt); |
||
|
|||
141 | } |
||
142 | |||
143 | $optionsValue[$name] = (object) [ |
||
144 | 'type' => $opt->type, |
||
145 | 'input' => $value, |
||
146 | ]; |
||
147 | } |
||
148 | |||
149 | return [$optionsValue, null]; |
||
150 | } |
||
154 |