Skip to content

Commit ed15de4

Browse files
committed
more phpDoc processing
@method, @property-read, @property-write, @link, @see
1 parent 7204f30 commit ed15de4

13 files changed

Lines changed: 735 additions & 202 deletions

src/Debug/AbstractObject.php

Lines changed: 321 additions & 144 deletions
Large diffs are not rendered by default.

src/Debug/Debug.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,8 @@ public function groupEnd()
360360
/**
361361
* Initiate the beginning of "summary" log entries
362362
*
363-
* When possible summary entries will be displayed at the beginning of the log
364-
* call groupEnd() (at matching group depth) to end summary
363+
* Debug methods called while a groupSummary is open will appear at the top of the log
364+
* call groupEnd() to close summary
365365
*
366366
* groupSummary can be used multiple times
367367
* All groupSummary groups will appear together in a single group

src/Debug/OutputBase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ protected function dumpObject($abs, $path = array())
189189
foreach ($abs['properties'] as $name => $info) {
190190
$path[$pathCount] = $name;
191191
$vis = $info['visibility'];
192-
if ($info['isMagic']) {
192+
if (in_array($vis, array('magic','magic-read','magic-write'))) {
193193
$vis = ''.$vis; // "sparkles": there is no magic-want unicode char
194194
}
195195
if ($vis == 'private' && $info['inheritedFrom']) {

src/Debug/OutputHtml.php

Lines changed: 86 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -516,23 +516,27 @@ protected function dumpMethods($methods)
516516
? 'methods'
517517
: 'no methods';
518518
$str = '<dt class="methods">'.$label.'</dt>'."\n";
519+
$magicMethods = array_intersect(array('__call','__callStatic'), array_keys($methods));
520+
$str .= $this->magicMethodInfo($magicMethods);
519521
foreach ($methods as $methodName => $info) {
520-
$paramStr = $this->dumpParams($info['params']);
522+
$classes = array_keys(array_filter(array(
523+
'method' => true,
524+
'deprecated' => $info['isDeprecated'],
525+
)));
521526
$modifiers = array_keys(array_filter(array(
522527
'final' => $info['isFinal'],
523528
$info['visibility'] => true,
524529
'static' => $info['isStatic'],
525530
)));
526-
$str .= '<dd'
527-
.' class="method '.implode(' ', $modifiers).($info['isDeprecated'] ? ' deprecated' : '').'"'
528-
.' data-implements="'.$info['implements'].'">'
531+
$classes = array_merge($classes, $modifiers);
532+
$str .= '<dd class="'.implode(' ', $classes).'" data-implements="'.$info['implements'].'">'
529533
.implode(' ', array_map(function ($modifier) {
530534
return '<span class="t_modifier_'.$modifier.'">'.$modifier.'</span>';
531535
}, $modifiers))
532-
.(isset($info['phpDoc']['return'][0])
536+
.(isset($info['phpDoc']['return'])
533537
? ' <span class="t_type"'
534-
.' title="'.htmlspecialchars($info['phpDoc']['return'][0]['desc']).'"'
535-
.'>'.$info['phpDoc']['return'][0]['type'].'</span>'
538+
.' title="'.htmlspecialchars($info['phpDoc']['return']['desc']).'"'
539+
.'>'.$info['phpDoc']['return']['type'].'</span>'
536540
: ''
537541
)
538542
.' <span class="method-name"'
@@ -542,7 +546,9 @@ protected function dumpMethods($methods)
542546
: ''
543547
))).'"'
544548
.'>'.$methodName.'</span>'
545-
.'<span class="t_punct">(</span>'.$paramStr.'<span class="t_punct">)</span>'
549+
.'<span class="t_punct">(</span>'
550+
.$this->dumpParams($info['params'])
551+
.'<span class="t_punct">)</span>'
546552
.($methodName == '__toString'
547553
? '<br /><span class="indent">'.$this->dump($info['returnValue']).'</span>'
548554
: ''
@@ -572,13 +578,36 @@ protected function dumpParams($params)
572578
$paramStr .= '<span class="t_parameter-name"'
573579
.' title="'.htmlspecialchars($info['desc']).'"'
574580
.'>'.htmlspecialchars($info['name']).'</span>';
575-
if ($info['defaultValue'] != $this->debug->abstracter->UNDEFINED) {
581+
if ($info['defaultValue'] !== $this->debug->abstracter->UNDEFINED) {
576582
$defaultValue = $info['defaultValue'];
577-
if (is_string($defaultValue)) {
578-
$defaultValue = str_replace("\n", ' ', $defaultValue);
579-
}
580583
$paramStr .= ' <span class="t_operator">=</span> ';
581-
$paramStr .= '<span class="t_parameter-default">'.$this->dump($defaultValue).'</span>';
584+
if ($info['constantName']) {
585+
/*
586+
only php >= 5.4.6 supports this...
587+
or via @method phpDoc
588+
589+
show the constant name / hover for value
590+
*/
591+
$title = '';
592+
$type = $this->debug->abstracter->getType($defaultValue);
593+
if (!in_array($type, array('array','resource'))) {
594+
$title = $this->debug->output->outputText->dump($defaultValue);
595+
$title = htmlspecialchars('value: '.$title);
596+
}
597+
$paramStr .= '<span class="t_parameter-default t_const"'
598+
.' title="'.$title.'"'
599+
.'>'.$info['constantName'].'</span>';
600+
} else {
601+
/*
602+
The constant's value is shown
603+
*/
604+
if (is_string($defaultValue)) {
605+
$defaultValue = str_replace("\n", ' ', $defaultValue);
606+
}
607+
$classAndInner = $this->debug->utilities->parseAttribString($this->dump($defaultValue));
608+
$classAndInner['class'] = trim('t_parameter-default '.$classAndInner['class']);
609+
$paramStr .= '<span class="'.$classAndInner['class'].'">'.$classAndInner['innerhtml'].'</span>';
610+
}
582611
}
583612
$paramStr .= '</span>, '; // end .parameter
584613
}
@@ -587,7 +616,7 @@ protected function dumpParams($params)
587616
}
588617

