qinty/doc-block-parser

This package's canonical repository appears to be gone and the package has been frozen as a result. Email us for help if needed.

Installs: 7 855

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/qinty/doc-block-parser

v2.0 2019-03-27 08:15 UTC

This package is auto-updated.

Last update: 2025-03-27 21:18:08 UTC


README

Build Status Test Coverage Code Climate

Extracts dynamically set properties for a class. For each property, will specify if is an array or not. The extracted type is either a basic type or a custom type (with full namespace path).

####Usage

using the sample class below, when called will display a list of properties

$instance = new \DocBlockParser\tests\support\SampleClassWithDocBlock;
$properties = \DocBlockParser\DocBlockParser::getProperties($instance);

print_r($properties);
// will display:
// Array(
//     [prop1] => DocBlockParser\Property Object
//         [type] => string
//         [isArray] => false
// 
//     [prop2] => DocBlockParser\Property Object
//         [type] => mixed
//         [isArray] => true
// 
//     [prop3] => DocBlockParser\Property Object
//         [type] => \DocBlockParser\tests\support\CustomType
//         [isArray] => true
// 
//     [prop4] => DocBlockParser\Property Object
//         [type] => \DocBlockParser\tests\support\CustomType
//         [isArray] => false
// 
//     [prop5] => DocBlockParser\Property Object
//         [type] => \CustomTypeFromGlobalNamespace
//         [isArray] => false
// 
//     [prop6] => DocBlockParser\Property Object
//         [type] => \Custom\Type\From\GlobalNamespace
//         [isArray] => false
// 
//     [prop7] => DocBlockParser\Property Object
//         [type] => \DocBlockParser\tests\support\CustomTypeWithRelativeNamespace
//         [isArray] => false
// 
//     [prop8] => DocBlockParser\Property Object
//         [type] => \DocBlockParser\Property
//         [isArray] => false
// 
//     [prop9] => DocBlockParser\Property Object
//         [type] => \DocBlockParser\tests\support\SampleClassWithoutDocBlock
//         [isArray] => false
// )

Sample class:

namespace DocBlockParser\tests\support;

use DocBlockParser\Property;
use DocBlockParser\tests\support\SampleClassWithoutDocBlock as CustomTypeWithAliasNamespace;

/**
 * // basic types
 * @property string prop1
 * @property array prop2
 *
 * // custom types
 * @property CustomType[] prop3                         relative namespace
 * @property CustomType prop4                           relative namespace
 *
 * // namespace resolver
 * @property \CustomTypeFromGlobalNamespace prop5       absolute namespace
 * @property \Custom\Type\From\GlobalNamespace prop6    absolute full namespace
 * @property CustomTypeWithRelativeNamespace prop7      relative namespace
 * @property Property prop8                             fully qualified namespace
 * @property CustomTypeWithAliasNamespace prop9         should get real full namespace
 *
 * // ignored
 * @var string prop10
 * @type string prop11
 */
class SampleClassWithDocBlock
{
    protected $attributes = [];

    public function __construct(array $attributes = [])
    {
        $this->attributes = $attributes;
    }

    public function __get($name)
    {
        if (array_key_exists($name, $this->attributes)) {
            return $this->attributes[$name];
        }
    }
}

####Todo

  • process @property-read, @property-write and implemented properties' @var docblock