You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Maxime ROCHER b6ddc8d42d
1er push
1 month ago
..
.github/workflows 1er push 1 month ago
src/PhpDocReader 1er push 1 month ago
.gitattributes 1er push 1 month ago
.gitignore 1er push 1 month ago
.phpcs.xml.dist 1er push 1 month ago
LICENSE 1er push 1 month ago
README.md 1er push 1 month ago
composer.json 1er push 1 month ago

README.md

PhpDocReader

This project is used by:

Fork the README to add your project here.

Features

PhpDocReader parses @var and @param values in PHP docblocks:


use My\Cache\Backend;

class Cache
{
    /**
     * @var Backend
     */
    protected $backend;

    /**
     * @param Backend $backend
     */
    public function __construct($backend)
    {
    }
}

It supports namespaced class names with the same resolution rules as PHP:

  • fully qualified name (starting with \)
  • imported class name (eg. use My\Cache\Backend;)
  • relative class name (from the current namespace, like SubNamespace\MyClass)
  • aliased class name (eg. use My\Cache\Backend as FooBar;)

Primitive types (@var string) are ignored (returns null), only valid class names are returned.

Usage

$reader = new PhpDocReader();

// Read a property type (@var phpdoc)
$property = new ReflectionProperty($className, $propertyName);
$propertyClass = $reader->getPropertyClass($property);

// Read a parameter type (@param phpdoc)
$parameter = new ReflectionParameter(array($className, $methodName), $parameterName);
$parameterClass = $reader->getParameterClass($parameter);