589618
/**
590-
* Dump phpDoc info as html
619+
* Dump object's phpDoc info as html
591620
*
592621
* @param array $phpDoc parsed phpDoc
593622
*
@@ -601,15 +630,27 @@ protected function dumpPhpDoc($phpDoc)
601630
continue;
602631
}
603632
foreach ($values as $value) {
604-
$str .= '<dd class="constant">'
633+
if ($k == 'link') {
634+
$value = '<a href="'.$value['uri'].'" target="_blank">'
635+
.htmlspecialchars($value['desc'] ?: $value['uri'])
636+
.'</a>';
637+
} elseif ($k == 'see' && $value['uri']) {
638+
$value = '<a href="'.$value['uri'].'" target="_blank">'
639+
.htmlspecialchars($value['desc'] ?: $value['uri'])
640+
.'</a>';
641+
} else {
642+
$value = htmlspecialchars(implode(' ', $value));
643+
}
644+
$str .= '<dd class="phpdoc phpdoc-'.$k.'">'
605645
.'<span class="phpdoc-tag">'.$k.'</span>'
606-
.' <span class="t_operator">=</span> '
607-
.implode(' ', array_map('htmlspecialchars', $value))
608-
.'</dd>';
646+
.'<span class="t_operator">:</span> '
647+
.$value
648+
.'</dd>'."\n";
609649
}
610650
}
611651
if ($str) {
612-
$str = '<dt class="phpDoc">phpDoc</dt>'.$str;
652+
$str = '<dt class="phpDoc">phpDoc</dt>'."\n"
653+
.$str;
613654
}
614655
return $str;
615656
}
@@ -630,17 +671,15 @@ protected function dumpProperties($abs)
630671
$label .= ' <span class="text-muted">(via __debugInfo)</span>';
631672
}
632673
$str = '<dt class="properties">'.$label.'</dt>'."\n";
633-
if (isset($abs['methods']['__get'])) {
634-
$str .= '<dd class="magic-method info">This object has a <code>__get()</code> method</dd>'."\n";
635-
}
674+
$magicMethods = array_intersect(array('__get','__set'), array_keys($abs['methods']));
675+
$str .= $this->magicMethodInfo($magicMethods);
636676
foreach ($abs['properties'] as $k => $info) {
637677
$isPrivateAncestor = $info['visibility'] == 'private' && $info['inheritedFrom'];
638678
$classes = array_keys(array_filter(array(
639-
'property' => true,
640-
$info['visibility'] => $info['visibility'] != 'debug',
641679
'debug-value' => !empty($info['viaDebugInfo']),
642680
'private-ancestor' => $isPrivateAncestor,
643-
'magic-property' => $info['isMagic'],
681+
'property' => true,
682+
$info['visibility'] => $info['visibility'] != 'debug',
644683
)));
645684
$str .= '<dd class="'.implode(' ', $classes).'">'
646685
.'<span class="t_modifier_'.$info['visibility'].'">'.$info['visibility'].'</span>'
@@ -662,6 +701,28 @@ protected function dumpProperties($abs)
662701
return $str;
663702
}
664703

704+
/**
705+
* Generate some info regarding the given method names
706+
*
707+
* @param string[] $methods method names
708+
*
709+
* @return string
710+
*/
711+
private function magicMethodInfo($methods)
712+
{
713+
if (!$methods) {
714+
return '';
715+
}
716+
foreach ($methods as $i => $method) {
717+
$methods[$i] = '<code>'.$method.'</code>';
718+
}
719+
$methods = implode(' and ', $methods);
720+
$methods = $i == 0
721+
? 'a '.$methods.' method'
722+
: $methods.' methods';
723+
return '<dd class="magic info">This object has '.$methods.'</dd>'."\n";
724+
}
725+
665726
/**
666727
* Wrap classname in span.t_classname
667728
* if namespaced'd additionally wrap namespace in span.namespace

src/Debug/OutputText.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ protected function dumpProperties($abs, $path = array())
149149
foreach ($abs['properties'] as $name => $info) {
150150
$path[$pathCount] = $name;
151151
$vis = $info['visibility'];
152-
if ($info['isMagic']) {
153-
$vis = ''.$vis; // "sparkles" there is no magic-want unicode char
152+
if (in_array($vis, array('magic','magic-read','magic-write'))) {
153+
$vis = ''.$vis; // "sparkles" there is no magic-wand unicode char
154154
}
155155
if ($vis == 'private' && $info['inheritedFrom']) {
156156
$vis = '🔒 '.$vis;
@@ -179,6 +179,7 @@ protected function dumpMethods($methods)
179179
'public' => 0,
180180
'protected' => 0,
181181
'private' => 0,
182+
'magic' => 0,
182183
);
183184
foreach ($methods as $info) {
184185
$counts[ $info['visibility'] ] ++;

0 commit comments

Comments
 (0)