Page MenuHomeDevCentral

D2538.id6411.diff
No OneTemporary

D2538.id6411.diff

diff --git a/src/Output/HTMLOutput.php b/src/Output/HTMLOutput.php
--- a/src/Output/HTMLOutput.php
+++ b/src/Output/HTMLOutput.php
@@ -15,48 +15,59 @@
public function render () : string {
$send = [];
- $title = $this->report->title;
- $send[] =
- '<h1 id="' . $this->makeId($title) . '">' . self::encode($title)
- . '</h1>';
+ if ($this->report->sections || $this->report->properties
+ || $this->report->title) {
- foreach ($this->report->sections as $section) {
- $title = $section->title;
+ $title = $this->report->title;
$send[] =
- '<h2 id="' . $this->makeId($title) . '">' .
- self::encode($title) . '</h2>';
- foreach ($section->entries as $entry) {
- $title = $entry->title;
- $send[] = '<h3 id="' . $this->makeId($title) . '">' .
- self::encode($title) . '</h3>';
+ '<h1 id="' . $this->makeId($title) . '">' . self::encode($title)
+ . '</h1>';
+ if ($this->report->sections) {
+ foreach ($this->report->sections as $section) {
+ $title = $section->title;
+ $send[] =
+ '<h2 id="' . $this->makeId($title) . '">' .
+ self::encode($title) . '</h2>';
+ foreach ($section->entries as $entry) {
+ $title = $entry->title;
+ $send[] = '<h3 id="' . $this->makeId($title) . '">' .
+ self::encode($title) . '</h3>';
- $text = explode("\n\n", $entry->text);
+ $text = explode("\n\n", $entry->text);
- foreach ($text as $value) {
- $send[] = '<p>' . self::encode($value) . '</p>';
+ foreach ($text as $value) {
+ $send[] = '<p>' . self::encode($value) . '</p>';
+ }
+ }
+ }
+ if ($this->report->properties && $this->report->sections) {
+ $send[] = '<hr>';
}
}
- }
- $send[] = '<hr>';
-
- $send[] = '<h2 id="report-properties">Report properties</h2>';
- $send[] = '<table>';
- $send[] = str_repeat(" ", 4) . '<tbody>';
+ if ($this->report->properties) {
+ $send[] = '<h2 id="report-properties">Report properties</h2>';
+ $send[] = '<table>';
+ $send[] = str_repeat(" ", 4) . '<tbody>';
- $properties = $this->report->properties;
+ $properties = $this->report->properties;
- foreach ($properties as $key => $value) {
- $send[] = str_repeat(" ", 4) . '<tr>';
- $send[] = str_repeat(" ", 8) .
+ foreach ($properties as $key => $value) {
+ $send[] = str_repeat(" ", 4) . '<tr>';
+ $send[] = str_repeat(" ", 8) .
- '<th>' . self::encode($key) . '</th>';
- $send[] = str_repeat(" ", 8) .
- '<td>' . self::encode($value) . '</td>';
+ '<th>' . self::encode($key) . '</th>';
+ $send[] = str_repeat(" ", 8) .
+ '<td>' . self::encode($value) . '</td>';
- $send[] = str_repeat(" ", 4) . '</tr>';
+ $send[] = str_repeat(" ", 4) . '</tr>';
+ }
+ $send[] = str_repeat(" ", 4) . '</tbody>';
+ $send[] = '</table>';
+ }
+ } else {
+ $send[] = '<h1 id="' . $this->makeId($this->report->title) . '">'
+ . self::encode($this->report->title) . '</h1>';
}
- $send[] = str_repeat(" ", 4) . '</tbody>';
- $send[] = '</table>';
$send[] = '';
return implode("\n", $send);
diff --git a/src/Output/MarkdownOutput.php b/src/Output/MarkdownOutput.php
--- a/src/Output/MarkdownOutput.php
+++ b/src/Output/MarkdownOutput.php
@@ -8,48 +8,61 @@
$send = [];
- $send[] = '# ' . $this->report->title;
- $send[] = '';
- foreach ($this->report->sections as $section) {
- $send[] = '## ' . $section->title;
+ if ($this->report->sections || $this->report->properties
+ || $this->report->title) {
+
+ $send[] = '# ' . $this->report->title;
$send[] = '';
- foreach ($section->entries as $entry) {
- $send[] = '### ' . $entry->title;
+ foreach ($this->report->sections as $section) {
+ $send[] = '## ' . $section->title;
$send[] = '';
- $send[] = $entry->text;
+ foreach ($section->entries as $entry) {
+
+ $send[] = '### ' . $entry->title;
+ $send[] = '';
+ $send[] = $entry->text;
+ $send[] = '';
+ }
+ }
+
+ if ($this->report->properties && $this->report->sections) {
+ $send[] = '---';
$send[] = '';
}
- }
+ if ($this->report->properties) {
+ $properties = $this->report->properties;
+ $propertyMaxLength = 0;
+ $maxValue = 0;
+ foreach ($properties as $key => $value) {
+ $propertyMaxLength = max($propertyMaxLength, strlen($key));
+ $maxValue = max($maxValue, strlen($value));
+ }
+ if ($propertyMaxLength < 8) {
+ $propertyMaxLength = 8;
+ }
- $send[] = '---';
- $send[] = '';
- $properties = $this->report->properties;
- $propertyMaxLength = 0;
- $maxValue = 0;
- foreach ($properties as $key => $value) {
- $propertyMaxLength = max($propertyMaxLength, strlen($key));
- $maxValue = max($maxValue, strlen($value));
- }
- if ($propertyMaxLength < 8) {
- $propertyMaxLength = 8;
- }
+ $send[] =
+ '| Property' . str_repeat(' ', $propertyMaxLength - 8)
+ . ' | '
+ . str_repeat(' ', $maxValue) . ' |';
- $send[] = '| Property' . str_repeat(' ', $propertyMaxLength - 8) . ' | '
- . str_repeat(' ', $maxValue) . ' |';
+ $send[] = '|' . str_repeat('-', $propertyMaxLength + 2) . '|'
+ . str_repeat('-', $maxValue + 2) . '|';
- $send[] = '|' . str_repeat('-', $propertyMaxLength + 2) . '|'
- . str_repeat('-', $maxValue + 2) . '|';
+ foreach ($properties as $key => $value) {
+ $send[] =
+ '| ' . $key . str_repeat(' ',
+ $propertyMaxLength - strlen($key))
+ . ' | '
+ . $value . str_repeat(' ', $maxValue - strlen($value))
+ . ' |';
+ }
- foreach ($properties as $key => $value) {
- $send[] =
- '| ' . $key . str_repeat(' ', $propertyMaxLength - strlen($key))
- . ' | '
- . $value . str_repeat(' ', $maxValue - strlen($value)) . ' |';
+ $send[] = '';
+ }
}
- $send[] = '';
-
return implode("\n", $send);
}
}
diff --git a/src/Output/XMLOutput.php b/src/Output/XMLOutput.php
--- a/src/Output/XMLOutput.php
+++ b/src/Output/XMLOutput.php
@@ -12,57 +12,71 @@
xmlwriter_set_indent($document, true);
xmlwriter_set_indent_string($document, ' ');
-
xmlwriter_start_document($document, '1.0', 'UTF-8');
xmlwriter_start_element($document, 'report');
xmlwriter_start_attribute($document, 'title');
- xmlwriter_text($document, $this->report->title);
- xmlwriter_end_attribute($document);
- foreach ($this->report->sections as $section) {
- xmlwriter_start_element($document, 'section');
- xmlwriter_start_attribute($document, 'title');
- xmlwriter_text($document, $section->title);
+ if ($this->report->sections || $this->report->properties
+ || $this->report->title) {
+
+ xmlwriter_text($document, $this->report->title);
xmlwriter_end_attribute($document);
- foreach ($section->entries as $entry) {
- xmlwriter_start_element($document, 'entry');
+ foreach ($this->report->sections as $section) {
+ xmlwriter_start_element($document, 'section');
xmlwriter_start_attribute($document, 'title');
- xmlwriter_text($document, $entry->title);
+ xmlwriter_text($document, $section->title);
xmlwriter_end_attribute($document);
- xmlwriter_start_element($document, 'text');
- xmlwriter_text($document, $entry->text);
- xmlwriter_end_element($document);
+ foreach ($section->entries as $entry) {
+ xmlwriter_start_element($document, 'entry');
+
+ xmlwriter_start_attribute($document, 'title');
+ xmlwriter_text($document, $entry->title);
+ xmlwriter_end_attribute($document);
- xmlwriter_end_element($document);
+ xmlwriter_start_element($document, 'text');
+ xmlwriter_text($document, $entry->text);
+ xmlwriter_end_element($document);
+
+ xmlwriter_end_element($document);
+ }
+ xmlwriter_end_element($document); // section
}
- xmlwriter_end_element($document); // section
- }
+
- xmlwriter_start_element($document, 'data');
- xmlwriter_start_attribute($document, 'title');
- xmlwriter_text($document, "Properties");
- xmlwriter_end_attribute($document);
+ if ($this->report->properties) {
- foreach ($this->report->properties as $key => $value) {
- xmlwriter_start_element($document, 'entry');
+ xmlwriter_start_element($document, 'data');
+ xmlwriter_start_attribute($document, 'title');
+ xmlwriter_text($document, "Properties");
+ xmlwriter_end_attribute($document);
+
+ foreach ($this->report->properties as $key => $value) {
+ xmlwriter_start_element($document, 'entry');
- xmlwriter_start_element($document, 'key');
- xmlwriter_text($document, $key);
- xmlwriter_end_element($document);
+ xmlwriter_start_element($document, 'key');
+ xmlwriter_text($document, $key);
+ xmlwriter_end_element($document);
- xmlwriter_start_element($document, 'value');
- xmlwriter_text($document, $value);
- xmlwriter_end_element($document);
+ xmlwriter_start_element($document, 'value');
+ xmlwriter_text($document, $value);
+ xmlwriter_end_element($document);
- xmlwriter_end_element($document);
+ xmlwriter_end_element($document);
+ }
+ xmlwriter_end_element($document); // data
+
+ // report
+ }
+ } else {
+ xmlwriter_text($document, "Void report");
+ xmlwriter_end_attribute($document);
}
- xmlwriter_end_element($document); // data
+ xmlwriter_end_element($document);
- xmlwriter_end_element($document); // report
xmlwriter_end_document($document);
return xmlwriter_output_memory($document);
diff --git a/tests/Output/XMLOutputTest.php b/tests/Output/XMLOutputTest.php
--- a/tests/Output/XMLOutputTest.php
+++ b/tests/Output/XMLOutputTest.php
@@ -23,7 +23,7 @@
public function testRender (string $name, Report $report) : void {
$actual = XMLOutput::for($report)->render();
- $expected = file_get_contents($this->getDataDir() . "/$name.html");
+ $expected = file_get_contents($this->getDataDir() . "/$name.xml");
$this->assertEquals($expected, $actual);
}
diff --git a/tests/data/empty.xml b/tests/data/empty.xml
--- a/tests/data/empty.xml
+++ b/tests/data/empty.xml
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
-<report title="Void report" />
+<report title="Void report"/>

File Metadata

Mime Type
text/plain
Expires
Thu, Nov 21, 10:10 (21 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2254991
Default Alt Text
D2538.id6411.diff (12 KB)

Event Timeline