Skip to content

Commit

Permalink
output phpDoc @throws tag info for methods
Browse files Browse the repository at this point in the history
  • Loading branch information
bkdotcom committed Dec 14, 2023
1 parent d8a336f commit 6160ecf
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 37 deletions.
4 changes: 4 additions & 0 deletions src/Debug/Dump/Html/ObjectMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function dump(Abstraction $abs)
return \str_replace(array(
' data-deprecated-desc="null"',
' data-implements="null"',
' data-throws="null"',
' <span class="t_type"></span>',
), '', $html);
}
Expand Down Expand Up @@ -250,6 +251,9 @@ protected function getAttribs(array $info, array $cfg = array())
? $info['phpDoc']['deprecated'][0]['desc']
: null,
'data-implements' => $info['implements'],
'data-throws' => $this->opts['phpDocOutput'] && isset($info['phpDoc']['throws'])
? $info['phpDoc']['throws']
: null,
));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Debug/css/Debug.css

Large diffs are not rendered by default.

45 changes: 29 additions & 16 deletions src/Debug/js/Debug.jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -5969,13 +5969,15 @@
if (title === 'Deprecated') {
title = tippyContentDeprecated($ref, title);
} else if (title === 'Implements') {
title = tippyContentImplements($ref);
title = tippyContentImplements($ref, title);
} else if (['Inherited', 'Private ancestor'].indexOf(title) > -1) {
title = tippyContentInherited($ref, title);
} else if (title === 'Overrides') {
title = tippyContentOverrides($ref, title);
} else if (title === 'Open in editor') {
title = '<i class="fa fa-pencil"></i> ' + title;
} else if (title === 'Throws') {
title = tippyContentThrows($ref, title);
} else if (title.match(/^\/.+: line \d+$/)) {
title = '<i class="fa fa-file-code-o"></i> ' + title;
}
Expand All @@ -5990,34 +5992,44 @@
}

function tippyContentImplements ($ref, title) {
var titleMore = $ref.parent().data('implements');
titleMore = '<span class="classname">' +
titleMore.replace(/^(.*\\)(.+)$/, '<span class="namespace">$1</span>$2') +
'</span>';
return 'Implements: ' + titleMore
var classname = $ref.parent().data('implements');
return title + ' ' + markupClassname(classname)
}

