From f79d50bb1eb080986916634246e5849124cf5c9a Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 4 Nov 2024 22:31:37 +0100 Subject: [PATCH] Generators: remove deprecated methods These methods were _soft_ deprecated in PHPCS 3.12.0 via PR 755 and hard deprecated in PHPCS 3.x via PR 889. Includes removing the associated tests which verified the deprecation notice was being thrown. Related to 6 --- src/Generators/HTML.php | 124 ++---------------- src/Generators/Markdown.php | 100 ++------------ src/Generators/Text.php | 80 +---------- tests/Core/Generators/Fixtures/HTMLDouble.php | 30 ----- .../Generators/Fixtures/MarkdownDouble.php | 30 ----- tests/Core/Generators/HTMLTest.php | 60 --------- tests/Core/Generators/MarkdownTest.php | 59 --------- 7 files changed, 24 insertions(+), 459 deletions(-) diff --git a/src/Generators/HTML.php b/src/Generators/HTML.php index 7a8408f17a..144d12da1f 100644 --- a/src/Generators/HTML.php +++ b/src/Generators/HTML.php @@ -153,31 +153,11 @@ public function generate() }//end generate() - /** - * Print the header of the HTML page. - * - * @deprecated 3.12.0 Use HTML::getFormattedHeader() instead. - * - * @codeCoverageIgnore - * - * @return void - */ - protected function printHeader() - { - trigger_error( - 'The '.__METHOD__.'() method is deprecated. Use "echo '.__CLASS__.'::getFormattedHeader()" instead.', - E_USER_DEPRECATED - ); - - echo $this->getFormattedHeader(); - - }//end printHeader() - - /** * Format the header of the HTML page. * - * @since 3.12.0 Replaces the deprecated HTML::printHeader() method. + * @since 3.12.0 Replaces the HTML::printHeader() method, + * which was deprecated in 3.12.0 and removed in 4.0.0. * * @return string */ @@ -202,33 +182,13 @@ protected function getFormattedHeader() }//end getFormattedHeader() - /** - * Print the table of contents for the standard. - * - * @deprecated 3.12.0 Use HTML::getFormattedToc() instead. - * - * @codeCoverageIgnore - * - * @return void - */ - protected function printToc() - { - trigger_error( - 'The '.__METHOD__.'() method is deprecated. Use "echo '.__CLASS__.'::getFormattedToc()" instead.', - E_USER_DEPRECATED - ); - - echo $this->getFormattedToc(); - - }//end printToc() - - /** * Format the table of contents for the standard. * * The TOC is just an unordered list of bookmarks to sniffs on the page. * - * @since 3.12.0 Replaces the deprecated HTML::printToc() method. + * @since 3.12.0 Replaces the HTML::printToc() method, + * which was deprecated in 3.12.0 and removed in 4.0.0. * * @return string */ @@ -259,31 +219,11 @@ protected function getFormattedToc() }//end getFormattedToc() - /** - * Print the footer of the HTML page. - * - * @deprecated 3.12.0 Use HTML::getFormattedFooter() instead. - * - * @codeCoverageIgnore - * - * @return void - */ - protected function printFooter() - { - trigger_error( - 'The '.__METHOD__.'() method is deprecated. Use "echo '.__CLASS__.'::getFormattedFooter()" instead.', - E_USER_DEPRECATED - ); - - echo $this->getFormattedFooter(); - - }//end printFooter() - - /** * Format the footer of the HTML page. * - * @since 3.12.0 Replaces the deprecated HTML::printFooter() method. + * @since 3.12.0 Replaces the HTML::printFooter() method, + * which was deprecated in 3.12.0 and removed in 4.0.0. * * @return string */ @@ -369,35 +309,13 @@ private function titleToAnchor($title) }//end titleToAnchor() - /** - * Print a text block found in a standard. - * - * @param \DOMNode $node The DOMNode object for the text block. - * - * @deprecated 3.12.0 Use HTML::getFormattedTextBlock() instead. - * - * @codeCoverageIgnore - * - * @return void - */ - protected function printTextBlock(DOMNode $node) - { - trigger_error( - 'The '.__METHOD__.'() method is deprecated. Use "echo '.__CLASS__.'::getFormattedTextBlock()" instead.', - E_USER_DEPRECATED - ); - - echo $this->getFormattedTextBlock($node); - - }//end printTextBlock() - - /** * Format a text block found in a standard. * * @param \DOMNode $node The DOMNode object for the text block. * - * @since 3.12.0 Replaces the deprecated HTML::printTextBlock() method. + * @since 3.12.0 Replaces the HTML::printTextBlock() method, + * which was deprecated in 3.12.0 and removed in 4.0.0. * * @return string */ @@ -444,35 +362,13 @@ protected function getFormattedTextBlock(DOMNode $node) }//end getFormattedTextBlock() - /** - * Print a code comparison block found in a standard. - * - * @param \DOMNode $node The DOMNode object for the code comparison block. - * - * @deprecated 3.12.0 Use HTML::getFormattedCodeComparisonBlock() instead. - * - * @codeCoverageIgnore - * - * @return void - */ - protected function printCodeComparisonBlock(DOMNode $node) - { - trigger_error( - 'The '.__METHOD__.'() method is deprecated. Use "echo '.__CLASS__.'::getFormattedCodeComparisonBlock()" instead.', - E_USER_DEPRECATED - ); - - echo $this->getFormattedCodeComparisonBlock($node); - - }//end printCodeComparisonBlock() - - /** * Format a code comparison block found in a standard. * * @param \DOMNode $node The DOMNode object for the code comparison block. * - * @since 3.12.0 Replaces the deprecated HTML::printCodeComparisonBlock() method. + * @since 3.12.0 Replaces the HTML::printCodeComparisonBlock() method, + * which was deprecated in 3.12.0 and removed in 4.0.0. * * @return string */ diff --git a/src/Generators/Markdown.php b/src/Generators/Markdown.php index f73fcd935f..24d4b9914d 100644 --- a/src/Generators/Markdown.php +++ b/src/Generators/Markdown.php @@ -46,31 +46,11 @@ public function generate() }//end generate() - /** - * Print the markdown header. - * - * @deprecated 3.12.0 Use Markdown::getFormattedHeader() instead. - * - * @codeCoverageIgnore - * - * @return void - */ - protected function printHeader() - { - trigger_error( - 'The '.__METHOD__.'() method is deprecated. Use "echo '.__CLASS__.'::getFormattedHeader()" instead.', - E_USER_DEPRECATED - ); - - echo $this->getFormattedHeader(); - - }//end printHeader() - - /** * Format the markdown header. * - * @since 3.12.0 Replaces the deprecated Markdown::printHeader() method. + * @since 3.12.0 Replaces the Markdown::printHeader() method, + * which was deprecated in 3.12.0 and removed in 4.0.0. * * @return string */ @@ -83,31 +63,11 @@ protected function getFormattedHeader() }//end getFormattedHeader() - /** - * Print the markdown footer. - * - * @deprecated 3.12.0 Use Markdown::getFormattedFooter() instead. - * - * @codeCoverageIgnore - * - * @return void - */ - protected function printFooter() - { - trigger_error( - 'The '.__METHOD__.'() method is deprecated. Use "echo '.__CLASS__.'::getFormattedFooter()" instead.', - E_USER_DEPRECATED - ); - - echo $this->getFormattedFooter(); - - }//end printFooter() - - /** * Format the markdown footer. * - * @since 3.12.0 Replaces the deprecated Markdown::printFooter() method. + * @since 3.12.0 Replaces the Markdown::printFooter() method, + * which was deprecated in 3.12.0 and removed in 4.0.0. * * @return string */ @@ -154,35 +114,13 @@ protected function processSniff(DOMNode $doc) }//end processSniff() - /** - * Print a text block found in a standard. - * - * @param \DOMNode $node The DOMNode object for the text block. - * - * @deprecated 3.12.0 Use Markdown::getFormattedTextBlock() instead. - * - * @codeCoverageIgnore - * - * @return void - */ - protected function printTextBlock(DOMNode $node) - { - trigger_error( - 'The '.__METHOD__.'() method is deprecated. Use "echo '.__CLASS__.'::getFormattedTextBlock()" instead.', - E_USER_DEPRECATED - ); - - echo $this->getFormattedTextBlock($node); - - }//end printTextBlock() - - /** * Format a text block found in a standard. * * @param \DOMNode $node The DOMNode object for the text block. * - * @since 3.12.0 Replaces the deprecated Markdown::printTextBlock() method. + * @since 3.12.0 Replaces the Markdown::printTextBlock() method, + * which was deprecated in 3.12.0 and removed in 4.0.0. * * @return string */ @@ -227,35 +165,13 @@ protected function getFormattedTextBlock(DOMNode $node) }//end getFormattedTextBlock() - /** - * Print a code comparison block found in a standard. - * - * @param \DOMNode $node The DOMNode object for the code comparison block. - * - * @deprecated 3.12.0 Use Markdown::getFormattedCodeComparisonBlock() instead. - * - * @codeCoverageIgnore - * - * @return void - */ - protected function printCodeComparisonBlock(DOMNode $node) - { - trigger_error( - 'The '.__METHOD__.'() method is deprecated. Use "echo '.__CLASS__.'::getFormattedCodeComparisonBlock()" instead.', - E_USER_DEPRECATED - ); - - echo $this->getFormattedCodeComparisonBlock($node); - - }//end printCodeComparisonBlock() - - /** * Format a code comparison block found in a standard. * * @param \DOMNode $node The DOMNode object for the code comparison block. * - * @since 3.12.0 Replaces the deprecated Markdown::printCodeComparisonBlock() method. + * @since 3.12.0 Replaces the Markdown::printCodeComparisonBlock() method, + * which was deprecated in 3.12.0 and removed in 4.0.0. * * @return string */ diff --git a/src/Generators/Text.php b/src/Generators/Text.php index 5dae8c1ab2..c97f16afdb 100644 --- a/src/Generators/Text.php +++ b/src/Generators/Text.php @@ -47,31 +47,6 @@ public function processSniff(DOMNode $doc) }//end processSniff() - /** - * Prints the title area for a single sniff. - * - * @param \DOMNode $doc The DOMNode object for the sniff. - * It represents the "documentation" tag in the XML - * standard file. - * - * @deprecated 3.12.0 Use Text::getFormattedTitle() instead. - * - * @codeCoverageIgnore - * - * @return void - */ - protected function printTitle(DOMNode $doc) - { - trigger_error( - 'The '.__METHOD__.'() method is deprecated. Use "echo '.__CLASS__.'::getFormattedTitle()" instead.', - E_USER_DEPRECATED - ); - - echo $this->getFormattedTitle($doc); - - }//end printTitle() - - /** * Format the title area for a single sniff. * @@ -79,7 +54,8 @@ protected function printTitle(DOMNode $doc) * It represents the "documentation" tag in the XML * standard file. * - * @since 3.12.0 Replaces the deprecated Text::printTitle() method. + * @since 3.12.0 Replaces the Text::printTitle() method, + * which was deprecated in 3.12.0 and removed in 4.0.0. * * @return string */ @@ -101,35 +77,13 @@ protected function getFormattedTitle(DOMNode $doc) }//end getFormattedTitle() - /** - * Print a text block found in a standard. - * - * @param \DOMNode $node The DOMNode object for the text block. - * - * @deprecated 3.12.0 Use Text::getFormattedTextBlock() instead. - * - * @codeCoverageIgnore - * - * @return void - */ - protected function printTextBlock(DOMNode $node) - { - trigger_error( - 'The '.__METHOD__.'() method is deprecated. Use "echo '.__CLASS__.'::getFormattedTextBlock()" instead.', - E_USER_DEPRECATED - ); - - echo $this->getFormattedTextBlock($node); - - }//end printTextBlock() - - /** * Format a text block found in a standard. * * @param \DOMNode $node The DOMNode object for the text block. * - * @since 3.12.0 Replaces the deprecated Text::printTextBlock() method. + * @since 3.12.0 Replaces the Text::printTextBlock() method, + * which was deprecated in 3.12.0 and removed in 4.0.0. * * @return string */ @@ -152,35 +106,13 @@ protected function getFormattedTextBlock(DOMNode $node) }//end getFormattedTextBlock() - /** - * Print a code comparison block found in a standard. - * - * @param \DOMNode $node The DOMNode object for the code comparison block. - * - * @deprecated 3.12.0 Use Text::getFormattedCodeComparisonBlock() instead. - * - * @codeCoverageIgnore - * - * @return void - */ - protected function printCodeComparisonBlock(DOMNode $node) - { - trigger_error( - 'The '.__METHOD__.'() method is deprecated. Use "echo '.__CLASS__.'::getFormattedCodeComparisonBlock()" instead.', - E_USER_DEPRECATED - ); - - echo $this->getFormattedCodeComparisonBlock($node); - - }//end printCodeComparisonBlock() - - /** * Format a code comparison block found in a standard. * * @param \DOMNode $node The DOMNode object for the code comparison block. * - * @since 3.12.0 Replaces the deprecated Text::printCodeComparisonBlock() method. + * @since 3.12.0 Replaces the Text::printCodeComparisonBlock() method, + * which was deprecated in 3.12.0 and removed in 4.0.0. * * @return string */ diff --git a/tests/Core/Generators/Fixtures/HTMLDouble.php b/tests/Core/Generators/Fixtures/HTMLDouble.php index 695c0c6d2f..8b737fb7c4 100644 --- a/tests/Core/Generators/Fixtures/HTMLDouble.php +++ b/tests/Core/Generators/Fixtures/HTMLDouble.php @@ -37,34 +37,4 @@ public function getRealFooter() { return parent::getFormattedFooter(); } - - /** - * [VISIBILITY WIDENING ONLY] Print the header of the HTML page. - * - * @return void - */ - public function printHeader() - { - parent::printHeader(); - } - - /** - * [VISIBILITY WIDENING ONLY] Print the table of contents for the standard. - * - * @return void - */ - public function printToc() - { - parent::printToc(); - } - - /** - * [VISIBILITY WIDENING ONLY] Print the footer of the HTML page. - * - * @return void - */ - public function printFooter() - { - parent::printFooter(); - } } diff --git a/tests/Core/Generators/Fixtures/MarkdownDouble.php b/tests/Core/Generators/Fixtures/MarkdownDouble.php index 79dc6b0bf2..e783f7dda7 100644 --- a/tests/Core/Generators/Fixtures/MarkdownDouble.php +++ b/tests/Core/Generators/Fixtures/MarkdownDouble.php @@ -35,34 +35,4 @@ public function getRealFooter() { return parent::getFormattedFooter(); } - - /** - * [VISIBILITY WIDENING ONLY] Print the header of the HTML page. - * - * @return void - */ - public function printHeader() - { - parent::printHeader(); - } - - /** - * [VISIBILITY WIDENING ONLY] Print the table of contents for the standard. - * - * @return void - */ - public function printToc() - { - parent::printToc(); - } - - /** - * [VISIBILITY WIDENING ONLY] Print the footer of the HTML page. - * - * @return void - */ - public function printFooter() - { - parent::printFooter(); - } } diff --git a/tests/Core/Generators/HTMLTest.php b/tests/Core/Generators/HTMLTest.php index 91cd7d1e55..a8ac84a8ab 100644 --- a/tests/Core/Generators/HTMLTest.php +++ b/tests/Core/Generators/HTMLTest.php @@ -363,64 +363,4 @@ public function testFooterDoesntThrowWarningOnMissingTimezone() }//end testFooterDoesntThrowWarningOnMissingTimezone() - /** - * Perfunctory test to verify that extenders which call deprecated methods will see a deprecation notice. - * - * Note: not all deprecated methods are tested as some need arguments. - * - * @param string $methodName Name of the deprecated method to test. - * - * @dataProvider dataCallingDeprecatedMethodThrowsDeprecationNotice - * - * @return void - */ - public function testCallingDeprecatedMethodThrowsDeprecationNotice($methodName) - { - $exceptionClass = 'PHPUnit\Framework\Error\Deprecated'; - if (class_exists($exceptionClass) === false) { - $exceptionClass = 'PHPUnit_Framework_Error_Deprecated'; - } - - $regex = '`^The PHP_CodeSniffer\\\\Generators\\\\HTML::%s\(\) method is deprecated\. Use "echo [^\s]+::%s\(\)" instead\.$`'; - $regex = sprintf($regex, preg_quote($methodName, '`'), str_replace('print', 'getFormatted', $methodName)); - - if (method_exists($this, 'expectExceptionMessageMatches') === true) { - $this->expectException($exceptionClass); - $this->expectExceptionMessageMatches($regex); - } else if (method_exists($this, 'expectExceptionMessageRegExp') === true) { - // PHPUnit < 8.4.0. - $this->expectException($exceptionClass); - $this->expectExceptionMessageRegExp($regex); - } else { - // PHPUnit < 5.2.0. - $this->setExpectedExceptionRegExp($exceptionClass, $regex); - } - - // Set up the ruleset. - $standard = __DIR__.'/OneDocTest.xml'; - $config = new ConfigDouble(["--standard=$standard"]); - $ruleset = new Ruleset($config); - - $generator = new HTMLDouble($ruleset); - $generator->$methodName(); - - }//end testCallingDeprecatedMethodThrowsDeprecationNotice() - - - /** - * Data provider. - * - * @return array> - */ - public static function dataCallingDeprecatedMethodThrowsDeprecationNotice() - { - return [ - 'printHeader()' => ['printHeader'], - 'printToc()' => ['printToc'], - 'printFooter()' => ['printFooter'], - ]; - - }//end dataCallingDeprecatedMethodThrowsDeprecationNotice() - - }//end class diff --git a/tests/Core/Generators/MarkdownTest.php b/tests/Core/Generators/MarkdownTest.php index f9fd47796b..6bc2c4fba2 100644 --- a/tests/Core/Generators/MarkdownTest.php +++ b/tests/Core/Generators/MarkdownTest.php @@ -335,63 +335,4 @@ public function testFooterDoesntThrowWarningOnMissingTimezone() }//end testFooterDoesntThrowWarningOnMissingTimezone() - /** - * Perfunctory test to verify that extenders which call deprecated methods will see a deprecation notice. - * - * Note: not all deprecated methods are tested as some need arguments. - * - * @param string $methodName Name of the deprecated method to test. - * - * @dataProvider dataCallingDeprecatedMethodThrowsDeprecationNotice - * - * @return void - */ - public function testCallingDeprecatedMethodThrowsDeprecationNotice($methodName) - { - $exceptionClass = 'PHPUnit\Framework\Error\Deprecated'; - if (class_exists($exceptionClass) === false) { - $exceptionClass = 'PHPUnit_Framework_Error_Deprecated'; - } - - $regex = '`^The PHP_CodeSniffer\\\\Generators\\\\Markdown::%s\(\) method is deprecated\. Use "echo [^\s]+::%s\(\)" instead\.$`'; - $regex = sprintf($regex, preg_quote($methodName, '`'), str_replace('print', 'getFormatted', $methodName)); - - if (method_exists($this, 'expectExceptionMessageMatches') === true) { - $this->expectException($exceptionClass); - $this->expectExceptionMessageMatches($regex); - } else if (method_exists($this, 'expectExceptionMessageRegExp') === true) { - // PHPUnit < 8.4.0. - $this->expectException($exceptionClass); - $this->expectExceptionMessageRegExp($regex); - } else { - // PHPUnit < 5.2.0. - $this->setExpectedExceptionRegExp($exceptionClass, $regex); - } - - // Set up the ruleset. - $standard = __DIR__.'/OneDocTest.xml'; - $config = new ConfigDouble(["--standard=$standard"]); - $ruleset = new Ruleset($config); - - $generator = new MarkdownDouble($ruleset); - $generator->$methodName(); - - }//end testCallingDeprecatedMethodThrowsDeprecationNotice() - - - /** - * Data provider. - * - * @return array> - */ - public static function dataCallingDeprecatedMethodThrowsDeprecationNotice() - { - return [ - 'printHeader()' => ['printHeader'], - 'printFooter()' => ['printFooter'], - ]; - - }//end dataCallingDeprecatedMethodThrowsDeprecationNotice() - - }//end class