-
-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathPrettyPrinter.php
69 lines (61 loc) · 2 KB
/
PrettyPrinter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* @link https://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license https://www.yiiframework.com/license/
*/
namespace yii\apidoc\helpers;
use PhpParser\Node\Expr;
use PhpParser\NodeAbstract;
use PhpParser\PrettyPrinter\Standard as BasePrettyPrinter;
/**
* Enhances the phpDocumentor PrettyPrinter:
*
* - Fix for single slash becoming double in values of properties and class constants.
* - All comments in values are removed because inline comments are shifted to the next line (can be confusing).
*
* @author Carsten Brandt <[email protected]>
* @since 2.0
*/
class PrettyPrinter extends BasePrettyPrinter
{
/**
* @link https://github.com/nikic/PHP-Parser/issues/447#issuecomment-348557940
* @param string $string
* @return string
*/
protected function pSingleQuotedString(string $string) {
return '\'' . preg_replace("/'|\\\\(?=[\\\\']|$)/", '\\\\$0', $string) . '\'';
}
/**
* @param NodeAbstract[] $nodes
* @param bool $trailingComma
* @return string
*/
protected function pMaybeMultiline(array $nodes, bool $trailingComma = false)
{
foreach ($nodes as $node) {
$node->setAttribute('comments', []);
}
if (!$nodes) {
return $this->pCommaSeparated($nodes);
} else {
return $this->pCommaSeparatedMultiline($nodes, $trailingComma) . $this->nl;
}
}
/**
* Returns a simple human readable output for a value.
* @param Expr $value The value node as provided by PHP-Parser.
* @return string
* @deprecated Pretty print is handled in "phpdocumentor/reflection" library. This custom pretty printer is now
* injected through strategies and not directly called within "apidoc" extension.
*/
public static function getRepresentationOfValue(Expr $value)
{
if ($value === null) {
return '';
}
$printer = new static();
return $printer->prettyPrintExpr($value);
}
}