filename = $filename; $this->line = $line; $this->docstring = $docstring; } public function getHint(): string { return 'callable'; } public function getFileName(): string { return $this->filename; } public function getLine(): int { return $this->line; } /** * @psalm-api * * @psalm-return ?non-empty-string */ public function getDocstring(): ?string { return $this->docstring; } /** * Returns the representation's docstring without surrounding comments. * * Note that this will not work flawlessly. * * On comments with whitespace after the stars the lines will begin with * whitespace, since we can't accurately guess how much of an indentation * is required. * * And on lines without stars on the left this may eat bullet points. * * Long story short: If you want the docstring read the contents. If you * absolutely must have it without comments (ie renderValueShort) this will * probably do. */ public function getDocstringWithoutComments(): ?string { if (null === ($ds = $this->getDocstring())) { return null; } $string = \substr($ds, 3, -2); $string = \preg_replace('/^\\s*\\*\\s*?(\\S|$)/m', '\\1', $string); return \trim($string); } public function getDocstringFirstLine(): ?string { $ds = $this->getDocstringWithoutComments(); if (null === $ds) { return null; } $ds = \explode("\n", $ds); $out = ''; foreach ($ds as $line) { if (0 === \strlen(\trim($line)) || '@' === $line[0]) { break; } $out .= $line.' '; } if (\strlen($out)) { return \rtrim($out); } return null; } public function getDocstringTrimmed(): ?string { if (null === ($ds = $this->getDocstring())) { return null; } $docstring = []; foreach (\explode("\n", $ds) as $line) { $line = \trim($line); if (($line[0] ?? null) === '*') { $line = ' '.$line; } $docstring[] = $line; } return \implode("\n", $docstring); } }