Skip to content

Does not work with phpdocumentor/reflection-docblock v4.x #7

@Kage

Description

@Kage

When incorporating phpdoc-md into a project, my composer installed phpdocumentor/reflection-docblock version 4.3.0. Version 4 of reflection-docblock adds a dependency on webmozart/assert, which they use to assert values passed into methods since reflection-docblock version 3.x. The DocBlock constructor now requires the first variable be a string, which makes the assertion throw this exception:

kage@derp:~/github/phpdoc-md$ bin/phpdoc-md 
PHP Fatal error:  Clean\PhpDocMd\Markdown\GitHub\ClassInfo::__toString -> InvalidArgumentException: Expected a string. Got: ReflectionMethod in /home/kage/github/phpdoc-md/vendor/webmozart/assert/src/Assert.php:1081
Stack trace:
#0 /home/kage/github/phpdoc-md/vendor/webmozart/assert/src/Assert.php(174): Webmozart\Assert\Assert::reportInvalidArgument('Expected a stri...')
#1 /home/kage/github/phpdoc-md/vendor/phpdocumentor/reflection-docblock/src/DocBlock.php(59): Webmozart\Assert\Assert::string(Object(ReflectionMethod))
#2 /home/kage/github/phpdoc-md/src/ClassParser.php(58): phpDocumentor\Reflection\DocBlock->__construct(Object(ReflectionMethod))
#3 /home/kage/github/phpdoc-md/src/ClassParser.php(50): Clean\PhpDocMd\ClassParser->getMethodDetails(Object(ReflectionMethod))
#4 /home/kage/github/phpdoc-md/src/Markdown/ClassInfo.php(32): Clean\PhpDocMd\ClassParser->getMethodsDetails()
#5 /home/kage/github/phpdoc-md/vendor/clean/view/src/AbstractView.php(92): Clean\PhpDocMd\Markdown\ClassInfo->render()
#6 [internal function]: Clean\ in /home/kage/github/phpdoc-md/vendor/clean/view/src/AbstractView.php on line 108

PHP version: PHP 7.0

Suggestions:

  1. (difficult, recommended) Refactor instantiation of DocBlock in src/ClassParser.php. Tried this myself but it led to more failures.
  2. (easy, not recommended) Change composer.json to require phpdocumentor/reflection-docblock only at ^2.0. This is not recommended because the 2.x version is no longer maintained, but is what I did in my project for an immediate fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions