function Printer::print
Same name in this branch
- 11.1.x vendor/phpunit/phpunit/src/TextUI/Output/Printer/Printer.php \PHPUnit\TextUI\Output\Printer::print()
4 calls to Printer::print()
- Printer::printFormatPreserving in vendor/
phpstan/ phpdoc-parser/ src/ Printer/ Printer.php - Printer::printNodeFormatPreserving in vendor/
phpstan/ phpdoc-parser/ src/ Printer/ Printer.php - Printer::printTagValue in vendor/
phpstan/ phpdoc-parser/ src/ Printer/ Printer.php - Printer::printType in vendor/
phpstan/ phpdoc-parser/ src/ Printer/ Printer.php
File
-
vendor/
phpstan/ phpdoc-parser/ src/ Printer/ Printer.php, line 190
Class
Namespace
PHPStan\PhpDocParser\PrinterCode
public function print(Node $node) : string {
if ($node instanceof PhpDocNode) {
return "/**\n *" . implode("\n *", array_map(function (PhpDocChildNode $child) : string {
$s = $this->print($child);
return $s === '' ? '' : ' ' . $s;
}, $node->children)) . "\n */";
}
if ($node instanceof PhpDocTextNode) {
return $node->text;
}
if ($node instanceof PhpDocTagNode) {
if ($node->value instanceof DoctrineTagValueNode) {
return $this->print($node->value);
}
return trim(sprintf('%s %s', $node->name, $this->print($node->value)));
}
if ($node instanceof PhpDocTagValueNode) {
return $this->printTagValue($node);
}
if ($node instanceof TypeNode) {
return $this->printType($node);
}
if ($node instanceof ConstExprNode) {
return $this->printConstExpr($node);
}
if ($node instanceof MethodTagValueParameterNode) {
$type = $node->type !== null ? $this->print($node->type) . ' ' : '';
$isReference = $node->isReference ? '&' : '';
$isVariadic = $node->isVariadic ? '...' : '';
$default = $node->defaultValue !== null ? ' = ' . $this->print($node->defaultValue) : '';
return "{$type}{$isReference}{$isVariadic}{$node->parameterName}{$default}";
}
if ($node instanceof CallableTypeParameterNode) {
$type = $this->print($node->type) . ' ';
$isReference = $node->isReference ? '&' : '';
$isVariadic = $node->isVariadic ? '...' : '';
$isOptional = $node->isOptional ? '=' : '';
return trim("{$type}{$isReference}{$isVariadic}{$node->parameterName}") . $isOptional;
}
if ($node instanceof ArrayShapeUnsealedTypeNode) {
if ($node->keyType !== null) {
return sprintf('<%s, %s>', $this->printType($node->keyType), $this->printType($node->valueType));
}
return sprintf('<%s>', $this->printType($node->valueType));
}
if ($node instanceof DoctrineAnnotation) {
return (string) $node;
}
if ($node instanceof DoctrineArgument) {
return (string) $node;
}
if ($node instanceof DoctrineArray) {
return (string) $node;
}
if ($node instanceof DoctrineArrayItem) {
return (string) $node;
}
throw new LogicException(sprintf('Unknown node type %s', get_class($node)));
}