Skip to content

Adding support for @throws tags #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/BasicClass.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ Adds two arguments



**Throws Exceptions**


`\InvalidArgumentException`
> Thrown when a param is invalid

`\RuntimeException`
> Thrown when something happens at runtime


### BasicClass::one

Expand Down
3 changes: 3 additions & 0 deletions example/BasicClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public function __construct(array $options)
* @param float $two Second argument
*
* @return float
*
* @throws InvalidArgumentException Thrown when a param is invalid
* @throws RuntimeException Thrown when something happens at runtime
*/
public function addValues($one, $two)
{
Expand Down
13 changes: 7 additions & 6 deletions src/ClassParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ private function getMethodDetails($method)
$data = [
'shortDescription' => $docblock->getShortDescription(),
'longDescription' => $docblock->getLongDescription(),
'argumentsList' => $this->retriveParams($docblock->getTagsByName('param')),
'argumentsDescription' => $this->retriveParamsDescription($docblock->getTagsByName('param')),
'returnValue' => $this->retriveReturnValue($docblock->getTagsByName('return')),
'argumentsList' => $this->retrieveParams($docblock->getTagsByName('param')),
'argumentsDescription' => $this->retrieveParamsDescription($docblock->getTagsByName('param')),
'returnValue' => $this->retrieveTagData($docblock->getTagsByName('return')),
'throwsExceptions' => $this->retrieveTagData($docblock->getTagsByName('throws')),
'visibility' => join(
'',
[
Expand All @@ -84,7 +85,7 @@ public function getInheritedMethods()
return $methods;
}

private function retriveReturnValue(array $params)
private function retrieveTagData(array $params)
{
$data = [];
foreach ($params as $param) {
Expand All @@ -96,7 +97,7 @@ private function retriveReturnValue(array $params)
return $data;
}

private function retriveParams(array $params)
private function retrieveParams(array $params)
{
$data = [];
foreach ($params as $param) {
Expand All @@ -105,7 +106,7 @@ private function retriveParams(array $params)
return $data;
}

private function retriveParamsDescription(array $params)
private function retrieveParamsDescription(array $params)
{
$data = [];
foreach ($params as $param) {
Expand Down
14 changes: 14 additions & 0 deletions tpl/github.class.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@
<?php endforeach ?>
<?php endif ?>

<?php if ($info->throwsExceptions) : ?>

**Throws Exceptions**

<?php foreach ($info->throwsExceptions as $param) : ?>

`<?= join('|', $param->type) ?>`
<?php if ($param->desc) : ?>
> <?= str_replace("\n", " \n", $param->desc) ?>
<?php endif ?>

<?php endforeach ?>
<?php endif ?>

<hr />

<?php endforeach ?>
13 changes: 13 additions & 0 deletions tpl/stash.class.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,18 @@

<?php endforeach ?>

<?php if ($info->throwsExceptions) : ?>

**Throws Exceptions**

<?php foreach ($info->throwsExceptions as $param) : ?>

`<?= join('|', $param->type) ?>`
<?php if ($param->desc) : ?>
> <?= str_replace("\n", " \n", $param->desc) ?>
<?php endif ?>

<?php endforeach ?>
<?php endif ?>

<?php endforeach ?>