function tippyContentInherited ($ref, title) {
var titleMore = $ref.parent().data('inheritedFrom');
if (typeof titleMore === 'undefined') {
var classname = $ref.parent().data('classname');
if (typeof classname === 'undefined') {
return title
}
title = title === 'Inherited'
? 'Inherited from'
: title + '<br />defined in';
titleMore = '<span class="classname">' +
titleMore.replace(/^(.*\\)(.+)$/, '<span class="namespace">$1</span>$2') +
'</span>';
return title + ' ' + titleMore
: title + '<br />defined in'; // private ancestor
return title + ' ' + markupClassname(classname)
}

function tippyContentOverrides ($ref, title) {
var titleMore = $ref.parent().data('declaredPrev');
return titleMore
? 'Overrides ' + titleMore
var classname = $ref.parent().data('declaredPrev');
return classname
? title + ' ' + markupClassname(classname)
: title
}

function tippyContentThrows ($ref, title) {
var throws = $ref.parent().data('throws');
var i;
var count;
var info;
var $dl = $('<dl class="dl-horizontal"></dl>');
for (i = 0, count = throws.length; i < count; i++) {
info = throws[i];
$dl.append($('<dt></dt>').html(markupClassname(info.type)));
if (info.desc) {
$dl.append($('<dd></dd>').text(info.desc));
}
}
return title + $dl[0].outerHTML
}

function tippyOnHide (instance) {
var $ref = $(instance.reference);
var title = $ref.data('titleOrig');
Expand Down Expand Up @@ -6302,6 +6314,7 @@
'> .method > .parameter.isPromoted': '<i class="fa fa-arrow-up" title="Promoted"></i>',
'> .method > .parameter[data-attributes]': '<i class="fa fa-hashtag" title="Attributes"></i>',
'> .method[data-implements]': '<i class="fa fa-handshake-o" title="Implements"></i>',
'> .method[data-throws]': '<i class="fa fa-flag" title="Throws"></i>',
'> .property.debuginfo-value': '<i class="fa fa-eye" title="via __debugInfo()"></i>',
'> .property.debuginfo-excluded': '<i class="fa fa-eye-slash" title="not included in __debugInfo"></i>',
'> .property.isDynamic': '<i class="fa fa-warning" title="Dynamic"></i>',
Expand Down
2 changes: 1 addition & 1 deletion src/Debug/js/Debug.jquery.min.js

Large diffs are not rendered by default.

42 changes: 27 additions & 15 deletions src/Debug/js_src/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ function tippyContent (reference) {
title = tippyContentOverrides($ref, title)
} else if (title === 'Open in editor') {
title = '<i class="fa fa-pencil"></i> ' + title
} else if (title === 'Throws') {
title = tippyContentThrows($ref, title)
} else if (title.match(/^\/.+: line \d+$/)) {
title = '<i class="fa fa-file-code-o"></i> ' + title
}
Expand All @@ -54,34 +56,44 @@ function tippyContentDeprecated ($ref, title) {
}

function tippyContentImplements ($ref, title) {
var titleMore = $ref.parent().data('implements')
titleMore = '<span class="classname">' +
titleMore.replace(/^(.*\\)(.+)$/, '<span class="namespace">$1</span>$2') +
'</span>'
return 'Implements: ' + titleMore
var classname = $ref.parent().data('implements')
return title + ' ' + markupClassname(classname)
}

function tippyContentInherited ($ref, title) {
var titleMore = $ref.parent().data('inheritedFrom')
if (typeof titleMore === 'undefined') {
var classname = $ref.parent().data('classname')
if (typeof classname === 'undefined') {
return title
}
title = title === 'Inherited'
? 'Inherited from'
: title + '<br />defined in'
titleMore = '<span class="classname">' +
titleMore.replace(/^(.*\\)(.+)$/, '<span class="namespace">$1</span>$2') +
'</span>'
return title + ' ' + titleMore
: title + '<br />defined in' // private ancestor
return title + ' ' + markupClassname(classname)
}

function tippyContentOverrides ($ref, title) {
var titleMore = $ref.parent().data('declaredPrev')
return titleMore
? 'Overrides ' + titleMore
var classname = $ref.parent().data('declaredPrev')
return classname
? title + ' ' + markupClassname(classname)
: title
}

function tippyContentThrows ($ref, title) {
var throws = $ref.parent().data('throws')
var i
var count
var info
var $dl = $('<dl class="dl-horizontal"></dl>')
for (i = 0, count = throws.length; i < count; i++) {
info = throws[i]
$dl.append($('<dt></dt>').html(markupClassname(info.type)))
if (info.desc) {
$dl.append($('<dd></dd>').text(info.desc))
}
}
return title + $dl[0].outerHTML
}

function tippyOnHide (instance) {
var $ref = $(instance.reference)
var title = $ref.data('titleOrig')
Expand Down
1 change: 1 addition & 0 deletions src/Debug/js_src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var config = new Config({
'> .method > .parameter.isPromoted': '<i class="fa fa-arrow-up" title="Promoted"></i>',
'> .method > .parameter[data-attributes]': '<i class="fa fa-hashtag" title="Attributes"></i>',
'> .method[data-implements]': '<i class="fa fa-handshake-o" title="Implements"></i>',
'> .method[data-throws]': '<i class="fa fa-flag" title="Throws"></i>',
'> .property.debuginfo-value': '<i class="fa fa-eye" title="via __debugInfo()"></i>',
'> .property.debuginfo-excluded': '<i class="fa fa-eye-slash" title="not included in __debugInfo"></i>',
'> .property.isDynamic': '<i class="fa fa-warning" title="Dynamic"></i>',
Expand Down
1 change: 1 addition & 0 deletions src/Debug/scss/_arrayAndObject.scss
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ li[class*=m_] > .t_array.array-file-tree > .array-inner {
}
}

i.fa-flag,
i.fa-warning {
color: $color-warning;
}
Expand Down
14 changes: 13 additions & 1 deletion src/Debug/scss/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,19 @@ dl {
margin-top: 0;
margin-bottom: 0;
dt { font-weight: bold; }
&:not(.dl-horizontal) dd {
&.dl-horizontal {
display: grid;
grid-template-columns: max-content auto;
> dt {
grid-column: 1;
text-align: right;
}
> dd {
grid-column: 2;
margin-left: 0.75em;
}
}
&:not(.dl-horizontal) > dd {
margin-left: 20px;
padding-left: 10px;
text-indent: -10px;
Expand Down
2 changes: 1 addition & 1 deletion tests/Debug/Fixture/TestObj.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function __debugInfo()
*
* @return string
*
* @throws \Exception
* @throws \Exception when toStrThrow is `1`
*/
public function __toString()
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Debug/Type/ObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ static function ($foo, $bar) {
self::assertAbstractionType($objAbs);
self::assertSame(array(
array(
'desc' => null,
'desc' => 'when toStrThrow is `1`',
'type' => 'Exception',
),
), $objAbs['methods']['__toString']['phpDoc']['throws']);
Expand Down Expand Up @@ -329,7 +329,7 @@ static function ($foo, $bar) {
'',
'Constructor description">__construct</span><span class="t_punct">(</span><span class="parameter"><span class="t_type">string</span> <span class="t_parameter-name" title="value __toString will return;">$toString</span> <span class="t_operator">=</span> <span class="t_parameter-default t_string">abracadabra</span></span><span class="t_punct">,</span> <span class="parameter"><span class="t_type">int</span> <span class="t_parameter-name" title="0: don&#039;t, 1: throw, 2: throw &amp; catch">$toStrThrow</span> <span class="t_operator">=</span> <span class="t_int t_parameter-default">0</span></span><span class="t_punct">)</span></dd>',
'<dd class="method public"><span class="t_modifier_public">public</span> <span class="t_identifier" title="magic method">__debugInfo</span><span class="t_punct">(</span><span class="t_punct">)</span><span class="t_punct t_colon">:</span> <span title="property=&gt;value array"><span class="t_type">array</span></span></dd>',
'<dd class="method public"' . (PHP_VERSION_ID >= 80000 ? ' data-implements="Stringable"' : '' ) . '><span class="t_modifier_public">public</span> <span class="t_identifier" title="toString magic method',
'<dd class="method public" ' . (PHP_VERSION_ID >= 80000 ? 'data-implements="Stringable" ' : '' ) . 'data-throws="[{&quot;desc&quot;:&quot;when toStrThrow is `1`&quot;,&quot;type&quot;:&quot;Exception&quot;}]"><span class="t_modifier_public">public</span> <span class="t_identifier" title="toString magic method',
'',
'Long Description">__toString</span><span class="t_punct">(</span><span class="t_punct">)</span><span class="t_punct t_colon">:</span> <span class="t_type">string</span>',
'<h3>static variables</h3>',
Expand Down

0 comments on commit 6160ecf

Please sign in to comment.