mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
Bugfix: resolve issue with multiline descriptions
The phpstan parser is not consuming the full description when parsing docblocks with a more complex description. For them it's mostlikely not an issue as phpstan doesn't use the descriptions. But it will also parse the descriptions into unexpected tags. This could be an advantage but is not according to the phpdoc spec. Our own tokenizer is already tokenizing the docblocks into the correct parts. So all we needed to do is assume all remaining tokens in the phpstan ast belong to the description. From there our own code is able to handle this as before in v5.3. fixes #365
This commit is contained in:
@@ -17,16 +17,21 @@ use Mockery as m;
|
||||
use phpDocumentor\Reflection\DocBlock\Description;
|
||||
use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Generic;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Method;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\MethodParameter;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Param;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Return_;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\See;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Since;
|
||||
use phpDocumentor\Reflection\PseudoTypes\ConstExpression;
|
||||
use phpDocumentor\Reflection\Types\Array_;
|
||||
use phpDocumentor\Reflection\Types\Compound;
|
||||
use phpDocumentor\Reflection\Types\Context;
|
||||
use phpDocumentor\Reflection\Types\Integer;
|
||||
use phpDocumentor\Reflection\Types\Mixed_;
|
||||
use phpDocumentor\Reflection\Types\Object_;
|
||||
use phpDocumentor\Reflection\Types\Self_;
|
||||
use phpDocumentor\Reflection\Types\String_;
|
||||
use phpDocumentor\Reflection\Types\Void_;
|
||||
@@ -123,8 +128,8 @@ DESCRIPTION;
|
||||
$this->assertInstanceOf(See::class, $seeTags[0]);
|
||||
|
||||
$seeTag = $seeTags[0];
|
||||
$this->assertSame('\\' . StandardTagFactory::class, (string) $seeTag->getReference());
|
||||
$this->assertSame('', (string) $seeTag->getDescription());
|
||||
$this->assertSame('\\' . StandardTagFactory::class, (string)$seeTag->getReference());
|
||||
$this->assertSame('', (string)$seeTag->getDescription());
|
||||
}
|
||||
|
||||
public function testDescriptionsCanEscapeAtSignsAndClosingBraces(): void
|
||||
@@ -268,4 +273,95 @@ DOC;
|
||||
$docblock->getTags()
|
||||
);
|
||||
}
|
||||
|
||||
public function testRegressionWordpressDocblocks(): void
|
||||
{
|
||||
$docCommment = <<<DOC
|
||||
/**
|
||||
* Install a package.
|
||||
*
|
||||
* Copies the contents of a package from a source directory, and installs them in
|
||||
* a destination directory. Optionally removes the source. It can also optionally
|
||||
* clear out the destination folder if it already exists.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @since 6.2.0 Use move_dir() instead of copy_dir() when possible.
|
||||
*
|
||||
* @global WP_Filesystem_Base \$wp_filesystem WordPress filesystem subclass.
|
||||
* @global array \$wp_theme_directories
|
||||
*
|
||||
* @param array|string \$args {
|
||||
* Optional. Array or string of arguments for installing a package. Default empty array.
|
||||
*
|
||||
* @type string \$source Required path to the package source. Default empty.
|
||||
* @type string \$destination Required path to a folder to install the package in.
|
||||
* Default empty.
|
||||
* @type bool \$clear_destination Whether to delete any files already in the destination
|
||||
* folder. Default false.
|
||||
* @type bool \$clear_working Whether to delete the files from the working directory
|
||||
* after copying them to the destination. Default false.
|
||||
* @type bool \$abort_if_destination_exists Whether to abort the installation if
|
||||
* the destination folder already exists. Default true.
|
||||
* @type array \$hook_extra Extra arguments to pass to the filter hooks called by
|
||||
* WP_Upgrader::install_package(). Default empty array.
|
||||
* }
|
||||
*
|
||||
* @return array|WP_Error The result (also stored in `WP_Upgrader::\$result`), or a WP_Error on failure.
|
||||
*/
|
||||
DOC;
|
||||
|
||||
$factory = DocBlockFactory::createInstance();
|
||||
$docblock = $factory->create($docCommment);
|
||||
|
||||
self::assertEquals(
|
||||
new DocBlock(
|
||||
'Install a package.',
|
||||
new Description(
|
||||
'Copies the contents of a package from a source directory, and installs them in' . PHP_EOL .
|
||||
'a destination directory. Optionally removes the source. It can also optionally' . PHP_EOL .
|
||||
'clear out the destination folder if it already exists.'
|
||||
),
|
||||
[
|
||||
new Since('2.8.0', new Description('')),
|
||||
new Since('6.2.0', new Description('Use move_dir() instead of copy_dir() when possible.')),
|
||||
new Generic(
|
||||
'global',
|
||||
new Description('WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.')
|
||||
),
|
||||
new Generic(
|
||||
'global',
|
||||
new Description('array $wp_theme_directories')
|
||||
),
|
||||
new Param(
|
||||
'args',
|
||||
new Compound([new Array_(new Mixed_()), new String_()]),
|
||||
false,
|
||||
new Description(
|
||||
'{' . "\n" .
|
||||
'Optional. Array or string of arguments for installing a package. Default empty array.' . "\n" .
|
||||
"\n" .
|
||||
' @type string $source Required path to the package source. Default empty.' . "\n" .
|
||||
' @type string $destination Required path to a folder to install the package in.' . "\n" .
|
||||
' Default empty.' . "\n" .
|
||||
' @type bool $clear_destination Whether to delete any files already in the destination' . "\n" .
|
||||
' folder. Default false.' . "\n" .
|
||||
' @type bool $clear_working Whether to delete the files from the working directory' . "\n" .
|
||||
' after copying them to the destination. Default false.' . "\n" .
|
||||
' @type bool $abort_if_destination_exists Whether to abort the installation if' . "\n" .
|
||||
' the destination folder already exists. Default true.' . "\n" .
|
||||
' @type array $hook_extra Extra arguments to pass to the filter hooks called by' . "\n" .
|
||||
' WP_Upgrader::install_package(). Default empty array.' . "\n" .
|
||||
'}'
|
||||
)
|
||||
),
|
||||
new Return_(
|
||||
new Compound([new Array_(new Mixed_()), new Object_(new Fqsen('\WP_Error'))]),
|
||||
new Description('The result (also stored in `WP_Upgrader::$result`), or a WP_Error on failure.')
|
||||
),
|
||||
],
|
||||
new Context('\\')
|
||||
),
|
||||
$docblock
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user