php-integrator/docblock-type-parser

This package is abandoned and no longer maintained. The author suggests using the serenata/docblock-type-parser package instead.

PHP docblock type parser

0.2.0 2017-05-28 19:34 UTC

This package is auto-updated.

Last update: 2018-05-05 12:13:01 UTC


README

Converts docblock types or type specifications into a more usable tree of type objects.

Part of the PHP Integrator project.

Installation

composer require "php-integrator/docblock-type-parser" "^0.2"

Usage

<?php

use PhpIntegrator\DocblockTypeParser\DocblockTypeParser;
use PhpIntegrator\DocblockTypeParser\CompoundDocblockType;

$parser = new DocblockTypeParser();
$type = $parser->parse('(int|bool)[]|string[]|array|null');

assert($type instanceof CompoundDocblockType);
assert($type->toString() === '(int|bool)[]|string[]|array|null');

Docblock types...?

Docblock types are those types that you specify inside docblocks for parameters, return values and other things. They allow narrowing down the type of a parameter that would otherwise not be possible in PHP itself and their syntax is more complex as a result.

Docblock types can can be interpreted by various tools, such as PHP Integrator or documentation generators:

<?php

/**
 * @param (int|bool)[]|string[]|array|null $test
 */
public function foo(array $test)
{

}

GPLv3 Logo