From da49da06c35db963bb0b05a78f7cc0540cc11c76 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 4 Nov 2024 08:58:43 +0100 Subject: [PATCH] Generators HTML/Markdown: don't print header/footer when there are no docs As things were, the Markdown/HTML header and footer would always be printed, even if there were no docs to display. In my opinion, there should be no output if there are no docs. This is in line with the `Text` output, which would already not generate any output when there are no docs. Includes updated test expectations. --- src/Generators/HTML.php | 4 + src/Generators/Markdown.php | 4 + .../Expectations/ExpectedOutputNoDocs.html | 78 ------------------- .../Expectations/ExpectedOutputNoDocs.md | 2 - tests/Core/Generators/HTMLTest.php | 2 +- tests/Core/Generators/MarkdownTest.php | 2 +- 6 files changed, 10 insertions(+), 82 deletions(-) delete mode 100644 tests/Core/Generators/Expectations/ExpectedOutputNoDocs.html delete mode 100644 tests/Core/Generators/Expectations/ExpectedOutputNoDocs.md diff --git a/src/Generators/HTML.php b/src/Generators/HTML.php index 0fce7c99ae..f2f2e64bdd 100644 --- a/src/Generators/HTML.php +++ b/src/Generators/HTML.php @@ -103,6 +103,10 @@ class HTML extends Generator */ public function generate() { + if (empty($this->docFiles) === true) { + return; + } + ob_start(); $this->printHeader(); $this->printToc(); diff --git a/src/Generators/Markdown.php b/src/Generators/Markdown.php index de207ec601..8739961697 100644 --- a/src/Generators/Markdown.php +++ b/src/Generators/Markdown.php @@ -27,6 +27,10 @@ class Markdown extends Generator */ public function generate() { + if (empty($this->docFiles) === true) { + return; + } + ob_start(); $this->printHeader(); diff --git a/tests/Core/Generators/Expectations/ExpectedOutputNoDocs.html b/tests/Core/Generators/Expectations/ExpectedOutputNoDocs.html deleted file mode 100644 index 060de7aa63..0000000000 --- a/tests/Core/Generators/Expectations/ExpectedOutputNoDocs.html +++ /dev/null @@ -1,78 +0,0 @@ - - - GeneratorTest Coding Standards - - - -

GeneratorTest Coding Standards

-

Table of Contents

- -
Documentation generated on #REDACTED# by PHP_CodeSniffer #VERSION#
- - diff --git a/tests/Core/Generators/Expectations/ExpectedOutputNoDocs.md b/tests/Core/Generators/Expectations/ExpectedOutputNoDocs.md deleted file mode 100644 index ece2692187..0000000000 --- a/tests/Core/Generators/Expectations/ExpectedOutputNoDocs.md +++ /dev/null @@ -1,2 +0,0 @@ -# GeneratorTest Coding Standard -Documentation generated on *REDACTED* by [PHP_CodeSniffer *VERSION*](https://github.com/PHPCSStandards/PHP_CodeSniffer) diff --git a/tests/Core/Generators/HTMLTest.php b/tests/Core/Generators/HTMLTest.php index 4140937ab7..17ef7c9bcf 100644 --- a/tests/Core/Generators/HTMLTest.php +++ b/tests/Core/Generators/HTMLTest.php @@ -62,7 +62,7 @@ public static function dataDocs() return [ 'Standard without docs' => [ 'standard' => __DIR__.'/NoDocsTest.xml', - 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputNoDocs.html', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputEmpty.txt', ], 'Standard with one doc file' => [ 'standard' => __DIR__.'/OneDocTest.xml', diff --git a/tests/Core/Generators/MarkdownTest.php b/tests/Core/Generators/MarkdownTest.php index 9a3e540044..1a89b7e8ee 100644 --- a/tests/Core/Generators/MarkdownTest.php +++ b/tests/Core/Generators/MarkdownTest.php @@ -62,7 +62,7 @@ public static function dataDocs() return [ 'Standard without docs' => [ 'standard' => __DIR__.'/NoDocsTest.xml', - 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputNoDocs.md', + 'pathToExpected' => __DIR__.'/Expectations/ExpectedOutputEmpty.txt', ], 'Standard with one doc file' => [ 'standard' => __DIR__.'/OneDocTest.xml',