From 9a2f0eb8ba4d75b6eed1098398a9665e888db21a Mon Sep 17 00:00:00 2001 From: Andrew Smith Date: Thu, 3 Nov 2022 20:51:33 +1000 Subject: [PATCH] Support parsing SuppressWarnings tags in doc block Signed-off-by: Andrew Smith --- src/Barryvdh/Reflection/DocBlock/Tag.php | 4 +- .../DocBlock/Tag/SuppressWarningsTag.php | 30 ++++++++ .../DocBlock/Tag/SuppressWarningsTagTest.php | 75 +++++++++++++++++++ 3 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 src/Barryvdh/Reflection/DocBlock/Tag/SuppressWarningsTag.php create mode 100644 tests/Barryvdh/Reflection/DocBlock/Tag/SuppressWarningsTagTest.php diff --git a/src/Barryvdh/Reflection/DocBlock/Tag.php b/src/Barryvdh/Reflection/DocBlock/Tag.php index 14a1a483..324f27e6 100644 --- a/src/Barryvdh/Reflection/DocBlock/Tag.php +++ b/src/Barryvdh/Reflection/DocBlock/Tag.php @@ -95,7 +95,9 @@ class Tag implements \Reflector 'var' => '\Barryvdh\Reflection\DocBlock\Tag\VarTag', 'version' - => '\Barryvdh\Reflection\DocBlock\Tag\VersionTag' + => '\Barryvdh\Reflection\DocBlock\Tag\VersionTag', + 'SuppressWarnings' + => '\Barryvdh\Reflection\DocBlock\Tag\SuppressWarningsTag' ); /** diff --git a/src/Barryvdh/Reflection/DocBlock/Tag/SuppressWarningsTag.php b/src/Barryvdh/Reflection/DocBlock/Tag/SuppressWarningsTag.php new file mode 100644 index 00000000..40578d3b --- /dev/null +++ b/src/Barryvdh/Reflection/DocBlock/Tag/SuppressWarningsTag.php @@ -0,0 +1,30 @@ + + * @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com) + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ + +namespace Barryvdh\Reflection\DocBlock\Tag; + +use Barryvdh\Reflection\DocBlock\Tag; + +/** + * Reflection class for a @SuppressWarnings tag in a Docblock. + * + * @author Andrew Smith + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ +class SuppressWarningsTag extends Tag +{ + public function __toString() + { + return "@{$this->getName()}{$this->getContent()}"; + } +} diff --git a/tests/Barryvdh/Reflection/DocBlock/Tag/SuppressWarningsTagTest.php b/tests/Barryvdh/Reflection/DocBlock/Tag/SuppressWarningsTagTest.php new file mode 100644 index 00000000..1e069f33 --- /dev/null +++ b/tests/Barryvdh/Reflection/DocBlock/Tag/SuppressWarningsTagTest.php @@ -0,0 +1,75 @@ + + * @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ + +namespace Barryvdh\Reflection\DocBlock\Tag; + +use PHPUnit\Framework\Test; +use PHPUnit\Framework\TestCase; + +/** + * Test class for \Barryvdh\Reflection\DocBlock\Tag\SuppressWarningsTag + * + * @author Andrew Smith + * @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ +class SuppressWarningsTagTest extends TestCase +{ + /** + * Test that the \Barryvdh\Reflection\DocBlock\Tag\SuppressWarningsTag can + * understand the @SuppressWarnings doc block. + * + * @param string $type + * @param string $content + * @param string $exType + * @param string $exVariable + * @param string $exDescription + * + * @covers \Barryvdh\Reflection\DocBlock\Tag\SuppressWarningsTag + * @dataProvider provideDataForConstuctor + * + * @return void + */ + public function testConstructorParesInputsIntoCorrectFields( + $type, + $content, + $description + ) { + $tag = new SuppressWarningsTag($type, $content); + + $this->assertEquals($type, $tag->getName()); + $this->assertEquals($description, $tag->getDescription()); + } + + /** + * Data provider for testConstructorParesInputsIntoCorrectFields + * + * @return array + */ + public function provideDataForConstuctor() + { + // $type, $content, $description + return array( + array( + 'SuppressWarnings', + 'SuppressWarnings(PHPMD)', + 'SuppressWarnings(PHPMD)', + ), + array( + 'SuppressWarnings', + 'SuppressWarnings(PHPMD.TooManyMethods)', + 'SuppressWarnings(PHPMD.TooManyMethods)', + ), + ); + } +}