PrettyPrinter.php 1.08 KB
Newer Older
Carsten Brandt committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\apidoc\helpers;

use PHPParser_Node_Expr;
use PHPParser_Node_Expr_Array;

/**
 * Enhances the phpDocumentor PrettyPrinter with short array syntax
 *
 * @author Carsten Brandt <mail@cebe.cc>
 * @since 2.0
 */
class PrettyPrinter extends \phpDocumentor\Reflection\PrettyPrinter
{
21 22 23 24
    /**
     * @param PHPParser_Node_Expr_Array $node
     * @return string
     */
25 26 27 28
    public function pExpr_Array(PHPParser_Node_Expr_Array $node)
    {
        return '[' . $this->pCommaSeparated($node->items) . ']';
    }
Carsten Brandt committed
29

30 31 32
    /**
     * Returns a simple human readable output for a value.
     *
33
     * @param PHPParser_Node_Expr $value The value node as provided by PHP-Parser.
34 35 36 37 38 39 40
     * @return string
     */
    public static function getRepresentationOfValue(PHPParser_Node_Expr $value)
    {
        if ($value === null) {
            return '';
        }
Carsten Brandt committed
41

42 43 44 45
        $printer = new static();

        return $printer->prettyPrintExpr($value);
    }
AlexGx committed
46
}