File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
src/DocBlock/Tags/Formatter Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 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<mike@phpdoc.org>
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+ }
You can’t perform that action at this time.
0 commit comments