PrettyPrinter.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\apidoc\helpers;
  8. use PHPParser_Node_Expr;
  9. use PHPParser_Node_Expr_Array;
  10. /**
  11. * Enhances the phpDocumentor PrettyPrinter with short array syntax
  12. *
  13. * @author Carsten Brandt <mail@cebe.cc>
  14. * @since 2.0
  15. */
  16. class PrettyPrinter extends \phpDocumentor\Reflection\PrettyPrinter
  17. {
  18. /**
  19. * @param PHPParser_Node_Expr_Array $node
  20. * @return string
  21. */
  22. public function pExpr_Array(PHPParser_Node_Expr_Array $node)
  23. {
  24. return '[' . $this->pCommaSeparated($node->items) . ']';
  25. }
  26. /**
  27. * Returns a simple human readable output for a value.
  28. *
  29. * @param PHPParser_Node_Expr $value The value node as provided by PHP-Parser.
  30. * @return string
  31. */
  32. public static function getRepresentationOfValue(PHPParser_Node_Expr $value)
  33. {
  34. if ($value === null) {
  35. return '';
  36. }
  37. $printer = new static();
  38. return $printer->prettyPrintExpr($value);
  39. }
  40. }