comparison vendor/psy/psysh/src/Command/Command.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
children
comparison
equal deleted inserted replaced
3:307d7a7fd348 4:a9cd425dd02b
63 $messages[] = $this->optionsAsText(); 63 $messages[] = $this->optionsAsText();
64 } 64 }
65 65
66 if ($help = $this->getProcessedHelp()) { 66 if ($help = $this->getProcessedHelp()) {
67 $messages[] = '<comment>Help:</comment>'; 67 $messages[] = '<comment>Help:</comment>';
68 $messages[] = ' ' . str_replace("\n", "\n ", $help) . "\n"; 68 $messages[] = ' ' . \str_replace("\n", "\n ", $help) . "\n";
69 } 69 }
70 70
71 return implode("\n", $messages); 71 return \implode("\n", $messages);
72 } 72 }
73 73
74 /** 74 /**
75 * {@inheritdoc} 75 * {@inheritdoc}
76 */ 76 */
77 private function getArguments() 77 private function getArguments()
78 { 78 {
79 $hidden = $this->getHiddenArguments(); 79 $hidden = $this->getHiddenArguments();
80 80
81 return array_filter($this->getNativeDefinition()->getArguments(), function ($argument) use ($hidden) { 81 return \array_filter($this->getNativeDefinition()->getArguments(), function ($argument) use ($hidden) {
82 return !in_array($argument->getName(), $hidden); 82 return !\in_array($argument->getName(), $hidden);
83 }); 83 });
84 } 84 }
85 85
86 /** 86 /**
87 * These arguments will be excluded from help output. 87 * These arguments will be excluded from help output.
98 */ 98 */
99 private function getOptions() 99 private function getOptions()
100 { 100 {
101 $hidden = $this->getHiddenOptions(); 101 $hidden = $this->getHiddenOptions();
102 102
103 return array_filter($this->getNativeDefinition()->getOptions(), function ($option) use ($hidden) { 103 return \array_filter($this->getNativeDefinition()->getOptions(), function ($option) use ($hidden) {
104 return !in_array($option->getName(), $hidden); 104 return !\in_array($option->getName(), $hidden);
105 }); 105 });
106 } 106 }
107 107
108 /** 108 /**
109 * These options will be excluded from help output. 109 * These options will be excluded from help output.
120 * 120 *
121 * @return string 121 * @return string
122 */ 122 */
123 private function aliasesAsText() 123 private function aliasesAsText()
124 { 124 {
125 return '<comment>Aliases:</comment> <info>' . implode(', ', $this->getAliases()) . '</info>' . PHP_EOL; 125 return '<comment>Aliases:</comment> <info>' . \implode(', ', $this->getAliases()) . '</info>' . PHP_EOL;
126 } 126 }
127 127
128 /** 128 /**
129 * Format command arguments as text. 129 * Format command arguments as text.
130 * 130 *
137 137
138 $arguments = $this->getArguments(); 138 $arguments = $this->getArguments();
139 if (!empty($arguments)) { 139 if (!empty($arguments)) {
140 $messages[] = '<comment>Arguments:</comment>'; 140 $messages[] = '<comment>Arguments:</comment>';
141 foreach ($arguments as $argument) { 141 foreach ($arguments as $argument) {
142 if (null !== $argument->getDefault() && (!is_array($argument->getDefault()) || count($argument->getDefault()))) { 142 if (null !== $argument->getDefault() && (!\is_array($argument->getDefault()) || \count($argument->getDefault()))) {
143 $default = sprintf('<comment> (default: %s)</comment>', $this->formatDefaultValue($argument->getDefault())); 143 $default = \sprintf('<comment> (default: %s)</comment>', $this->formatDefaultValue($argument->getDefault()));
144 } else { 144 } else {
145 $default = ''; 145 $default = '';
146 } 146 }
147 147
148 $description = str_replace("\n", "\n" . str_pad('', $max + 2, ' '), $argument->getDescription()); 148 $description = \str_replace("\n", "\n" . \str_pad('', $max + 2, ' '), $argument->getDescription());
149 149
150 $messages[] = sprintf(" <info>%-${max}s</info> %s%s", $argument->getName(), $description, $default); 150 $messages[] = \sprintf(" <info>%-${max}s</info> %s%s", $argument->getName(), $description, $default);
151 } 151 }
152 152
153 $messages[] = ''; 153 $messages[] = '';
154 } 154 }
155 155
156 return implode(PHP_EOL, $messages); 156 return \implode(PHP_EOL, $messages);
157 } 157 }
158 158
159 /** 159 /**
160 * Format options as text. 160 * Format options as text.
161 * 161 *
169 $options = $this->getOptions(); 169 $options = $this->getOptions();
170 if ($options) { 170 if ($options) {
171 $messages[] = '<comment>Options:</comment>'; 171 $messages[] = '<comment>Options:</comment>';
172 172
173 foreach ($options as $option) { 173 foreach ($options as $option) {
174 if ($option->acceptValue() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) { 174 if ($option->acceptValue() && null !== $option->getDefault() && (!\is_array($option->getDefault()) || \count($option->getDefault()))) {
175 $default = sprintf('<comment> (default: %s)</comment>', $this->formatDefaultValue($option->getDefault())); 175 $default = \sprintf('<comment> (default: %s)</comment>', $this->formatDefaultValue($option->getDefault()));
176 } else { 176 } else {
177 $default = ''; 177 $default = '';
178 } 178 }
179 179
180 $multiple = $option->isArray() ? '<comment> (multiple values allowed)</comment>' : ''; 180 $multiple = $option->isArray() ? '<comment> (multiple values allowed)</comment>' : '';
181 $description = str_replace("\n", "\n" . str_pad('', $max + 2, ' '), $option->getDescription()); 181 $description = \str_replace("\n", "\n" . \str_pad('', $max + 2, ' '), $option->getDescription());
182 182
183 $optionMax = $max - strlen($option->getName()) - 2; 183 $optionMax = $max - \strlen($option->getName()) - 2;
184 $messages[] = sprintf( 184 $messages[] = \sprintf(
185 " <info>%s</info> %-${optionMax}s%s%s%s", 185 " <info>%s</info> %-${optionMax}s%s%s%s",
186 '--' . $option->getName(), 186 '--' . $option->getName(),
187 $option->getShortcut() ? sprintf('(-%s) ', $option->getShortcut()) : '', 187 $option->getShortcut() ? \sprintf('(-%s) ', $option->getShortcut()) : '',
188 $description, 188 $description,
189 $default, 189 $default,
190 $multiple 190 $multiple
191 ); 191 );
192 } 192 }
193 193
194 $messages[] = ''; 194 $messages[] = '';
195 } 195 }
196 196
197 return implode(PHP_EOL, $messages); 197 return \implode(PHP_EOL, $messages);
198 } 198 }
199 199
200 /** 200 /**
201 * Calculate the maximum padding width for a set of lines. 201 * Calculate the maximum padding width for a set of lines.
202 * 202 *
205 private function getMaxWidth() 205 private function getMaxWidth()
206 { 206 {
207 $max = 0; 207 $max = 0;
208 208
209 foreach ($this->getOptions() as $option) { 209 foreach ($this->getOptions() as $option) {
210 $nameLength = strlen($option->getName()) + 2; 210 $nameLength = \strlen($option->getName()) + 2;
211 if ($option->getShortcut()) { 211 if ($option->getShortcut()) {
212 $nameLength += strlen($option->getShortcut()) + 3; 212 $nameLength += \strlen($option->getShortcut()) + 3;
213 } 213 }
214 214
215 $max = max($max, $nameLength); 215 $max = \max($max, $nameLength);
216 } 216 }
217 217
218 foreach ($this->getArguments() as $argument) { 218 foreach ($this->getArguments() as $argument) {
219 $max = max($max, strlen($argument->getName())); 219 $max = \max($max, \strlen($argument->getName()));
220 } 220 }
221 221
222 return ++$max; 222 return ++$max;
223 } 223 }
224 224
229 * 229 *
230 * @return string 230 * @return string
231 */ 231 */
232 private function formatDefaultValue($default) 232 private function formatDefaultValue($default)
233 { 233 {
234 if (is_array($default) && $default === array_values($default)) { 234 if (\is_array($default) && $default === \array_values($default)) {
235 return sprintf("array('%s')", implode("', '", $default)); 235 return \sprintf("array('%s')", \implode("', '", $default));
236 } 236 }
237 237
238 return str_replace("\n", '', var_export($default, true)); 238 return \str_replace("\n", '', \var_export($default, true));
239 } 239 }
240 240
241 /** 241 /**
242 * Get a Table instance. 242 * Get a Table instance.
243 * 243 *
245 * 245 *
246 * @return Table|TableHelper 246 * @return Table|TableHelper
247 */ 247 */
248 protected function getTable(OutputInterface $output) 248 protected function getTable(OutputInterface $output)
249 { 249 {
250 if (!class_exists('Symfony\Component\Console\Helper\Table')) { 250 if (!\class_exists('Symfony\Component\Console\Helper\Table')) {
251 return $this->getTableHelper(); 251 return $this->getTableHelper();
252 } 252 }
253 253
254 $style = new TableStyle(); 254 $style = new TableStyle();
255 $style 255 $style