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 * @author    Jan Schneider <jan@horde.org>
9 * @copyright 2017 Mike van Riel<mike@phpdoc.org>
10 * @license   http://www.opensource.org/licenses/mit-license.php MIT
11 * @link      http://phpdoc.org
12 */
13
14namespace phpDocumentor\Reflection\DocBlock\Tags\Formatter;
15
16use phpDocumentor\Reflection\DocBlock\Tag;
17use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
18
19class AlignFormatter implements Formatter
20{
21    /** @var int The maximum tag name length. */
22    protected $maxLen = 0;
23
24    /**
25     * Constructor.
26     *
27     * @param Tag[] $tags All tags that should later be aligned with the formatter.
28     */
29    public function __construct(array $tags)
30    {
31        foreach ($tags as $tag) {
32            $this->maxLen = max($this->maxLen, strlen($tag->getName()));
33        }
34    }
35
36    /**
37     * Formats the given tag to return a simple plain text version.
38     *
39     * @param Tag $tag
40     *
41     * @return string
42     */
43    public function format(Tag $tag)
44    {
45        return '@' . $tag->getName() . str_repeat(' ', $this->maxLen - strlen($tag->getName()) + 1) . (string)$tag;
46    }
47}
48