method parse documentation in bbn\Parsers\Php
Function that analyzes the class by returning the information in detail
function(string $class_name)
{
$rc = new \ReflectionClass($class_name);
//die(var_dump($rc->hasConstant('PARAM_BOOL')));
$constants = $rc->getConstants();
$parent = $rc->getParentClass();
$parent_constants = [];
if ($parent) {
$parent_constants = $parent->getConstants();
}
$cparser =& $this;
$cls = [
'doc' => [
'title' => $this->iparse($rc->getDocComment()),
],
'name' => $rc->getName(),
'constants' => array_map(
function ($a) use ($constants, $parent_constants) {
return [
'name' => $a->name,
'value' => $constants[$a->name]
];
},
array_filter(
$rc->getReflectionConstants(),
function ($a) use ($parent_constants, $constants) {
return !array_key_exists($a->name, $parent_constants) || ($parent_constants[$a->name] !== $constants[$a->name]);
}
)
),
'namespace' => $rc->getNamespaceName(),
'traits' => $rc->getTraits(),
'interfaces' => $rc->getInterfaces(),
'parent' => $parent ? $parent->getName() : null,
'properties' => array_map(
function ($m) use ($cparser) {
//$m->setAccessible(true);
return [
'name' => $m->getName(),
//'value' => $m->getValue(),
'static' => $m->isStatic(),
'private' => $m->isPrivate(),
'protected' => $m->isProtected(),
'public' => $m->isPublic(),
'doc' => $cparser->iparse($m->getDocComment())
];
},
$rc->getProperties()
),
'methods' => array_map(
function ($m) use ($cparser) {
$ret = null;
if ($m->hasReturnType()) {
$type = $m->getReturnType();
$ret = [(string)$type];
if ($type->allowsNull()) {
$ret[] = null;
}
}
return [
'name' => $m->getName(),
'static' => $m->isStatic(),
'private' => $m->isPrivate(),
'protected' => $m->isProtected(),
'public' => $m->isPublic(),
'final' => $m->isFinal(),
'code' => $this->_closureSource($m),
'doc' => $cparser->iparse($m->getDocComment()),
'returns' => $ret,
'arguments' => array_map(
function ($p) use ($m) {
return [
'name' => $p->getName(),
'position' => $p->getPosition(),
'type' => $p->getType(),
'required' => !$p->isOptional(),
'has_default' => $p->isDefaultValueAvailable(),
'default' => $p->isDefaultValueAvailable() ? $p->getDefaultValue() : '',
'default_name' => $p->isDefaultValueAvailable() && $p->isDefaultValueConstant() ? $p->getDefaultValueConstantName() : ''
];
},
$m->getParameters()
)
];
},
$rc->getMethods()
)
];
/*
try {
$obj = $parser->parse($code);
$arr = json_decode(json_encode($obj), true);
foreach ( $arr[0]['stmts'] as $node ){
if ( $node['nodeType'] === 'Stmt_Class' ){
$res['class'] = $node['name']['name'];
$res['elements'] = [];
foreach ( $node['stmts'] as $stmts ){
if ( isset($stmts['attributes'], $stmts['attributes']['comments']) ){
foreach ( $stmts['attributes']['comments'] as $c ){
$docblock = $doc_parser->create($c['text']);
// Contains the summary for this DocBlock
$res['summary'] = $docblock->getSummary();
$tags = $docblock->getTags();
// Contains \phpDocumentor\Reflection\DocBlock\Description object
$res['description_obj'] = $docblock->getDescription();
foreach ( $tags as $i => $t ){
X::hdump($i, (string)$t->getType(), $t->getName);
$desc = $t->getDescription()->render();
var_dump($desc);
}
echo '';
var_dump($summary, $description, $tags);
echo '
';
}
}
}
X::hdump("HEY??", count($node['stmts']));
}
}
X::hdump(count($arr[0]['stmts']));
X::hdump($arr[0]['stmts']);
}
catch (PhpParser\Error $e) {
echo 'Parse Error: ', $e->getMessage();
}
*/
return $cls;
}
Function that analyzes the class by returning the information in detail BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way