Skip to content

Commit 47ace60

Browse files
yunoshjaapio
authored andcommitted
Add a tag formatter that aligns all tag values.
1 parent d52fdc6 commit 47ace60

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* This file is part of phpDocumentor.
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*
8+
* @copyright 2017 Mike van Riel<[email protected]>
9+
* @license http://www.opensource.org/licenses/mit-license.php MIT
10+
* @link http://phpdoc.org
11+
*/
12+
13+
namespace phpDocumentor\Reflection\DocBlock\Tags\Formatter;
14+
15+
use phpDocumentor\Reflection\DocBlock\Tag;
16+
use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
17+
18+
class AlignFormatter implements Formatter
19+
{
20+
/** @var int The maximum tag name length. */
21+
protected $maxLen = 0;
22+
23+
/**
24+
* Constructor.
25+
*
26+
* @param Tag[] $tags All tags that should later be aligned with the formatter.
27+
*/
28+
public function __construct(array $tags)
29+
{
30+
foreach ($tags as $tag) {
31+
$this->maxLen = max($this->maxLen, strlen($tag->getName()));
32+
}
33+
}
34+
35+
/**
36+
* Formats the given tag to return a simple plain text version.
37+
*
38+
* @param Tag $tag
39+
*
40+
* @return string
41+
*/
42+
public function format(Tag $tag)
43+
{
44+
return '@' . $tag->getName() . str_repeat(' ', $this->maxLen - strlen($tag->getName()) + 1) . (string)$tag;
45+
}
46+
}

0 commit comments

Comments
 (0)