Skip to content

Commit a0d7b13

Browse files
committed
add toString() and __toString() methods
1 parent 1bcb09a commit a0d7b13

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/CodeSnippet.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,22 @@ public function getLineNumberEnd(): int
142142
return $this->surroundingLines[count($this->surroundingLines) - 1] ?? 0;
143143
}
144144

145+
public function toString()
146+
{
147+
$result = '';
148+
149+
foreach($this->getLines() as $line) {
150+
$result .= $line->value() . PHP_EOL;
151+
}
152+
153+
return $result;
154+
}
155+
156+
public function __toString()
157+
{
158+
return $this->toString();
159+
}
160+
145161
protected function isSurroundedLineNumber(int $lineNumber): bool
146162
{
147163
return in_array($lineNumber, $this->surroundingLines, true);

0 commit comments

Comments
 (0)