@@ -260,7 +260,7 @@ |
||
| 260 | 260 | protected static function longestWordLength($str) |
| 261 | 261 | { |
| 262 | 262 | $words = preg_split('/[ -]/', $str); |
| 263 | - $lengths = array_map(function ($s) { |
|
| 263 | + $lengths = array_map(function($s) { |
|
| 264 | 264 | return strlen($s); |
| 265 | 265 | }, $words); |
| 266 | 266 | return max($lengths); |
@@ -123,6 +123,7 @@ |
||
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * Add our custom table style(s) to the table. |
| 126 | + * @param Table $table |
|
| 126 | 127 | */ |
| 127 | 128 | protected static function addCustomTableStyles($table) |
| 128 | 129 | { |
@@ -4,12 +4,10 @@ |
||
| 4 | 4 | use Symfony\Component\Console\Output\OutputInterface; |
| 5 | 5 | use Symfony\Component\Console\Helper\Table; |
| 6 | 6 | use Symfony\Component\Console\Helper\TableStyle; |
| 7 | - |
|
| 8 | 7 | use Consolidation\OutputFormatters\Validate\ValidDataTypesInterface; |
| 9 | 8 | use Consolidation\OutputFormatters\Options\FormatterOptions; |
| 10 | 9 | use Consolidation\OutputFormatters\Validate\ValidDataTypesTrait; |
| 11 | 10 | use Consolidation\OutputFormatters\StructuredData\TableDataInterface; |
| 12 | -use Consolidation\OutputFormatters\Transformations\ReorderFields; |
|
| 13 | 11 | use Consolidation\OutputFormatters\Exception\IncompatibleDataException; |
| 14 | 12 | use Consolidation\OutputFormatters\Transformations\WordWrapper; |
| 15 | 13 | |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | if (!empty($headers)) { |
| 90 | 90 | array_splice($headers, 1, 0, ':'); |
| 91 | 91 | } |
| 92 | - $data = array_map(function ($item) { |
|
| 92 | + $data = array_map(function($item) { |
|
| 93 | 93 | array_splice($item, 1, 0, ':'); |
| 94 | 94 | return $item; |
| 95 | 95 | }, $data); |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | $wrapper = new WordWrapper($options->get(FormatterOptions::TERMINAL_WIDTH)); |
| 117 | 117 | $wrapper->setPaddingFromStyle($tableStyle); |
| 118 | 118 | if (!empty($headers)) { |
| 119 | - $headerLengths = array_map(function ($item) { |
|
| 119 | + $headerLengths = array_map(function($item) { |
|
| 120 | 120 | return strlen($item); |
| 121 | 121 | }, $headers); |
| 122 | 122 | $wrapper->setMinimumWidths($headerLengths); |
@@ -34,6 +34,9 @@ discard block |
||
| 34 | 34 | $this->addXmlChildren($dom, $element, $elementName, $structuredData); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | + /** |
|
| 38 | + * @param \DOMElement $xmlParent |
|
| 39 | + */ |
|
| 37 | 40 | protected function addXmlChildren(\DOMDocument $dom, $xmlParent, $elementName, $structuredData) |
| 38 | 41 | { |
| 39 | 42 | foreach ($structuredData as $key => $value) { |
@@ -52,6 +55,9 @@ discard block |
||
| 52 | 55 | $this->addXmlData($dom, $xmlParent, $elementName, $value); |
| 53 | 56 | } |
| 54 | 57 | |
| 58 | + /** |
|
| 59 | + * @param string $childElementName |
|
| 60 | + */ |
|
| 55 | 61 | protected function determineElementName($key, $childElementName, $value) |
| 56 | 62 | { |
| 57 | 63 | if (is_numeric($key)) { |
@@ -58,7 +58,7 @@ |
||
| 58 | 58 | return $childElementName; |
| 59 | 59 | } |
| 60 | 60 | if (is_object($value)) { |
| 61 | - $value = (array)$value; |
|
| 61 | + $value = (array) $value; |
|
| 62 | 62 | } |
| 63 | 63 | if (!is_array($value)) { |
| 64 | 64 | return $key; |
@@ -111,13 +111,13 @@ discard block |
||
| 111 | 111 | |
| 112 | 112 | if (count($validFormats) > 1) { |
| 113 | 113 | // Make an input option for --format |
| 114 | - $description = 'Format the result data. Available formats: ' . implode(',', $validFormats); |
|
| 114 | + $description = 'Format the result data. Available formats: '.implode(',', $validFormats); |
|
| 115 | 115 | $automaticOptions[FormatterOptions::FORMAT] = new InputOption(FormatterOptions::FORMAT, '', InputOption::VALUE_OPTIONAL, $description, $defaultFormat); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | if ($availableFields) { |
| 119 | 119 | $defaultFields = $options->get(FormatterOptions::DEFAULT_FIELDS, [], ''); |
| 120 | - $description = 'Available fields: ' . implode(', ', $this->availableFieldsList($availableFields)); |
|
| 120 | + $description = 'Available fields: '.implode(', ', $this->availableFieldsList($availableFields)); |
|
| 121 | 121 | $automaticOptions[FormatterOptions::FIELDS] = new InputOption(FormatterOptions::FIELDS, '', InputOption::VALUE_OPTIONAL, $description, $defaultFields); |
| 122 | 122 | $automaticOptions[FormatterOptions::FIELD] = new InputOption(FormatterOptions::FIELD, '', InputOption::VALUE_OPTIONAL, "Select just one field, and force format to 'string'.", ''); |
| 123 | 123 | } |
@@ -132,8 +132,8 @@ discard block |
||
| 132 | 132 | protected function availableFieldsList($availableFields) |
| 133 | 133 | { |
| 134 | 134 | return array_map( |
| 135 | - function ($key) use ($availableFields) { |
|
| 136 | - return $availableFields[$key] . " ($key)"; |
|
| 135 | + function($key) use ($availableFields) { |
|
| 136 | + return $availableFields[$key]." ($key)"; |
|
| 137 | 137 | }, |
| 138 | 138 | array_keys($availableFields) |
| 139 | 139 | ); |
@@ -197,10 +197,10 @@ discard block |
||
| 197 | 197 | */ |
| 198 | 198 | public function write(OutputInterface $output, $format, $structuredOutput, FormatterOptions $options) |
| 199 | 199 | { |
| 200 | - $formatter = $this->getFormatter((string)$format); |
|
| 200 | + $formatter = $this->getFormatter((string) $format); |
|
| 201 | 201 | if (!is_string($structuredOutput) && !$this->isValidFormat($formatter, $structuredOutput)) { |
| 202 | 202 | $validFormats = $this->validFormats($structuredOutput); |
| 203 | - throw new InvalidFormatException((string)$format, $structuredOutput, $validFormats); |
|
| 203 | + throw new InvalidFormatException((string) $format, $structuredOutput, $validFormats); |
|
| 204 | 204 | } |
| 205 | 205 | // Give the formatter a chance to override the options |
| 206 | 206 | $options = $this->overrideOptions($formatter, $structuredOutput, $options); |
@@ -2,8 +2,6 @@ |
||
| 2 | 2 | namespace Consolidation\OutputFormatters\Formatters; |
| 3 | 3 | |
| 4 | 4 | use Consolidation\OutputFormatters\Options\FormatterOptions; |
| 5 | -use Consolidation\OutputFormatters\Validate\ValidDataTypesInterface; |
|
| 6 | -use Consolidation\OutputFormatters\Validate\ValidDataTypesTrait; |
|
| 7 | 5 | use Symfony\Component\Console\Output\OutputInterface; |
| 8 | 6 | use Symfony\Component\Console\Helper\Table; |
| 9 | 7 | use Symfony\Component\Console\Helper\TableCell; |
@@ -14,11 +14,11 @@ discard block |
||
| 14 | 14 | class HelpFormatter implements FormatterInterface |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @inheritdoc |
|
| 19 | - */ |
|
| 20 | - public function write(OutputInterface $output, $data, FormatterOptions $options) |
|
| 21 | - { |
|
| 17 | + /** |
|
| 18 | + * @inheritdoc |
|
| 19 | + */ |
|
| 20 | + public function write(OutputInterface $output, $data, FormatterOptions $options) |
|
| 21 | + { |
|
| 22 | 22 | $table = new Table($this->output()); |
| 23 | 23 | $table->setStyle('compact'); |
| 24 | 24 | |
@@ -26,51 +26,51 @@ discard block |
||
| 26 | 26 | $output->writeln($command->getDescription()); |
| 27 | 27 | |
| 28 | 28 | if ($usages = $command->getExampleUsages()) { |
| 29 | - $table->addRow(['','']); |
|
| 30 | - $table->addRow([new TableCell('Examples:', array('colspan' => 2))]); |
|
| 31 | - foreach ($usages as $key => $description) { |
|
| 29 | + $table->addRow(['','']); |
|
| 30 | + $table->addRow([new TableCell('Examples:', array('colspan' => 2))]); |
|
| 31 | + foreach ($usages as $key => $description) { |
|
| 32 | 32 | $table->addRow([' ' . $key, $description]); |
| 33 | - } |
|
| 33 | + } |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | if ($arguments = $def->getArguments()) { |
| 37 | - $table->addRow(['','']); |
|
| 38 | - $table->addRow([new TableCell('Arguments:', array('colspan' => 2))]); |
|
| 39 | - foreach ($arguments as $argument) { |
|
| 37 | + $table->addRow(['','']); |
|
| 38 | + $table->addRow([new TableCell('Arguments:', array('colspan' => 2))]); |
|
| 39 | + foreach ($arguments as $argument) { |
|
| 40 | 40 | $formatted = $this->formatArgumentName($argument); |
| 41 | 41 | $description = $argument->getDescription(); |
| 42 | 42 | if ($argument->getDefault()) { |
| 43 | - $description .= ' [default: ' . $argument->getDefault() . ']'; |
|
| 43 | + $description .= ' [default: ' . $argument->getDefault() . ']'; |
|
| 44 | 44 | } |
| 45 | 45 | $table->addRow([' ' . $formatted, $description]); |
| 46 | - } |
|
| 46 | + } |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | if ($options = $def->getOptions()) { |
| 50 | - $table->addRow(['','']); |
|
| 51 | - $table->addRow([new TableCell('Options:', array('colspan' => 2))]); |
|
| 52 | - foreach ($options as $option) { |
|
| 50 | + $table->addRow(['','']); |
|
| 51 | + $table->addRow([new TableCell('Options:', array('colspan' => 2))]); |
|
| 52 | + foreach ($options as $option) { |
|
| 53 | 53 | $formatted = $this->formatOption($option); |
| 54 | 54 | $table->addRow([' ' . $formatted, $option->getDescription()]); |
| 55 | - } |
|
| 55 | + } |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | if ($topics = $command->getTopics()) { |
| 59 | - $table->addRow(['','']); |
|
| 60 | - $table->addRow([new TableCell('Topics:', array('colspan' => 2))]); |
|
| 61 | - foreach ($topics as $topic) { |
|
| 59 | + $table->addRow(['','']); |
|
| 60 | + $table->addRow([new TableCell('Topics:', array('colspan' => 2))]); |
|
| 61 | + foreach ($topics as $topic) { |
|
| 62 | 62 | // @todo deal with long descriptions |
| 63 | 63 | $table->addRow([' ' . $topic, substr($allTopics[$topic]['description'], 0, 30)]); |
| 64 | - } |
|
| 64 | + } |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | if ($aliases = $command->getAliases()) { |
| 68 | - $table->addRow(['','']); |
|
| 69 | - $table->addRow([new TableCell('Aliases: '. implode(' ', $aliases), array('colspan' => 2))]); |
|
| 68 | + $table->addRow(['','']); |
|
| 69 | + $table->addRow([new TableCell('Aliases: '. implode(' ', $aliases), array('colspan' => 2))]); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | $table->render(); |
| 73 | 73 | |
| 74 | 74 | $output->writeln($help); |
| 75 | - } |
|
| 75 | + } |
|
| 76 | 76 | } |
@@ -26,47 +26,47 @@ |
||
| 26 | 26 | $output->writeln($command->getDescription()); |
| 27 | 27 | |
| 28 | 28 | if ($usages = $command->getExampleUsages()) { |
| 29 | - $table->addRow(['','']); |
|
| 29 | + $table->addRow(['', '']); |
|
| 30 | 30 | $table->addRow([new TableCell('Examples:', array('colspan' => 2))]); |
| 31 | 31 | foreach ($usages as $key => $description) { |
| 32 | - $table->addRow([' ' . $key, $description]); |
|
| 32 | + $table->addRow([' '.$key, $description]); |
|
| 33 | 33 | } |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | if ($arguments = $def->getArguments()) { |
| 37 | - $table->addRow(['','']); |
|
| 37 | + $table->addRow(['', '']); |
|
| 38 | 38 | $table->addRow([new TableCell('Arguments:', array('colspan' => 2))]); |
| 39 | 39 | foreach ($arguments as $argument) { |
| 40 | 40 | $formatted = $this->formatArgumentName($argument); |
| 41 | 41 | $description = $argument->getDescription(); |
| 42 | 42 | if ($argument->getDefault()) { |
| 43 | - $description .= ' [default: ' . $argument->getDefault() . ']'; |
|
| 43 | + $description .= ' [default: '.$argument->getDefault().']'; |
|
| 44 | 44 | } |
| 45 | - $table->addRow([' ' . $formatted, $description]); |
|
| 45 | + $table->addRow([' '.$formatted, $description]); |
|
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | if ($options = $def->getOptions()) { |
| 50 | - $table->addRow(['','']); |
|
| 50 | + $table->addRow(['', '']); |
|
| 51 | 51 | $table->addRow([new TableCell('Options:', array('colspan' => 2))]); |
| 52 | 52 | foreach ($options as $option) { |
| 53 | 53 | $formatted = $this->formatOption($option); |
| 54 | - $table->addRow([' ' . $formatted, $option->getDescription()]); |
|
| 54 | + $table->addRow([' '.$formatted, $option->getDescription()]); |
|
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | if ($topics = $command->getTopics()) { |
| 59 | - $table->addRow(['','']); |
|
| 59 | + $table->addRow(['', '']); |
|
| 60 | 60 | $table->addRow([new TableCell('Topics:', array('colspan' => 2))]); |
| 61 | 61 | foreach ($topics as $topic) { |
| 62 | 62 | // @todo deal with long descriptions |
| 63 | - $table->addRow([' ' . $topic, substr($allTopics[$topic]['description'], 0, 30)]); |
|
| 63 | + $table->addRow([' '.$topic, substr($allTopics[$topic]['description'], 0, 30)]); |
|
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | if ($aliases = $command->getAliases()) { |
| 68 | - $table->addRow(['','']); |
|
| 69 | - $table->addRow([new TableCell('Aliases: '. implode(' ', $aliases), array('colspan' => 2))]); |
|
| 68 | + $table->addRow(['', '']); |
|
| 69 | + $table->addRow([new TableCell('Aliases: '.implode(' ', $aliases), array('colspan' => 2))]); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | $table->render(); |